<CODE>
#!/bin/sh
set -x
###############################################################################################################
###############################################################################################################
# Script to Restore Xen Host/Dom0 and all DomUs which are using Logical Volumes as Virtual Hard Disks
###############################################################################################################
###############################################################################################################
# Written by:
# Mr. Teo En Ming (Zhang Enming) Dip(Mechatronics) BEng(Hons)(Mechanical Engineering)
# Alma Maters:
# (1) Singapore Polytechnic
# (2) National University of Singapore
# Primary Blog: http://teo-en-ming-aka-zhang-enming.blogspot.com
# Secondary Blog: http://enmingteo.wordpress.com
# Youtube Videos: http://www.youtube.com/user/enmingteo
# Xen Tutorials and Video Demos: http://www.xen.org/support/tutorial.html
# Email: space.time.universe@xxxxxxxxx
# MSN: teoenming@xxxxxxxxxxx
# Mobile Phone (Starhub Prepaid): +65-8369-2618
# Street: Bedok Reservoir Road
# Country: Singapore
# First written: 13 November 2009 Friday 6:49 P.M. Singapore time
# Last updated: 13 November 2009 Friday 8:25 P.M. Singapore time
# Last updated: 13 November 2009 Friday 8:59 P.M. Singapore time
# Last updated: 13 November 2009 Friday 9:40 P.M. Singapore time
# Last updated: 14 November 2009 Saturday 3:31 A.M. Singapore time
# Last updated: 15 November 2009 Sunday 1:25 A.M. Singapore time
# Last updated: 15 November 2009 Sunday 8:38 A.M. Singapore time
# Last updated: 19 November 2009 Thursday 2:35 A.M. Singapore time
# Last updated: 19 November 2009 Thursday 3:40 A.M. Singapore time
# REFERNCE: "Geek Sheet: Bare-metal backup and recovery", May 7th, 2008, Jason Perlow
# URL: http://blogs.zdnet.com/BTL/?p=8759
# Usage Instructions:
# Boot up your desktop/server with System Rescue CD version 1.3.2 for i386/amd64.
# Then execute this restore script. You need to adapt this script to work for your environment.
# Download System Rescue CD from http://www.sysresccd.org/Main_Page
# No. of QC Checks Performed on this restore script: 1
###############################################################################################################
# Declare Variables
###############################################################################################################
HARDDISK=/dev/sda
SOURCE=/mnt/hitachi/Xen-VGA-Passthrough-FINAL-Update-2-2009-11-15-02-img
###############################################################################################################
###############################################################################################################
# Restoring Xen Host/Dom0
###############################################################################################################
###############################################################################################################
# Restore the Master Boot Record
dd if=$SOURCE/f11-xen-dom0-sda.mbr of=$HARDDISK bs=512 count=1
# Restore the Partition Geometry
sfdisk --force --no-reread $HARDDISK < $SOURCE/f11-xen-dom0-partition-geometry-sda.sfdisk
# Re-create the LVM2 PV containing the host operating system/dom0
#pvcreate --uuid ??? /dev/sda2
pvcreate -f /dev/sda2
# Re-create the LVM2 PV containing all the virtual machines
#pvcreate --uuid ??? /dev/sda3
pvcreate -f /dev/sda3
# Restore the LVM2 metadata for the volume group containing the host operating system/dom0
vgcfgrestore --file $SOURCE/vg_fedora11_host-vgcfg.lvm2.metadata vg_fedora11_host
# Restore the LVM2 metadata for the volume group containing all the virtual machines
vgcfgrestore --file $SOURCE/virtualmachines-vgcfg.lvm2.metadata virtualmachines
# Activate all the volume groups
vgchange -ay
# Restore all filesystems for the host operating system/dom0
fsarchiver restfs -v $SOURCE/f11-xen-dom0-filesystems.fsa id=0,dest=/dev/sda1 \
id=1,dest=/dev/vg_fedora11_host/lv_home \
id=2,dest=/dev/vg_fedora11_host/lv_root \
id=3,dest=/dev/vg_fedora11_host/lv_var
# Re-create the swap partition
mkswap /dev/vg_fedora11_host/lv_swap
###############################################################################################################
###############################################################################################################
# Restoring Xen-based Virtual Machines/DomUs/Guest Operating Systems/VMs
###############################################################################################################
###############################################################################################################
### NOTE: Check for swap partitions in each virtual machine and do a mkswap.
# VM 1: Fedora 11 x86_64 PV domU (MPICH2 Virtual Supercomputer Center)
###############################################################################################################
zcat $SOURCE/virtualmachines-f11-pv-hpc-node0001.img.gz | dd of=/dev/virtualmachines/f11-pv-hpc-node0001
# VM 2: Fedora 11 x86_64 PV domU (MPICH2 Virtual Supercomputer Center)
###############################################################################################################
zcat $SOURCE/virtualmachines-f11-pv-hpc-node0002.img.gz | dd of=/dev/virtualmachines/f11-pv-hpc-node0002
# VM 3: Fedora 11 x86_64 PV domU (MPICH2 Virtual Supercomputer Center)
###############################################################################################################
zcat $SOURCE/virtualmachines-f11-pv-hpc-node0003.img.gz | dd of=/dev/virtualmachines/f11-pv-hpc-node0003
# VM 4: Fedora 11 x86_64 PV domU (MPICH2 Virtual Supercomputer Center)
###############################################################################################################
zcat $SOURCE/virtualmachines-f11-pv-hpc-node0004.img.gz | dd of=/dev/virtualmachines/f11-pv-hpc-node0004
# VM 5: Fedora 11 x86_64 PV domU (MPICH2 Virtual Supercomputer Center)
###############################################################################################################
zcat $SOURCE/virtualmachines-f11-pv-hpc-node0005.img.gz | dd of=/dev/virtualmachines/f11-pv-hpc-node0005
# VM 6: Fedora 11 x86_64 PV domU (MPICH2 Virtual Supercomputer Center)
###############################################################################################################
zcat $SOURCE/virtualmachines-f11-pv-hpc-node0006.img.gz | dd of=/dev/virtualmachines/f11-pv-hpc-node0006
# VM 7: Fedora 11 x86_64 PV domU (MPICH2 Virtual Supercomputer Center)
###############################################################################################################
zcat $SOURCE/virtualmachines-f11-pv-hpc-node0007.img.gz | dd of=/dev/virtualmachines/f11-pv-hpc-node0007
# VM 8: Fedora 11 x86_64 PV domU (MPICH2 Virtual Supercomputer Center)
###############################################################################################################
zcat $SOURCE/virtualmachines-f11-pv-hpc-node0008.img.gz | dd of=/dev/virtualmachines/f11-pv-hpc-node0008
# VM 9: FreeBSD 8.0 RC2 UNIX amd64 HVM domU
###############################################################################################################
zcat $SOURCE/virtualmachines-freebsd.img.gz | dd of=/dev/virtualmachines/freebsd
# VM 10: OpenSolaris 2009.06 UNIX amd64 PV domU
###############################################################################################################
zcat $SOURCE/virtualmachines-opensolaris.img.gz | dd of=/dev/virtualmachines/opensolaris
# VM 11: Rocks 5.1 x86_64 HPC Compute Cluster HVM domU (based on CentOS 5.2)
###############################################################################################################
# Add partition mappings in /dev/mapper
kpartx -av /dev/virtualmachines/rocks0001
# Restore MBR
dd if=$SOURCE/virtualmachines-rocks0001.mbr of=/dev/virtualmachines/rocks0001 bs=512 count=1
# Restore partition geometry
sfdisk --force --no-reread /dev/virtualmachines/rocks0001 < $SOURCE/virtualmachines-rocks0001.sfdisk
# Restore all filesystems
partimage -e -b restore /dev/mapper/virtualmachines-rocks0001p1 $SOURCE/virtualmachines-rocks0001p1.img.000
partimage -e -b restore /dev/mapper/virtualmachines-rocks0001p2 $SOURCE/virtualmachines-rocks0001p2.img.000
partimage -e -b restore /dev/mapper/virtualmachines-rocks0001p5 $SOURCE/virtualmachines-rocks0001p5.img.000
# Re-create swap
mkswap /dev/mapper/virtualmachines-rocks0001p3
# Delete partition mappings in /dev/mapper
kpartx -dv /dev/virtualmachines/rocks0001
# VM 12: Rocks 5.1 x86_64 HPC Compute Cluster HVM domU (based on CentOS 5.2)
###############################################################################################################
# Add partition mappings in /dev/mapper
kpartx -av /dev/virtualmachines/rocks0002
# Restore MBR
dd if=$SOURCE/virtualmachines-rocks0002.mbr of=/dev/virtualmachines/rocks0002 bs=512 count=1
# Restore partition geometry
sfdisk --force --no-reread /dev/virtualmachines/rocks0002 < $SOURCE/virtualmachines-rocks0002.sfdisk
# Restore all filesystems
partimage -e -b restore /dev/mapper/virtualmachines-rocks0002p1 $SOURCE/virtualmachines-rocks0002p1.img.000
partimage -e -b restore /dev/mapper/virtualmachines-rocks0002p2 $SOURCE/virtualmachines-rocks0002p2.img.000
partimage -e -b restore /dev/mapper/virtualmachines-rocks0002p5 $SOURCE/virtualmachines-rocks0002p5.img.000
# Re-create swap
mkswap /dev/mapper/virtualmachines-rocks0002p3
# Delete partition mappings in /dev/mapper
kpartx -dv /dev/virtualmachines/rocks0002
# VM 13: Rocks 5.1 x86_64 HPC Compute Cluster HVM domU (based on CentOS 5.2)
###############################################################################################################
# Add partition mappings in /dev/mapper
kpartx -av /dev/virtualmachines/rocks0003
# Restore MBR
dd if=$SOURCE/virtualmachines-rocks0003.mbr of=/dev/virtualmachines/rocks0003 bs=512 count=1
# Restore partition geometry
sfdisk --force --no-reread /dev/virtualmachines/rocks0003 < $SOURCE/virtualmachines-rocks0003.sfdisk
# Restore all filesystems
partimage -e -b restore /dev/mapper/virtualmachines-rocks0003p1 $SOURCE/virtualmachines-rocks0003p1.img.000
partimage -e -b restore /dev/mapper/virtualmachines-rocks0003p2 $SOURCE/virtualmachines-rocks0003p2.img.000
partimage -e -b restore /dev/mapper/virtualmachines-rocks0003p5 $SOURCE/virtualmachines-rocks0003p5.img.000
# Re-create swap
mkswap /dev/mapper/virtualmachines-rocks0003p3
# Delete partition mappings in /dev/mapper
kpartx -dv /dev/virtualmachines/rocks0003
# VM 14: Rocks 5.1 x86_64 HPC Compute Cluster HVM domU (based on CentOS 5.2)
###############################################################################################################
# Add partition mappings in /dev/mapper
kpartx -av /dev/virtualmachines/rocks0004
# Restore MBR
dd if=$SOURCE/virtualmachines-rocks0004.mbr of=/dev/virtualmachines/rocks0004 bs=512 count=1
# Restore partition geometry
sfdisk --force --no-reread /dev/virtualmachines/rocks0004 < $SOURCE/virtualmachines-rocks0004.sfdisk
# Restore all filesystems
partimage -e -b restore /dev/mapper/virtualmachines-rocks0004p1 $SOURCE/virtualmachines-rocks0004p1.img.000
partimage -e -b restore /dev/mapper/virtualmachines-rocks0004p2 $SOURCE/virtualmachines-rocks0004p2.img.000
partimage -e -b restore /dev/mapper/virtualmachines-rocks0004p5 $SOURCE/virtualmachines-rocks0004p5.img.000
# Re-create swap
mkswap /dev/mapper/virtualmachines-rocks0004p3
# Delete partition mappings in /dev/mapper
kpartx -dv /dev/virtualmachines/rocks0004
# VM 15: Rocks 5.1 x86_64 HPC Compute Cluster HVM domU (based on CentOS 5.2)
###############################################################################################################
# Add partition mappings in /dev/mapper
kpartx -av /dev/virtualmachines/rocks0005
# Restore MBR
dd if=$SOURCE/virtualmachines-rocks0005.mbr of=/dev/virtualmachines/rocks0005 bs=512 count=1
# Restore partition geometry
sfdisk --force --no-reread /dev/virtualmachines/rocks0005 < $SOURCE/virtualmachines-rocks0005.sfdisk
# Restore all filesystems
partimage -e -b restore /dev/mapper/virtualmachines-rocks0005p1 $SOURCE/virtualmachines-rocks0005p1.img.000
partimage -e -b restore /dev/mapper/virtualmachines-rocks0005p2 $SOURCE/virtualmachines-rocks0005p2.img.000
partimage -e -b restore /dev/mapper/virtualmachines-rocks0005p5 $SOURCE/virtualmachines-rocks0005p5.img.000
# Re-create swap
mkswap /dev/mapper/virtualmachines-rocks0005p3
# Delete partition mappings in /dev/mapper
kpartx -dv /dev/virtualmachines/rocks0005
# VM 16: Slackware64 13.0 amd64 HVM domU
###############################################################################################################
# Add partition mappings in /dev/mapper
kpartx -av /dev/virtualmachines/slackware64
# Restore MBR
dd if=$SOURCE/virtualmachines-slackware64.mbr of=/dev/virtualmachines/slackware64 bs=512 count=1
# Restore partition geometry
sfdisk --force --no-reread /dev/virtualmachines/slackware64 < $SOURCE/virtualmachines-slackware64.sfdisk
# Restore all filesystems
# partimage does not support ext4 filesystems
#partimage -e -b restore /dev/mapper/virtualmachines-slackware64p1 $SOURCE/virtualmachines-slackware64p1.img.000
#partimage -e -b restore /dev/mapper/virtualmachines-slackware64p2 $SOURCE/virtualmachines-slackware64p2.img.000
fsarchiver restfs -v $SOURCE/virtualmachines-slackware64p1.fsa \
id=0,dest=/dev/mapper/virtualmachines-slackware64p1
fsarchiver restfs -v $SOURCE/virtualmachines-slackware64p2.fsa \
id=0,dest=/dev/mapper/virtualmachines-slackware64p2
# Re-create swap
mkswap /dev/mapper/virtualmachines-slackware64p3
# Delete partition mappings in /dev/mapper
kpartx -dv /dev/virtualmachines/slackware64
# VM 17: Ubuntu 9.10 Karmic Koala Linux HVM domU
###############################################################################################################
# Add partition mappings in /dev/mapper
kpartx -av /dev/virtualmachines/ubuntu910
# Restore MBR
dd if=$SOURCE/virtualmachines-ubuntu910.mbr of=/dev/virtualmachines/ubuntu910 bs=512 count=1
# Restore partition geometry
sfdisk --force --no-reread /dev/virtualmachines/ubuntu910 < $SOURCE/virtualmachines-ubuntu910.sfdisk
# Restore all filesystems
# partimage does not support ext4 filesystems
#partimage -e -b restore /dev/mapper/virtualmachines-ubuntu910p1 $SOURCE/virtualmachines-ubuntu910p1.img.000
fsarchiver restfs -v $SOURCE/virtualmachines-ubuntu910p1.fsa \
id=0,dest=/dev/mapper/virtualmachines-ubuntu910p1
# Re-create swap
mkswap /dev/mapper/virtualmachines-ubuntu910p5
# Delete partition mappings in /dev/mapper
kpartx -dv /dev/virtualmachines/ubuntu910
# VM 18: Windows XP Home Edition SP3 32-bit HVM domU with VGA passthrough (requires Intel VT-d)
###############################################################################################################
# Add partition mappings in /dev/mapper
kpartx -av /dev/virtualmachines/winxphome32
# Restore MBR
dd if=$SOURCE/virtualmachines-winxphome32.mbr of=/dev/virtualmachines/winxphome32 bs=512 count=1
# Restore partition geometry
sfdisk --force --no-reread /dev/virtualmachines/winxphome32 < $SOURCE/virtualmachines-winxphome32.sfdisk
# Restore all filesystems
partimage -e -b restore /dev/mapper/virtualmachines-winxphome32p1 $SOURCE/virtualmachines-winxphome32p1.img.000
# Delete partition mappings in /dev/mapper
kpartx -dv /dev/virtualmachines/winxphome32
# VM 19: openSUSE 11.2 x86_64 Linux PV domU
###############################################################################################################
# Add partition mappings in /dev/mapper
kpartx -av /dev/virtualmachines/opensuse
# Restore MBR
dd if=$SOURCE/virtualmachines-opensuse.mbr of=/dev/virtualmachines/opensuse bs=512 count=1
# Restore partition geometry
sfdisk --force --no-reread /dev/virtualmachines/opensuse < $SOURCE/virtualmachines-opensuse.sfdisk
# Restore all filesystems
# partimage does not support ext4 filesystems
#partimage -e -b restore /dev/mapper/virtualmachines-opensuse2 $SOURCE/virtualmachines-opensuse2.img.000
fsarchiver restfs -v $SOURCE/virtualmachines-opensuse2.fsa id=0,dest=/dev/mapper/virtualmachines-opensuse2
# Re-create swap
mkswap /dev/mapper/virtualmachines-opensuse1
# Delete partition mappings in /dev/mapper
kpartx -dv /dev/virtualmachines/opensuse
###############################################################################################################
###############################################################################################################
# Deactivate Logical Volume Manager
vgchange -an
# Sync filesystems
sync
# Reinstall GRUB on the restore harddisk before rebooting
# grub
# grub> root (hd0,0)
# grub> setup (hd0)
# grub> quit
# Reboot the machine
reboot
###############################################################################################################
# EOF
###############################################################################################################
</CODE>
-- fedora-list mailing list fedora-list@xxxxxxxxxx To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines