WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-users

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

To: Sergey Vlasov <vsu@xxxxxxxxxxx>
Subject: Re: [Xen-users] Re: How to Backup and Restore MBR within Logical Volumes?
From: "Mr. Teo En Ming (Zhang Enming)" <space.time.universe@xxxxxxxxx>
Date: Fri, 13 Nov 2009 13:25:51 +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: Thu, 12 Nov 2009 21:27:09 -0800
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type; bh=ysaWjTponRrV+wItz6PFK9qkD5wPwf7Ilf00FKNRN78=; b=m0Hkcp2kD+9c/7bC+uFxgAyeKFGMd5sDEiSMmoqA8x+e8eJYxhKmcALjmDS51ONRWi ot56fw0Tdz2BBbh5+erkJhLlCQRbdsm7DqQgBBLr0PhDx/Gn/Ewfn8xYtc+0cOaZkhqa /dSxRTgPQkub50h1L83I5+S832zAbw3hjKSiM=
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=Prc2OU1HpCBLc2oh+D+b9fc4MpiLAblZ/FKWjQMR2F5fTsPNdJH6TRkYXz5lBIBpyE JQcpy1IM9NMKZohP+1Zz7neSmxIi/geZO2ICeoTmUAJSN4RYxKit0hLdm8ZaMopYN5lB ynUofnkvMD6jhwTWrafi0BeW2GhdPr4Nk3ejo=
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <f712b9cf0911121917p689dcaf2w27955bca87258add@xxxxxxxxxxxxxx>
List-help: <mailto:xen-users-request@lists.xensource.com?subject=help>
List-id: Xen user discussion <xen-users.lists.xensource.com>
List-post: <mailto:xen-users@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-users>, <mailto:xen-users-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-users>, <mailto:xen-users-request@lists.xensource.com?subject=unsubscribe>
References: <f712b9cf0911120123l685a1c53te4d0c7b7634b3e60@xxxxxxxxxxxxxx> <4AFBD787.1090309@xxxxxxxxxxxxxxxx> <f712b9cf0911120152v4db222ddn94cf3ab449caa29a@xxxxxxxxxxxxxx> <7207d96f0911120202h41e8d6b6q3d322e2572d9ab5e@xxxxxxxxxxxxxx> <f712b9cf0911120210h652e5c3fja02e5a6e94742068@xxxxxxxxxxxxxx> <7207d96f0911120237k506c4a30nfe38703eb507f49f@xxxxxxxxxxxxxx> <f712b9cf0911120453g237599b5tebe0f2e1417bb51d@xxxxxxxxxxxxxx> <f712b9cf0911120857v38ec5c06tf1ee2867eb22297@xxxxxxxxxxxxxx> <20091112214031.GA8607@xxxxxxxxxx> <f712b9cf0911121917p689dcaf2w27955bca87258add@xxxxxxxxxxxxxx>
Sender: xen-users-bounces@xxxxxxxxxxxxxxxxxxx


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>
#!/bin/sh

###############################################################################################################
###############################################################################################################
# Script to Backup/Clone 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 12:38 A.M. Singapore time
# Last updated: 13 November 2009 Friday 12:38 A.M. Singapore time
# Last updated: 13 November 2009 Friday 1:20 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 backup script. You need to adapt this script to work for your environment.
# Download System Rescue CD from http://www.sysresccd.org/Main_Page

# FAQ
# Q: Why do I want to write this cloning script when there are many open source cloning software available?
# A: I am previously using Clonezilla. It is a very good cloning software. However, it could not detect all the
#    virtual machines in my LVM2 logical volumes and had to fall back on using dd to image all my domUs,
#    which resulted in an enormous 300 GB (!) backup image set and an extremely lengthy cloning process of
#    7 hours. Clonezilla is very good for LVs which only contain filesystems, but not for LVs which contain
#    virtual machines with MBR, partition geometries and full fledged operating systems. It is very diffcult
#    to image nested logical volumes, i.e. logical volumes within logical volumes. And the PV within a LV is
#    the barrier. So it is not Clonezilla's fault. Anybody who knows how to activate all the logical volumes
#    of all the volume groups within LVM2 physical volumes inside a logical volume hosting a virtual machine,
#    please share your knowledge with me. Thank you very much.

# No. of QC Checks Performed on this backup script: 0

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

