[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-users] Re: Re: How to Backup and Restore MBR within Logical Volumes?


  • To: Sergey Vlasov <vsu@xxxxxxxxxxx>
  • From: "Mr. Teo En Ming (Zhang Enming)" <space.time.universe@xxxxxxxxx>
  • Date: Fri, 13 Nov 2009 20:31:01 +0800
  • Cc: "Community assistance, encouragement, and advice for using Fedora." <fedora-list@xxxxxxxxxx>, space.time.universe@xxxxxxxxx, xen-users@xxxxxxxxxxxxxxxxxxx, Fedora Xen <fedora-xen@xxxxxxxxxx>
  • Delivery-date: Fri, 13 Nov 2009 04:32:18 -0800
  • Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=pazePZRcjEElT2gt+ydrKeQt/X4Xqx3JqfNE/paHYDvEXNWFMZWEs1jzplgGphY/hU EgyQo3xD7GtGttqd7fp9jfifT4Rxg9WCd/OWh00YiYU/6PhP/xX24whv/8l/0GEvKp3Z hUfQk9Fivc7/2OM/SU+qMHf8bB1vJuDgE/us0=
  • List-id: Xen user discussion <xen-users.lists.xensource.com>



On Fri, Nov 13, 2009 at 5:35 PM, Mr. Teo En Ming (Zhang Enming) <space.time.universe@xxxxxxxxx> wrote:


On Fri, Nov 13, 2009 at 1:25 PM, Mr. Teo En Ming (Zhang Enming) <space.time.universe@xxxxxxxxx> wrote:


On Fri, Nov 13, 2009 at 11:17 AM, Mr. Teo En Ming (Zhang Enming) <space.time.universe@xxxxxxxxx> wrote:


On Fri, Nov 13, 2009 at 5:40 AM, Sergey Vlasov <vsu@xxxxxxxxxxx> wrote:
On Fri, Nov 13, 2009 at 12:57:22AM +0800, Mr. Teo En Ming (Zhang Enming) wrote:
[...]
> # VM 11: Rocks 5.1 x86_64 HPC Compute Cluster HVM domU
>
> kpartx -av /dev/virtualmachines/rocks0001
>
> dd if=/dev/virtualmachines/rocks0001 of=$DEST/rocks0001.mbr bs=512 count=1
>
> partimage -d -M -b -z1 save /dev/mapper/virtualmachines-rocks0001p1
> $DEST/virtualmachines-rocks0001p1.img
>
> partimage -d -M -b -z1 save /dev/mapper/virtualmachines-rocks0001p2
> $DEST/virtualmachines-rocks0001p2.img
>
> partimage -d -M -b -z1 save /dev/mapper/virtualmachines-rocks0001p5
> $DEST/virtualmachines-rocks0001p5.img

Note that this VM (and some other VMs listed in your script) uses
logical partitions.  In this case just saving a copy of MBR will not
be enough to save partition layout - MBR describes only 4 primary
partitions, and restoring just MBR will not restore extended
partitions.

One way to backup the complete partition layout is by saving also
the output of "sfdisk -d $device"; the resulting file can be used as
input to sfdisk to restore all partitions, including logical ones.
Saving MBR is still needed together with sfdisk, because it saves
the boot code (used for HVM) and CHS geometry information (which can
be used during boot in some cases).

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iEYEARECAAYFAkr8gM8ACgkQW82GfkQfsqLa+QCaAqpO5NWhYHtKVi3M5ytERw27
eC0AnjsJuG34MAR1jZRejBiJCVybQvc1
=RRGH
-----END PGP SIGNATURE-----


_______________________________________________
Xen-users mailing list
Xen-users@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-users



Thank you for pointing this out. Otherwise I would made incomplete backups.

Would it be best practice to always backup both the MBR and the partition geometry using sfdisk whenever cloning our harddisks on desktops and servers?

Besides sfdisk, there are also other partitioning tools like fdisk, cfdisk, and parted.

Could these other tools also be used for backing up the partition geometry like sfdisk?

Thank you.


--
Mr. Teo En Ming (Zhang Enming) Dip(Mechatronics) BEng(Hons)(Mechanical Engineering)
Alma Maters:
(1) Singapore Polytechnic
(2) National University of Singapore
My Primary Blog: http://teo-en-ming-aka-zhang-enming.blogspot.com
My Secondary Blog: http://enmingteo.wordpress.com
My Youtube videos: http://www.youtube.com/user/enmingteo
Email: space.time.universe@xxxxxxxxx
Mobile Phone (Starhub Prepaid): +65-8369-2618
Street: Bedok Reservoir Road
Country: Singapore

