<font size="4"><b>Restore script:</b></font><br><div class="gmail_quote"><br><CODE><br><font size="1">#!/bin/sh<br>
<br>###############################################################################################################<br>###############################################################################################################<br>

# Script to Restore Xen Host/Dom0 and all DomUs which are using Logical Volumes as Virtual Hard Disks<br>###############################################################################################################<br>
###############################################################################################################<br>
<br># Written by:<br> <br># Mr. Teo En Ming (Zhang Enming) Dip(Mechatronics) BEng(Hons)(Mechanical Engineering)<br># Alma Maters:<br># (1) Singapore Polytechnic<br># (2) National University of Singapore<br># Primary Blog: <a href="http://teo-en-ming-aka-zhang-enming.blogspot.com" target="_blank">http://teo-en-ming-aka-zhang-enming.blogspot.com</a><br>

# Secondary Blog: <a href="http://enmingteo.wordpress.com" target="_blank">http://enmingteo.wordpress.com</a><br># Youtube Videos: <a href="http://www.youtube.com/user/enmingteo" target="_blank">http://www.youtube.com/user/enmingteo</a><br>
# Xen Tutorials and Video Demos: <a href="http://www.xen.org/support/tutorial.html" target="_blank">http://www.xen.org/support/tutorial.html</a><br>
# Email: <a href="mailto:space.time.universe@gmail.com" target="_blank">space.time.universe@gmail.com</a><br># MSN: <a href="mailto:teoenming@hotmail.com" target="_blank">teoenming@hotmail.com</a><br># Mobile Phone (Starhub Prepaid): +65-8369-2618<br>
# Street: Bedok Reservoir Road<br>
# Country: Singapore<br><br># First written: 13 November 2009 Friday 6:49 P.M. Singapore time<br># Last updated: 13 November 2009 Friday 8:25 P.M. Singapore time<br># Last updated: 13 November 2009 Friday 8:59 P.M. Singapore time<br>

# Last updated: 13 November 2009 Friday 9:40 P.M. Singapore time<br><br># REFERNCE: "Geek Sheet: Bare-metal backup and recovery", May 7th, 2008, Jason Perlow<br># URL: <a href="http://blogs.zdnet.com/BTL/?p=8759" target="_blank">http://blogs.zdnet.com/BTL/?p=8759</a><br>

<br># Usage Instructions:<br><br># Boot up your desktop/server with System Rescue CD version 1.3.2 for i386/amd64. <br># Then execute this restore script. You need to adapt this script to work for your environment.<br># Download System Rescue CD from <a href="http://www.sysresccd.org/Main_Page" target="_blank">http://www.sysresccd.org/Main_Page</a><br>

<br># No. of QC Checks Performed on this restore script: 1 <br><br>###############################################################################################################<br># Declare Variables<br>###############################################################################################################<br>

<br>HARDDISK=/dev/sda<br>SOURCE=/media/hitachi/test<br><br>###############################################################################################################<br>###############################################################################################################<br>

# Restoring Xen Host/Dom0<br>###############################################################################################################<br>###############################################################################################################<br>

<br># Restore the Master Boot Record<br>dd if=$SOURCE/f11-xen-dom0-sda.mbr of=$HARDDISK bs=512 count=1<br><br># Restore the Partition Geometry<br>sfdisk $HARDDISK < $SOURCE/f11-xen-dom0-partition-geometry-sda.sfdisk<br>

<br># Re-create the LVM2 PV containing the host operating system/dom0<br>pvcreate --uuid ??? /dev/sda2<br><br># Re-create the LVM2 PV containing all the virtual machines<br>pvcreate --uuid ??? /dev/sda3<br><br># Restore the LVM2 metadata for the volume group containing the host operating system/dom0<br>

vgcfgrestore --file $SOURCE/vg_fedora11_host-vgcfg.lvm2.metadata vg_fedora11_host<br><br># Restore the LVM2 metadata for the volume group containing all the virtual machines<br>vgcfgrestore --file $SOURCE/virtualmachines-vgcfg.lvm2.metadata virtualmachines<br>

<br># Activate all the volume groups<br>vgchange -ay<br><br># Restore all filesystems for the host operating system/dom0<br>fsarchiver restfs -v $SOURCE/f11-xen-dom0-filesystems.fsa id=0,dest=/dev/sda1 \<br>id=1,dest=/dev/vg_fedora11_host/lv_home \<br>