HARDDISK=/dev/sda
DEST=/media/hitachi/test
FSA_COMPLEVEL=9
PROCESSOR_CORES=2
GZIP_COMPLEVEL=fast
PARTIMAGE_COMPLEVEL=1

###############################################################################################################
# Create Storage Directory for Backup Images
###############################################################################################################

if [ ! -d $DEST ]
then
    mkdir -p $DEST
fi

###############################################################################################################
###############################################################################################################
# Cloning Xen Host/Dom0
###############################################################################################################
###############################################################################################################

# Backup MBR

dd if=$HARDDISK of=$DEST/f11-xen-dom0-sda.mbr bs=512 count=1

# Backup Partition Geometry
sfdisk -d $HARDDISK > $DEST/f11-xen-dom0-partition-geometry-sda.sfdisk

# Activate all logical volumes in all volume groups

vgchange -ay

# Backup UUIDs of PVs

pvdisplay > $DEST/f11-xen-dom0-pvdisplay.txt

# Backup LVM2 Metadata

# Backup the configuration of dedicated volume group for dom0

vgcfgbackup -d -v vg_fedora11_host -f $DEST/vg_fedora11_host-vgcfg.lvm2.metadata

# Backup the configuration of dedicated volume group for domUs

vgcfgbackup -d -v virtualmachines -f $DEST/virtualmachines-vgcfg.lvm2.metadata

# Backup /boot partition and all logical volumes of dedicated volume group for host/dom0

fsarchiver savefs -v -z $FSA_COMPLEVEL -j $PROCESSOR_CORES $DEST/f11-xen-dom0-filesystems.fsa /dev/sda1 \
/dev/vg_fedora11_host/lv_home /dev/vg_fedora11_host/lv_root /dev/vg_fedora11_host/lv_var

###############################################################################################################
###############################################################################################################
# Cloning Xen-based Virtual Machines/DomUs/Guest Operating Systems/VMs
###############################################################################################################
###############################################################################################################

# The following 8 virtual machines have LVM2 physical volumes, so it is not possible to image using partimage
# or fsarchiver directly, as both do not support PVs.  The only convenient way is to image the logical volume  
# for the VM using dd, ie. sector by sector copy, and then piping it to gzip for a smaller backup image.
# Other methods would have been more involved and tedious.

# VM 1: Fedora 11 x86_64 PV domU
###############################################################################################################

# Sector by sector copy
dd if=/dev/virtualmachines/f11-pv-hpc-node0001 | gzip --$GZIP_COMPLEVEL > \
$DEST/virtualmachines-f11-pv-hpc-node0001.img

# VM 2: Fedora 11 x86_64 PV domU
###############################################################################################################

# Sector by sector copy
dd if=/dev/virtualmachines/f11-pv-hpc-node0002 | gzip --$GZIP_COMPLEVEL > \
$DEST/virtualmachines-f11-pv-hpc-node0002.img

# VM 3: Fedora 11 x86_64 PV domU
###############################################################################################################

# Sector by sector copy
dd if=/dev/virtualmachines/f11-pv-hpc-node0003 | gzip --$GZIP_COMPLEVEL > \
$DEST/virtualmachines-f11-pv-hpc-node0003.img

# VM 4: Fedora 11 x86_64 PV domU
###############################################################################################################

# Sector by sector copy
dd if=/dev/virtualmachines/f11-pv-hpc-node0004 | gzip --$GZIP_COMPLEVEL > \
$DEST/virtualmachines-f11-pv-hpc-node0004.img

# VM 5: Fedora 11 x86_64 PV domU
###############################################################################################################

# Sector by sector copy
dd if=/dev/virtualmachines/f11-pv-hpc-node0005 | gzip --$GZIP_COMPLEVEL > \
$DEST/virtualmachines-f11-pv-hpc-node0005.img

# VM 6: Fedora 11 x86_64 PV domU
###############################################################################################################

# Sector by sector copy
dd if=/dev/virtualmachines/f11-pv-hpc-node0006 | gzip --$GZIP_COMPLEVEL > \
$DEST/virtualmachines-f11-pv-hpc-node0006.img

# VM 7: Fedora 11 x86_64 PV domU
###############################################################################################################

# Sector by sector copy
dd if=/dev/virtualmachines/f11-pv-hpc-node0007 | gzip --$GZIP_COMPLEVEL > \
$DEST/virtualmachines-f11-pv-hpc-node0007.img

# VM 8: Fedora 11 x86_64 PV domU
###############################################################################################################