Hi,

I have made some improvements to the backup/cloning script. Please help me to vet it through for any mistakes. Thank you very much!


<SCRIPT>
       ***SNIPPED***
</SCRIPT>

--
Mr. Teo En Ming (Zhang Enming) Dip(Mechatronics) BEng(Hons)(Mechanical Engineering)
Alma Maters:
(1) Singapore Polytechnic
(2) National University of Singapore
My Primary Blog: http://teo-en-ming-aka-zhang-enming.blogspot.com
My Secondary Blog: http://enmingteo.wordpress.com
My Youtube videos: http://www.youtube.com/user/enmingteo
Email: space.time.universe@xxxxxxxxx
Mobile Phone (Starhub Prepaid): +65-8369-2618
Street: Bedok Reservoir Road
Country: Singapore

Hi All,

This is the final version of my backup script. I have gone through the script once to make sure there are no mistakes. If I want to capture any errors during the execution of the backup/cloning script, which of the following commands do I run?

# ./backup-script.sh > backup.log

OR

# ./backup-script.sh 2> backup.log

After completing the backup script, I will proceed to write the restore script.

If there are any errors, please let me know because I do not want to make any mistakes with the cloning process. Thank you.

<SCRIPT>
***SNIPPED***
</SCRIPT>

--
Mr. Teo En Ming (Zhang Enming) Dip(Mechatronics) BEng(Hons)(Mechanical Engineering)
Alma Maters:
(1) Singapore Polytechnic
(2) National University of Singapore
My Primary Blog: http://teo-en-ming-aka-zhang-enming.blogspot.com
My Secondary Blog: http://enmingteo.wordpress.com
My Youtube videos: http://www.youtube.com/user/enmingteo
Email: space.time.universe@xxxxxxxxx
Mobile Phone (Starhub Prepaid): +65-8369-2618
Street: Bedok Reservoir Road
Country: Singapore

Dear All,

This is the *initial* version of my data restore script.

<SCRIPT>
#!/bin/sh

###############################################################################################################
###############################################################################################################
# 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

# 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: 0

###############################################################################################################
# Declare Variables
###############################################################################################################

HARDDISK=/dev/sda
SOURCE=/media/hitachi/test

###############################################################################################################
###############################################################################################################
# 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 $HARDDISK < $SOURCE/f11-xen-dom0-partition-geometry-sda.sfdisk

# Re-create the LVM2 PV containing the host operating system/dom0
pvcreate --uuid ??? /dev/sda2

# Re-create the LVM2 PV containing all the virtual machines
pvcreate --uuid ??? /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 /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

# 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 /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

# 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 /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

# 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 /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

# 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 /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

# 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 /dev/virtualmachines/slackware64 < $SOURCE/virtualmachines-slackware64.sfdisk

# Restore all 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

# 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 /dev/virtualmachines/ubuntu910 < $SOURCE/virtualmachines-ubuntu910.sfdisk

# Restore all filesystems
partimage -e -b restore /dev/mapper/virtualmachines-ubuntu910p1 $SOURCE/virtualmachines-ubuntu910p1.img.000

# 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 /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

###############################################################################################################
###############################################################################################################

# Deactivate Logical Volume Manager
vgchange -an

# Sync filesystems
sync

# Reboot the machine
reboot

###############################################################################################################
# EOF
###############################################################################################################

</SCRIPT>

--
Mr. Teo En Ming (Zhang Enming) Dip(Mechatronics) BEng(Hons)(Mechanical Engineering)
Alma Maters:
(1) Singapore Polytechnic
(2) National University of Singapore
My Primary Blog: http://teo-en-ming-aka-zhang-enming.blogspot.com
My Secondary Blog: http://enmingteo.wordpress.com
My Youtube videos: http://www.youtube.com/user/enmingteo
Email: space.time.universe@xxxxxxxxx
Mobile Phone (Starhub Prepaid): +65-8369-2618
Street: Bedok Reservoir Road
Country: Singapore
_______________________________________________
Xen-users mailing list
Xen-users@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-users

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.