id=2,dest=/dev/vg_fedora11_host/lv_root \<br>id=3,dest=/dev/vg_fedora11_host/lv_var<br><br># Re-create the swap partition<br>mkswap /dev/vg_fedora11_host/lv_swap<br><br>###############################################################################################################<br>

###############################################################################################################<br># Restoring Xen-based Virtual Machines/DomUs/Guest Operating Systems/VMs<br>###############################################################################################################<br>

###############################################################################################################<br><br>### NOTE: Check for swap partitions in each virtual machine and do a mkswap.<br><br># VM 1: Fedora 11 x86_64 PV domU (MPICH2 Virtual Supercomputer Center)<br>

###############################################################################################################<br><br>zcat $SOURCE/virtualmachines-f11-pv-hpc-node0001.img.gz | dd of=/dev/virtualmachines/f11-pv-hpc-node0001<br>

<br># VM 2: Fedora 11 x86_64 PV domU (MPICH2 Virtual Supercomputer Center)<br>###############################################################################################################<br><br>zcat $SOURCE/virtualmachines-f11-pv-hpc-node0002.img.gz | dd of=/dev/virtualmachines/f11-pv-hpc-node0002<br>

<br># VM 3: Fedora 11 x86_64 PV domU (MPICH2 Virtual Supercomputer Center)<br>###############################################################################################################<br><br>zcat $SOURCE/virtualmachines-f11-pv-hpc-node0003.img.gz | dd of=/dev/virtualmachines/f11-pv-hpc-node0003<br>

<br># VM 4: Fedora 11 x86_64 PV domU (MPICH2 Virtual Supercomputer Center)<br>###############################################################################################################<br><br>zcat $SOURCE/virtualmachines-f11-pv-hpc-node0004.img.gz | dd of=/dev/virtualmachines/f11-pv-hpc-node0004<br>

<br># VM 5: Fedora 11 x86_64 PV domU (MPICH2 Virtual Supercomputer Center)<br>###############################################################################################################<br><br>zcat $SOURCE/virtualmachines-f11-pv-hpc-node0005.img.gz | dd of=/dev/virtualmachines/f11-pv-hpc-node0005<br>

<br># VM 6: Fedora 11 x86_64 PV domU (MPICH2 Virtual Supercomputer Center)<br>###############################################################################################################<br><br>zcat $SOURCE/virtualmachines-f11-pv-hpc-node0006.img.gz | dd of=/dev/virtualmachines/f11-pv-hpc-node0006<br>

<br># VM 7: Fedora 11 x86_64 PV domU (MPICH2 Virtual Supercomputer Center)<br>###############################################################################################################<br><br>zcat $SOURCE/virtualmachines-f11-pv-hpc-node0007.img.gz | dd of=/dev/virtualmachines/f11-pv-hpc-node0007<br>

<br># VM 8: Fedora 11 x86_64 PV domU (MPICH2 Virtual Supercomputer Center)<br>###############################################################################################################<br><br>zcat $SOURCE/virtualmachines-f11-pv-hpc-node0008.img.gz | dd of=/dev/virtualmachines/f11-pv-hpc-node0008<br>

<br># VM 9: FreeBSD 8.0 RC2 UNIX amd64 HVM domU<br>###############################################################################################################<br><br>zcat $SOURCE/virtualmachines-freebsd.img.gz | dd of=/dev/virtualmachines/freebsd<br>

<br># VM 10: OpenSolaris 2009.06 UNIX amd64 PV domU<br>###############################################################################################################<br><br>zcat $SOURCE/virtualmachines-opensolaris.img.gz | dd of=/dev/virtualmachines/opensolaris<br>

<br># VM 11: Rocks 5.1 x86_64 HPC Compute Cluster HVM domU (based on CentOS 5.2)<br>###############################################################################################################<br><br># Add partition mappings in /dev/mapper<br>

kpartx -av /dev/virtualmachines/rocks0001<br><br># Restore MBR<br>dd if=$SOURCE/virtualmachines-rocks0001.mbr of=/dev/virtualmachines/rocks0001 bs=512 count=1<br><br># Restore partition geometry<br>sfdisk /dev/virtualmachines/rocks0001 < $SOURCE/virtualmachines-rocks0001.sfdisk<br>

<br># Restore all filesystems<br>partimage -e -b restore /dev/mapper/virtualmachines-rocks0001p1 $SOURCE/virtualmachines-rocks0001p1.img.000<br><br>partimage -e -b restore /dev/mapper/virtualmachines-rocks0001p2 $SOURCE/virtualmachines-rocks0001p2.img.000<br>