# Sector by sector copy
dd if=/dev/virtualmachines/f11-pv-hpc-node0008 | gzip --$GZIP_COMPLEVEL > \
$DEST/virtualmachines-f11-pv-hpc-node0008.img

# VM 9: FreeBSD 8.0 RC2 UNIX amd64 HVM domU
###############################################################################################################

# Sector by sector copy
dd if=/dev/virtualmachines/freebsd | gzip --$GZIP_COMPLEVEL > \
$DEST/virtualmachines-freebsd.img

# VM 10: OpenSolaris 2009.06 UNIX amd64 PV domU
###############################################################################################################

# Sector by sector copy
dd if=/dev/virtualmachines/opensolaris | gzip --$GZIP_COMPLEVEL > \
$DEST/virtualmachines-opensolaris.img

# VM 11: Rocks 5.1 x86_64 HPC Compute Cluster HVM domU
###############################################################################################################

# Add partition mappings in /dev/mapper
kpartx -av /dev/virtualmachines/rocks0001

# Backup MBR
dd if=/dev/virtualmachines/rocks0001 of=$DEST/virtualmachines-rocks0001.mbr bs=512 count=1

# Backup Partition Geometry
sfdisk -d /dev/virtualmachines/rocks0001 > $DEST/virtualmachines-rocks0001.sfdisk

# Backup Filesystems
partimage -d -M -b -z$PARTIMAGE_COMPLEVEL save /dev/mapper/virtualmachines-rocks0001p1 \
$DEST/virtualmachines-rocks0001p1.img

partimage -d -M -b -z$PARTIMAGE_COMPLEVEL save /dev/mapper/virtualmachines-rocks0001p2 \
$DEST/virtualmachines-rocks0001p2.img

partimage -d -M -b -z$PARTIMAGE_COMPLEVEL save /dev/mapper/virtualmachines-rocks0001p5 \
$DEST/virtualmachines-rocks0001p5.img

# Delete partition mappings in /dev/mapper
kpartx -dv /dev/virtualmachines/rocks0001

# VM 12: Rocks 5.1 x86_64 HPC Compute Cluster HVM domU
###############################################################################################################

# Add partition mappings in /dev/mapper
kpartx -av /dev/virtualmachines/rocks0002

# Backup MBR
dd if=/dev/virtualmachines/rocks0002 of=$DEST/virtualmachines-rocks0002.mbr bs=512 count=1

# Backup Partition Geometry
sfdisk -d /dev/virtualmachines/rocks0002 > $DEST/virtualmachines-rocks0002.sfdisk

# Backup Filesystems
partimage -d -M -b -z$PARTIMAGE_COMPLEVEL save /dev/mapper/virtualmachines-rocks0002p1 \
$DEST/virtualmachines-rocks0002p1.img

partimage -d -M -b -z$PARTIMAGE_COMPLEVEL save /dev/mapper/virtualmachines-rocks0002p2 \
$DEST/virtualmachines-rocks0002p2.img

partimage -d -M -b -z$PARTIMAGE_COMPLEVEL save /dev/mapper/virtualmachines-rocks0002p5 \
$DEST/virtualmachines-rocks0002p5.img

# Delete partition mappings in /dev/mapper
kpartx -dv /dev/virtualmachines/rocks0002

# VM 13: Rocks 5.1 x86_64 HPC Compute Cluster HVM domU
###############################################################################################################

# Add partition mappings in /dev/mapper
kpartx -av /dev/virtualmachines/rocks0003

# Backup MBR
dd if=/dev/virtualmachines/rocks0003 of=$DEST/virtualmachines-rocks0003.mbr bs=512 count=1

# Backup Partition Geometry
sfdisk -d /dev/virtualmachines/rocks0003 > $DEST/virtualmachines-rocks0003.sfdisk

# Backup Filesystems
partimage -d -M -b -z$PARTIMAGE_COMPLEVEL save /dev/mapper/virtualmachines-rocks0003p1 \
$DEST/virtualmachines-rocks0003p1.img

partimage -d -M -b -z$PARTIMAGE_COMPLEVEL save /dev/mapper/virtualmachines-rocks0003p2 \
$DEST/virtualmachines-rocks0003p2.img

partimage -d -M -b -z$PARTIMAGE_COMPLEVEL save /dev/mapper/virtualmachines-rocks0003p5 \
$DEST/virtualmachines-rocks0003p5.img