<br>partimage -e -b restore /dev/mapper/virtualmachines-rocks0001p5 $SOURCE/virtualmachines-rocks0001p5.img.000<br><br># Re-create swap<br>mkswap /dev/mapper/virtualmachines-rocks0001p3<br><br># Delete partition mappings in /dev/mapper<br>

kpartx -dv /dev/virtualmachines/rocks0001<br><br># VM 12: Rocks 5.1 x86_64 HPC Compute Cluster HVM domU (based on CentOS 5.2)<br>###############################################################################################################<br>

<br># Add partition mappings in /dev/mapper<br>kpartx -av /dev/virtualmachines/rocks0002<br><br># Restore MBR<br>dd if=$SOURCE/virtualmachines-rocks0002.mbr of=/dev/virtualmachines/rocks0002 bs=512 count=1<br><br># Restore partition geometry<br>

sfdisk /dev/virtualmachines/rocks0002 < $SOURCE/virtualmachines-rocks0002.sfdisk<br><br># Restore all filesystems<br>partimage -e -b restore /dev/mapper/virtualmachines-rocks0002p1 $SOURCE/virtualmachines-rocks0002p1.img.000<br>

<br>partimage -e -b restore /dev/mapper/virtualmachines-rocks0002p2 $SOURCE/virtualmachines-rocks0002p2.img.000<br><br>partimage -e -b restore /dev/mapper/virtualmachines-rocks0002p5 $SOURCE/virtualmachines-rocks0002p5.img.000<br>

<br># Re-create swap<br>mkswap /dev/mapper/virtualmachines-rocks0002p3<br><br># Delete partition mappings in /dev/mapper<br>kpartx -dv /dev/virtualmachines/rocks0002<br><br># VM 13: Rocks 5.1 x86_64 HPC Compute Cluster HVM domU (based on CentOS 5.2)<br>

###############################################################################################################<br><br># Add partition mappings in /dev/mapper<br>kpartx -av /dev/virtualmachines/rocks0003<br><br># Restore MBR<br>

dd if=$SOURCE/virtualmachines-rocks0003.mbr of=/dev/virtualmachines/rocks0003 bs=512 count=1<br><br># Restore partition geometry<br>sfdisk /dev/virtualmachines/rocks0003 < $SOURCE/virtualmachines-rocks0003.sfdisk<br><br>

# Restore all filesystems<br>partimage -e -b restore /dev/mapper/virtualmachines-rocks0003p1 $SOURCE/virtualmachines-rocks0003p1.img.000<br><br>partimage -e -b restore /dev/mapper/virtualmachines-rocks0003p2 $SOURCE/virtualmachines-rocks0003p2.img.000<br>

<br>partimage -e -b restore /dev/mapper/virtualmachines-rocks0003p5 $SOURCE/virtualmachines-rocks0003p5.img.000<br><br># Re-create swap<br>mkswap /dev/mapper/virtualmachines-rocks0003p3<br><br># Delete partition mappings in /dev/mapper<br>

kpartx -dv /dev/virtualmachines/rocks0003<br><br># VM 14: Rocks 5.1 x86_64 HPC Compute Cluster HVM domU (based on CentOS 5.2)<br>###############################################################################################################<br>

<br># Add partition mappings in /dev/mapper<br>kpartx -av /dev/virtualmachines/rocks0004<br><br># Restore MBR<br>dd if=$SOURCE/virtualmachines-rocks0004.mbr of=/dev/virtualmachines/rocks0004 bs=512 count=1<br><br># Restore partition geometry<br>

sfdisk /dev/virtualmachines/rocks0004 < $SOURCE/virtualmachines-rocks0004.sfdisk<br><br># Restore all filesystems<br>partimage -e -b restore /dev/mapper/virtualmachines-rocks0004p1 $SOURCE/virtualmachines-rocks0004p1.img.000<br>

<br>partimage -e -b restore /dev/mapper/virtualmachines-rocks0004p2 $SOURCE/virtualmachines-rocks0004p2.img.000<br><br>partimage -e -b restore /dev/mapper/virtualmachines-rocks0004p5 $SOURCE/virtualmachines-rocks0004p5.img.000<br>

<br># Re-create swap<br>mkswap /dev/mapper/virtualmachines-rocks0004p3<br><br># Delete partition mappings in /dev/mapper<br>kpartx -dv /dev/virtualmachines/rocks0004<br><br># VM 15: Rocks 5.1 x86_64 HPC Compute Cluster HVM domU (based on CentOS 5.2)<br>

###############################################################################################################<br><br># Add partition mappings in /dev/mapper<br>kpartx -av /dev/virtualmachines/rocks0005<br><br># Restore MBR<br>

dd if=$SOURCE/virtualmachines-rocks0005.mbr of=/dev/virtualmachines/rocks0005 bs=512 count=1<br><br># Restore partition geometry<br>sfdisk /dev/virtualmachines/rocks0005 < $SOURCE/virtualmachines-rocks0005.sfdisk<br><br>

# Restore all filesystems<br>partimage -e -b restore /dev/mapper/virtualmachines-rocks0005p1 $SOURCE/virtualmachines-rocks0005p1.img.000<br><br>partimage -e -b restore /dev/mapper/virtualmachines-rocks0005p2 $SOURCE/virtualmachines-rocks0005p2.img.000<br>

<br>partimage -e -b restore /dev/mapper/virtualmachines-rocks0005p5 $SOURCE/virtualmachines-rocks0005p5.img.000<br><br># Re-create swap<br>mkswap /dev/mapper/virtualmachines-rocks0005p3<br><br># Delete partition mappings in /dev/mapper<br>

kpartx -dv /dev/virtualmachines/rocks0005<br><br># VM 16: Slackware64 13.0 amd64 HVM domU<br>###############################################################################################################<br><br># Add partition mappings in /dev/mapper<br>

kpartx -av /dev/virtualmachines/slackware64<br><br># Restore MBR<br>dd if=$SOURCE/virtualmachines-slackware64.mbr of=/dev/virtualmachines/slackware64 bs=512 count=1<br><br># Restore partition geometry<br>sfdisk /dev/virtualmachines/slackware64 < $SOURCE/virtualmachines-slackware64.sfdisk<br>

<br># Restore all filesystems<br>partimage -e -b restore /dev/mapper/virtualmachines-slackware64p1 $SOURCE/virtualmachines-slackware64p1.img.000<br><br>partimage -e -b restore /dev/mapper/virtualmachines-slackware64p2 $SOURCE/virtualmachines-slackware64p2.img.000<br>

<br># Re-create swap<br>mkswap /dev/mapper/virtualmachines-slackware64p3<br><br># Delete partition mappings in /dev/mapper<br>kpartx -dv /dev/virtualmachines/slackware64<br><br># VM 17: Ubuntu 9.10 Karmic Koala Linux HVM domU<br>

###############################################################################################################<br><br># Add partition mappings in /dev/mapper<br>kpartx -av /dev/virtualmachines/ubuntu910<br><br># Restore MBR<br>

dd if=$SOURCE/virtualmachines-ubuntu910.mbr of=/dev/virtualmachines/ubuntu910 bs=512 count=1<br><br># Restore partition geometry<br>sfdisk /dev/virtualmachines/ubuntu910 < $SOURCE/virtualmachines-ubuntu910.sfdisk<br><br>

# Restore all filesystems<br>partimage -e -b restore /dev/mapper/virtualmachines-ubuntu910p1 $SOURCE/virtualmachines-ubuntu910p1.img.000<br><br># Re-create swap<br>mkswap /dev/mapper/virtualmachines-ubuntu910p5<br><br># Delete partition mappings in /dev/mapper<br>

kpartx -dv /dev/virtualmachines/ubuntu910<br><br># VM 18: Windows XP Home Edition SP3 32-bit HVM domU with VGA passthrough (requires Intel VT-d)<br>###############################################################################################################<br>

<br># Add partition mappings in /dev/mapper<br>kpartx -av /dev/virtualmachines/winxphome32<br><br># Restore MBR<br>dd if=$SOURCE/virtualmachines-winxphome32.mbr of=/dev/virtualmachines/winxphome32 bs=512 count=1<br><br># Restore partition geometry<br>

sfdisk /dev/virtualmachines/winxphome32 < $SOURCE/virtualmachines-winxphome32.sfdisk<br><br># Restore all filesystems<br>partimage -e -b restore /dev/mapper/virtualmachines-winxphome32p1 $SOURCE/virtualmachines-winxphome32p1.img.000<br>

<br># Delete partition mappings in /dev/mapper<br>kpartx -dv /dev/virtualmachines/winxphome32<br><br>###############################################################################################################<br>###############################################################################################################<br>

<br># Deactivate Logical Volume Manager<br>vgchange -an<br><br># Sync filesystems<br>sync<br><br># Reboot the machine<br>reboot<br><br>###############################################################################################################<br>

# EOF<br>###############################################################################################################</font><br></CODE><br><br><br>
</div>