# Delete partition mappings in /dev/mapper
kpartx -dv /dev/virtualmachines/rocks0003

# VM 14: Rocks 5.1 x86_64 HPC Compute Cluster HVM domU
###############################################################################################################

# Add partition mappings in /dev/mapper
kpartx -av /dev/virtualmachines/rocks0004

# Backup MBR
dd if=/dev/virtualmachines/rocks0004 of=$DEST/virtualmachines-rocks0004.mbr bs=512 count=1

# Backup Partition Geometry
sfdisk -d /dev/virtualmachines/rocks0004 > $DEST/virtualmachines-rocks0004.sfdisk

# Backup Filesystems
partimage -d -M -b -z$PARTIMAGE_COMPLEVEL save /dev/mapper/virtualmachines-rocks0004p1 \
$DEST/virtualmachines-rocks0004p1.img

partimage -d -M -b -z$PARTIMAGE_COMPLEVEL save /dev/mapper/virtualmachines-rocks0004p2 \
$DEST/virtualmachines-rocks0004p2.img

partimage -d -M -b -z$PARTIMAGE_COMPLEVEL save /dev/mapper/virtualmachines-rocks0004p5 \
$DEST/virtualmachines-rocks0004p5.img

# Delete partition mappings in /dev/mapper
kpartx -dv /dev/virtualmachines/rocks0004

# VM 15: Rocks 5.1 x86_64 HPC Compute Cluster HVM domU
###############################################################################################################

# Add partition mappings in /dev/mapper
kpartx -av /dev/virtualmachines/rocks0005

# Backup MBR
dd if=/dev/virtualmachines/rocks0005 of=$DEST/virtualmachines-rocks0005.mbr bs=512 count=1

# Backup Partition Geometry
sfdisk -d /dev/virtualmachines/rocks0005 > $DEST/virtualmachines-rocks0005.sfdisk

# Backup Filesystems
partimage -d -M -b -z$PARTIMAGE_COMPLEVEL save /dev/mapper/virtualmachines-rocks0005p1 \
$DEST/virtualmachines-rocks0005p1.img

partimage -d -M -b -z$PARTIMAGE_COMPLEVEL save /dev/mapper/virtualmachines-rocks0005p2 \
$DEST/virtualmachines-rocks0005p2.img

partimage -d -M -b -z$PARTIMAGE_COMPLEVEL save /dev/mapper/virtualmachines-rocks0005p5 \
$DEST/virtualmachines-rocks0005p5.img

# 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

# Backup MBR
dd if=/dev/virtualmachines/slackware64 of=$DEST/virtualmachines-slackware64.mbr bs=512 count=1

# Backup Partition Geometry
sfdisk -d /dev/virtualmachines/slackware64 > $DEST/virtualmachines-slackware64.sfdisk

# Backup Filesystems
partimage -d -M -b -z$PARTIMAGE_COMPLEVEL save /dev/mapper/virtualmachines-slackware64p1 \
$DEST/virtualmachines-slackware64p1.img

partimage -d -M -b -z$PARTIMAGE_COMPLEVEL save /dev/mapper/virtualmachines-slackware64p2 \
$DEST/virtualmachines-slackware64p2.img

# 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

# Backup MBR
dd if=/dev/virtualmachines/ubuntu910 of=$DEST/virtualmachines-ubuntu910.mbr bs=512 count=1

# Backup Partition Geometry
sfdisk -d /dev/virtualmachines/ubuntu910 > $DEST/virtualmachines-ubuntu910.sfdisk

# Backup Filesystems
partimage -d -M -b -z$PARTIMAGE_COMPLEVEL save /dev/mapper/virtualmachines-ubuntu910p1 \
$DEST/virtualmachines-ubuntu910p1.img

# 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

# Backup MBR
dd if=/dev/virtualmachines/winxphome32 of=$DEST/virtualmachines-winxphome32.mbr bs=512 count=1

# Backup Partition Geometry
sfdisk -d /dev/virtualmachines/winxphome32 > $DEST/virtualmachines-winxphome32.sfdisk

# Backup Filesystems
partimage -d -M -b -z$PARTIMAGE_COMPLEVEL save /dev/mapper/virtualmachines-winxphome32p1 \
$DEST/virtualmachines-winxphome32p1.img

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

###############################################################################################################
# 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
<Prev in Thread] Current Thread [Next in Thread>