Mr. Teo En Ming (Zhang Enming)
2009-Nov-12 09:23 UTC
[Fedora-xen] How to Backup and Restore MBR within Logical Volumes?
Hi All, I have several Xen virtual machines within logical volumes using LVM2. I did not use disk images for performance reasons. Conventionally, if I want to clone my virtual machines, I have to dd the LV to an image file. But this consumes a lot of time and harddisk space. So, instead of doing that, I want to use losetup and kpartx with my logical volumes, which contain operating systems of virtual machines. I can backup the filesystems of a virtual machine in this way: # losetup /dev/loop1 /dev/virtualmachines/windows7-x64 virtualmachines is the name of my volume group. windows7-x64 is the logical volume. # kpartx -av /dev/loop1 Then I would see the partitions of the virtual machine within a logical volume, like so: /dev/mapper/loop1p1 /dev/mapper/loop1p2 /dev/mapper/loop1p3 Now that I can access the partitions of the virtual machine within a logical volume, I can use partimage or fsarchiver to backup the partitions (provided the filesystem is supported by the archiver). But the problem is that I can only backup/clone the filesystems of my virtual machine within a logical volume. I can''t backup the Master Boot Record (MBR) of the virtual machine within a logical volume. For example, dd if=/dev/hda of=mbr.hda bs=512 count=1 Because /dev/hda resides in a logical volume. The logical volume is a virtual harddisk for my virtual machine. I would like to know how to backup and also restore the MBR of my virtual machine/guest operating system/domU within a logical volume because the losetup and kpartx procedure only allows me access to the partitions, not the MBR. A complete backup of a virtual machine (and also a bare metal machine) includes the MBR and all filesystems. If there is a catastrophic failure with my logical volumes containing domUs, I would like to 1) re-create the physical volume (PV) 2) re-create the volume group 3) assign the PV to the volume group 4) restore the LVM metadata, i.e. the configuration files for all the logical volumes 5) restore the MBR of my domU 6) restore the filesystems of my domU Please advise. Thank you very much. -- 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@gmail.com Mobile Phone (Starhub Prepaid): +65-8369-2618 Street: Bedok Reservoir Road Country: Singapore
Geert Janssens
2009-Nov-12 09:36 UTC
Re: [Xen-users] How to Backup and Restore MBR within Logical Volumes?
On Thursday 12 November 2009, Mr. Teo En Ming (Zhang Enming) wrote:> Hi All, > > I have several Xen virtual machines within logical volumes using LVM2. I > did not use disk images for performance reasons. > > Conventionally, if I want to clone my virtual machines, I have to dd the LV > to an image file. But this consumes a lot of time and harddisk space. > > So, instead of doing that, I want to use losetup and kpartx with my logical > volumes, which contain operating systems of virtual machines. > > I can backup the filesystems of a virtual machine in this way: > > # losetup /dev/loop1 /dev/virtualmachines/windows7-x64 >Are you sure you need to call losetup first ? I remember I used kpartx directly on the lvm containing my vbd. Also, I think you can treat the lvm based vbd as a real disk. So dd if=/dev/virtualmachines/windows7-x64 of=mbr.w7-x64 bs=512 count=1 should backup your mbr. Anyone correct me if I''m wrong please. Geert -- Kobalt W.I.T. Web & Information Technology Brusselsesteenweg 152 1850 Grimbergen Tel : +32 479 339 655 Email: info@kobaltwit.be _______________________________________________ Xen-users mailing list Xen-users@lists.xensource.com http://lists.xensource.com/xen-users
Mr. Teo En Ming (Zhang Enming)
2009-Nov-12 09:45 UTC
[Fedora-xen] Re: [Xen-users] How to Backup and Restore MBR within Logical Volumes?
> dd if=/dev/virtualmachines/windows7-x64 of=mbr.w7-x64 bs=512 count=1I think if you do this, you are only backing up the first 512 bytes of the logical volume, not the MBR. Someone correct me if I am wrong. -- 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@gmail.com Mobile Phone (Starhub Prepaid): +65-8369-2618 Street: Bedok Reservoir Road Country: Singapore On Thu, Nov 12, 2009 at 9:36 AM, Geert Janssens <info@kobaltwit.be> wrote:> On Thursday 12 November 2009, Mr. Teo En Ming (Zhang Enming) wrote: > > Hi All, > > > > I have several Xen virtual machines within logical volumes using LVM2. I > > did not use disk images for performance reasons. > > > > Conventionally, if I want to clone my virtual machines, I have to dd the > LV > > to an image file. But this consumes a lot of time and harddisk space. > > > > So, instead of doing that, I want to use losetup and kpartx with my > logical > > volumes, which contain operating systems of virtual machines. > > > > I can backup the filesystems of a virtual machine in this way: > > > > # losetup /dev/loop1 /dev/virtualmachines/windows7-x64 > > > Are you sure you need to call losetup first ? > > I remember I used kpartx directly on the lvm containing my vbd. > > Also, I think you can treat the lvm based vbd as a real disk. > > So > dd if=/dev/virtualmachines/windows7-x64 of=mbr.w7-x64 bs=512 count=1 > > should backup your mbr. > > Anyone correct me if I''m wrong please. > > Geert > > -- > Kobalt W.I.T. > Web & Information Technology > Brusselsesteenweg 152 > 1850 Grimbergen > > Tel : +32 479 339 655 > Email: info@kobaltwit.be > > > _______________________________________________ > Xen-users mailing list > Xen-users@lists.xensource.com > http://lists.xensource.com/xen-users >
Veli-Pekka Kestilä
2009-Nov-12 09:51 UTC
Re: [Fedora-xen] How to Backup and Restore MBR within Logical Volumes?
Mr. Teo En Ming (Zhang Enming) wrote:> Hi All, > > I have several Xen virtual machines within logical volumes using LVM2. > I did not use disk images for performance reasons. > > # losetup /dev/loop1 /dev/virtualmachines/windows7-x64 > windows7-x64 is the logical volume. > # kpartx -av /dev/loop1 > > Then I would see the partitions of the virtual machine within a > logical volume, like so: > > /dev/mapper/loop1p1 > /dev/mapper/loop1p2 > /dev/mapper/loop1p3 > > Now that I can access the partitions of the virtual machine within a > logical volume, I can use partimage or fsarchiver to backup the > partitions (provided the filesystem is supported by the archiver). > > But the problem is that I can only backup/clone the filesystems of my > virtual machine within a logical volume. I can''t backup the Master > Boot Record (MBR) of the virtual machine within a logical volume. For > example, > > dd if=/dev/hda of=mbr.hda bs=512 count=1 > > Because /dev/hda resides in a logical volume. The logical volume is a > virtual harddisk for my virtual machine.You can do dd if=/dev/dev/loop1 of=mbr.dha bs=512 count=1 to make the copy of the boot block.> > I would like to know how to backup and also restore the MBR of my > virtual machine/guest operating system/domU within a logical volume > because the losetup and kpartx procedure only allows me access to the > partitions, not the MBR. A complete backup of a virtual machine (and > also a bare metal machine) includes the MBR and all filesystems. > > If there is a catastrophic failure with my logical volumes containing > domUs, I would like to > > 1) re-create the physical volume (PV) > > 2) re-create the volume group > > 3) assign the PV to the volume group > > 4) restore the LVM metadata, i.e. the configuration files for all the > logical volumes > > 5) restore the MBR of my domU > > 6) restore the filesystems of my domU >Of these steps you can recreate 1,2,3 and 4 just by keeping records of their parameters and using normal fdisk, pvcreate, vgcreate and lvcreate commands. For the things inside of lvm you can use losetup to make the loopback device out of the lv where you want to install the quest operating system and then recreate mbr from the file. Problem probably is how to recreate the filesystems if your backup software cannot do it. Also with windows protected system files can be a problem if backup software doesn''t support them. One thing you could of course do is to make the system restore backup inside of the DomU when it''s running. And then boot new DomU when starting up and use the system backup to restore. (of course this is still more work that pure dd from one place to another.) Problem is that everything else than using dd can have it fair share of problems. If the domU can''t be offline too long, you could allocate more space and use the lvm:s instant cloning features (can''t remember the name just now. ) and then use dd with gzip or bzip to make the backup from this clone to keep the space requirements minimum for the stored copies. And have minimum disruption for the DomU. -vpk
Mr. Teo En Ming (Zhang Enming)
2009-Nov-12 09:52 UTC
[Fedora-xen] Re: How to Backup and Restore MBR within Logical Volumes?
> Maybe I didn''t really understand your setup, but... isn''t your mbr simplyon /dev/loop1? Yes, you are right. root@sysresccd /mnt/hitachi/test % fdisk -l /dev/loop1 Disk /dev/loop1: 53.7 GB, 53687091200 bytes 255 heads, 63 sectors/track, 6527 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0x2b362b35 Device Boot Start End Blocks Id System /dev/loop1p1 * 1 6526 52420063+ 7 HPFS/NTFS I am so used with device nomenclature of harddisks being /dev/hda, /dev/hdb, /dev/sda, /dev/md0, /dev/xvda, etc that it didn''t occur to me that the device node of my virtual machine in a logical volume is very simply /dev/loop1 after I have performed the "losetup /dev/loop1 /dev/volumegroup/logicalvolume" step. Thank you very much for enlightening me! Now I can proceed with writing the backup and restore script for my Fedora 11 Dom0 (all partitions using LVM2 logical volumes) and all of my Xen virtual machines (contained in logical volumes). -- 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@gmail.com Mobile Phone (Starhub Prepaid): +65-8369-2618 Street: Bedok Reservoir Road Country: Singapore On Thu, Nov 12, 2009 at 9:38 AM, Roberto Ragusa <mail@robertoragusa.it>wrote:> Mr. Teo En Ming (Zhang Enming) wrote: > > > # kpartx -av /dev/loop1 > [...] > > But the problem is that I can only backup/clone the filesystems of my > > virtual machine within a logical volume. I can''t backup the Master Boot > > Record (MBR) of the virtual machine within a logical volume. For example, > > > > dd if=/dev/hda of=mbr.hda bs=512 count=1 > > > > Because /dev/hda resides in a logical volume. The logical volume is a > > virtual harddisk for my virtual machine. > > Maybe I didn''t really understand your setup, but... isn''t your mbr > simply on /dev/loop1? > > -- > Roberto Ragusa mail at robertoragusa.it > > -- > fedora-list mailing list > fedora-list@redhat.com > To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list > Guidelines: > http://fedoraproject.org/wiki/Communicate/MailingListGuidelines >
Mr. Teo En Ming (Zhang Enming)
2009-Nov-12 10:01 UTC
Re: [Fedora-xen] How to Backup and Restore MBR within Logical Volumes?
Thank you for your advice! Is it called LVM snapshot? -- 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@gmail.com Mobile Phone (Starhub Prepaid): +65-8369-2618 Street: Bedok Reservoir Road Country: Singapore 2009/11/12 Veli-Pekka Kestilä <fedora@guagua.fi>> Mr. Teo En Ming (Zhang Enming) wrote: > >> Hi All, >> >> I have several Xen virtual machines within logical volumes using LVM2. I >> did not use disk images for performance reasons. >> >> # losetup /dev/loop1 /dev/virtualmachines/windows7-x64 >> windows7-x64 is the logical volume. >> # kpartx -av /dev/loop1 >> >> Then I would see the partitions of the virtual machine within a logical >> volume, like so: >> >> /dev/mapper/loop1p1 >> /dev/mapper/loop1p2 >> /dev/mapper/loop1p3 >> >> Now that I can access the partitions of the virtual machine within a >> logical volume, I can use partimage or fsarchiver to backup the partitions >> (provided the filesystem is supported by the archiver). >> >> But the problem is that I can only backup/clone the filesystems of my >> virtual machine within a logical volume. I can''t backup the Master Boot >> Record (MBR) of the virtual machine within a logical volume. For example, >> >> dd if=/dev/hda of=mbr.hda bs=512 count=1 >> >> Because /dev/hda resides in a logical volume. The logical volume is a >> virtual harddisk for my virtual machine. >> > You can do dd if=/dev/dev/loop1 of=mbr.dha bs=512 count=1 to make the copy > of the boot block. > > >> I would like to know how to backup and also restore the MBR of my virtual >> machine/guest operating system/domU within a logical volume because the >> losetup and kpartx procedure only allows me access to the partitions, not >> the MBR. A complete backup of a virtual machine (and also a bare metal >> machine) includes the MBR and all filesystems. >> >> If there is a catastrophic failure with my logical volumes containing >> domUs, I would like to >> >> 1) re-create the physical volume (PV) >> >> 2) re-create the volume group >> >> 3) assign the PV to the volume group >> >> 4) restore the LVM metadata, i.e. the configuration files for all the >> logical volumes >> >> 5) restore the MBR of my domU >> >> 6) restore the filesystems of my domU >> >> Of these steps you can recreate 1,2,3 and 4 just by keeping records of > their parameters and using normal fdisk, pvcreate, vgcreate and lvcreate > commands. > > For the things inside of lvm you can use losetup to make the loopback > device out of the lv where you want to install the quest operating system > and then recreate mbr from the file. Problem probably is how to recreate the > filesystems if your backup software cannot do it. Also with windows > protected system files can be a problem if backup software doesn''t support > them. > > One thing you could of course do is to make the system restore backup > inside of the DomU when it''s running. And then boot new DomU when starting > up and use the system backup to restore. (of course this is still more work > that pure dd from one place to another.) > > Problem is that everything else than using dd can have it fair share of > problems. If the domU can''t be offline too long, you could allocate more > space and use the lvm:s instant cloning features (can''t remember the name > just now. ) and then use dd with gzip or bzip to make the backup from this > clone to keep the space requirements minimum for the stored copies. And have > minimum disruption for the DomU. > > -vpk > > -- > Fedora-xen mailing list > Fedora-xen@redhat.com > https://www.redhat.com/mailman/listinfo/fedora-xen >
Fajar A. Nugraha
2009-Nov-12 10:02 UTC
Re: [Xen-users] Re: How to Backup and Restore MBR within Logical Volumes?
On Thu, Nov 12, 2009 at 4:52 PM, Mr. Teo En Ming (Zhang Enming) <space.time.universe@gmail.com> wrote:> Now I can proceed with writing the > backup and restore script for my Fedora 11 Dom0 (all partitions using LVM2 > logical volumes) and all of my Xen virtual machines (contained in logical > volumes).A reminder though: don''t forget to create a "consistent", unchanging version of domU storage before doing backup. Either by shutting down domU, or by creating LVM snapshot first. Also, if it comes to Windows domUs, I find ntfsclone is better than fsarchiver. One of the reasons is that fsarchiver can not create compressed files during restore. -- Fajar _______________________________________________ Xen-users mailing list Xen-users@lists.xensource.com http://lists.xensource.com/xen-users
Veli-Pekka Kestilä
2009-Nov-12 10:07 UTC
Re: [Fedora-xen] How to Backup and Restore MBR within Logical Volumes?
Mr. Teo En Ming (Zhang Enming) wrote:> Thank you for your advice! > > Is it called LVM snapshot?Yes. That''s what it''s called for. -vpk PS. And please don''t top post. It breaks the ''flow'' of the post and makes it hard to read from the archives. Plus is against the list rules in some of the lists you are cross posting this (which is also bad). It would have been better to ask the question separatedly on different lists instead.> > > > Problem is that everything else than using dd can have it fair > share of problems. If the domU can''t be offline too long, you > could allocate more space and use the lvm:s instant cloning > features (can''t remember the name just now. ) and then use dd with > gzip or bzip to make the backup from this clone to keep the space > requirements minimum for the stored copies. And have minimum > disruption for the DomU. > > -vpk > > -- > Fedora-xen mailing list > Fedora-xen@redhat.com <mailto:Fedora-xen@redhat.com> > https://www.redhat.com/mailman/listinfo/fedora-xen > > > > >
Mr. Teo En Ming (Zhang Enming)
2009-Nov-12 10:10 UTC
[Fedora-xen] Re: [Xen-users] Re: How to Backup and Restore MBR within Logical Volumes?
Hi, I don''t think I will be using the LVM snapshot method. I will simply ensure that my domU is not running, then I proceed to do the losetup and kpartx procedure. Subsequently I will backup the MBR of my domU by dd-ing /dev/loopX and clone all the filesystems of the domU using fsarchiver. I would like to use fsarchiver because it can support LZMA compression. LZMA can compress better than bzip2 and decompress 3x faster than bzip2. partimage only supports gzip and bzip2. -- 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@gmail.com Mobile Phone (Starhub Prepaid): +65-8369-2618 Street: Bedok Reservoir Road Country: Singapore On Thu, Nov 12, 2009 at 10:02 AM, Fajar A. Nugraha <fajar@fajar.net> wrote:> On Thu, Nov 12, 2009 at 4:52 PM, Mr. Teo En Ming (Zhang Enming) > <space.time.universe@gmail.com> wrote: > > Now I can proceed with writing the > > backup and restore script for my Fedora 11 Dom0 (all partitions using > LVM2 > > logical volumes) and all of my Xen virtual machines (contained in logical > > volumes). > > A reminder though: don''t forget to create a "consistent", unchanging > version of domU storage before doing backup. Either by shutting down > domU, or by creating LVM snapshot first. > > Also, if it comes to Windows domUs, I find ntfsclone is better than > fsarchiver. One of the reasons is that fsarchiver can not create > compressed files during restore. > > -- > Fajar >
Mr. Teo En Ming (Zhang Enming)
2009-Nov-12 10:14 UTC
Re: [Fedora-xen] How to Backup and Restore MBR within Logical Volumes?
2009/11/12 Veli-Pekka Kestilä <fedora@guagua.fi>> Mr. Teo En Ming (Zhang Enming) wrote: > >> Thank you for your advice! >> >> Is it called LVM snapshot? >> > Yes. That''s what it''s called for. > > -vpk > > PS. And please don''t top post. It breaks the ''flow'' of the post and makes > it hard to read from the archives. Plus is against the list rules in some of > the lists you are cross posting this (which is also bad). It would have been > better to ask the question separatedly on different lists instead. > >> >> >> >> Problem is that everything else than using dd can have it fair >> share of problems. If the domU can''t be offline too long, you >> could allocate more space and use the lvm:s instant cloning >> features (can''t remember the name just now. ) and then use dd with >> gzip or bzip to make the backup from this clone to keep the space >> requirements minimum for the stored copies. And have minimum >> disruption for the DomU. >> >> -vpk >> >> -- >> Fedora-xen mailing list >> Fedora-xen@redhat.com <mailto:Fedora-xen@redhat.com> >> >> https://www.redhat.com/mailman/listinfo/fedora-xen >> >> >> >> >> >> > -- > Fedora-xen mailing list > Fedora-xen@redhat.com > https://www.redhat.com/mailman/listinfo/fedora-xen >Thank you vpk. I will keep that in mind when I have a new question to ask. -- 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@gmail.com Mobile Phone (Starhub Prepaid): +65-8369-2618 Street: Bedok Reservoir Road Country: Singapore
Fajar A. Nugraha
2009-Nov-12 10:37 UTC
Re: [Xen-users] Re: How to Backup and Restore MBR within Logical Volumes?
On Thu, Nov 12, 2009 at 5:10 PM, Mr. Teo En Ming (Zhang Enming) <space.time.universe@gmail.com> wrote:> Hi, > > I don''t think I will be using the LVM snapshot method. I will simply ensure > that my domU is not running,Ah, so you can live with the down time. It makes things a lot simpler then.> then I proceed to do the losetup and kpartx > procedure.Like others mentioned, you don''t need losetup for LVs. It will only make things slower.> Subsequently I will backup the MBR of my domU by dd-ing > /dev/loopX and clone all the filesystems of the domU using fsarchiver. > > I would like to use fsarchiver because it can support LZMA compression. LZMA > can compress better than bzip2 and decompress 3x faster than bzip2. > partimage only supports gzip and bzip2.If your concern is the size and speed of backup, here''s one final note from me: you might want to look at zfs. Possible use scenarios : - use opensolaris as dom0. Probably the most supported option when it comes to xen + zfs, but you need to be familiar with how opensolaris works. - use external storage server running solaris/opensolaris as iscsi SAN. Think of it as poor-man''s Netapp. - use zfs-fuse inside Linux dom0, and store domU storage as files - use zfs-fuse on domU, and do backup from domU instead of dom0. With zfs, you''d get zfs snapshot (which is like instaneous in-place backup), incremental block-level send (can greatly reduce backup storage size if your data doesn''t change often), optional transparent compression for live data (like what ntfs has). -- Fajar _______________________________________________ Xen-users mailing list Xen-users@lists.xensource.com http://lists.xensource.com/xen-users
Bryn M. Reeves
2009-Nov-12 10:45 UTC
[Xen-users] Re: How to Backup and Restore MBR within Logical Volumes?
On Thu, 2009-11-12 at 09:23 +0000, Mr. Teo En Ming (Zhang Enming) wrote:> Hi All, > > I have several Xen virtual machines within logical volumes using LVM2. > I did not use disk images for performance reasons. > > Conventionally, if I want to clone my virtual machines, I have to dd > the LV to an image file. But this consumes a lot of time and harddisk > space. > > So, instead of doing that, I want to use losetup and kpartx with my > logical volumes, which contain operating systems of virtual machines. > > I can backup the filesystems of a virtual machine in this way: > > # losetup /dev/loop1 /dev/virtualmachines/windows7-x64What''s the point of adding a loopback device on top of the LV? Running kpartx on the LV itself will work just fine and this just adds an unnecessary layer of overhead and complexity unless I am missing something.> dd if=/dev/hda of=mbr.hda bs=512 count=1 > > Because /dev/hda resides in a logical volume. The logical volume is a > virtual harddisk for my virtual machine.Assuming that the LV given above is a whole-disk image containing a DOS MBR partition table: dd if=/dev/virtualmachines/windows7-x64 of=/tmp.mbr.img bs=512 count=1 You could also do the same with the loopN device that you set up earlier, although I still don''t see the need for that step.> 1) re-create the physical volume (PV) > > 2) re-create the volume group > > 3) assign the PV to the volume group > > 4) restore the LVM metadata, i.e. the configuration files for all the > logical volumes > > 5) restore the MBR of my domU > > 6) restore the filesystems of my domUShould work fine, just be sure to test each step so that you are confident and comfortable with it before you find yourself needing to do this in anger. Regards, Bryn. _______________________________________________ Xen-users mailing list Xen-users@lists.xensource.com http://lists.xensource.com/xen-users
Mr. Teo En Ming (Zhang Enming)
2009-Nov-12 10:55 UTC
[Fedora-xen] Re: How to Backup and Restore MBR within Logical Volumes?
On Thu, Nov 12, 2009 at 10:45 AM, Bryn M. Reeves <bmr@redhat.com> wrote:> On Thu, 2009-11-12 at 09:23 +0000, Mr. Teo En Ming (Zhang Enming) wrote: > > Hi All, > > > > I have several Xen virtual machines within logical volumes using LVM2. > > I did not use disk images for performance reasons. > > > > Conventionally, if I want to clone my virtual machines, I have to dd > > the LV to an image file. But this consumes a lot of time and harddisk > > space. > > > > So, instead of doing that, I want to use losetup and kpartx with my > > logical volumes, which contain operating systems of virtual machines. > > > > I can backup the filesystems of a virtual machine in this way: > > > > # losetup /dev/loop1 /dev/virtualmachines/windows7-x64 > > What''s the point of adding a loopback device on top of the LV? Running > kpartx on the LV itself will work just fine and this just adds an > unnecessary layer of overhead and complexity unless I am missing > something. > > > dd if=/dev/hda of=mbr.hda bs=512 count=1 > > > > Because /dev/hda resides in a logical volume. The logical volume is a > > virtual harddisk for my virtual machine. > > Assuming that the LV given above is a whole-disk image containing a DOS > MBR partition table: > > dd if=/dev/virtualmachines/windows7-x64 of=/tmp.mbr.img bs=512 count=1 > > You could also do the same with the loopN device that you set up > earlier, although I still don''t see the need for that step. > > > 1) re-create the physical volume (PV) > > > > 2) re-create the volume group > > > > 3) assign the PV to the volume group > > > > 4) restore the LVM metadata, i.e. the configuration files for all the > > logical volumes > > > > 5) restore the MBR of my domU > > > > 6) restore the filesystems of my domU > > Should work fine, just be sure to test each step so that you are > confident and comfortable with it before you find yourself needing to do > this in anger. > > Regards, > Bryn. > > > -- > fedora-list mailing list > fedora-list@redhat.com > To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list > Guidelines: > http://fedoraproject.org/wiki/Communicate/MailingListGuidelines >Hi Bryn, I have just tried an experiment without the losetup step. I have verified that it works using kpartx only. root@sysresccd /root % kpartx -av /dev/virtualmachines/winxphome32 add map virtualmachines-winxphome32p1 (253:22): 0 104840127 linear /dev/virtualmachines/winxphome32 63 root@sysresccd /root % cd /dev/mapper root@sysresccd /dev/mapper % ls *winxphome32* virtualmachines-winxphome32 virtualmachines-winxphome32p1 root@sysresccd /dev/mapper % ls -al *winxphome32* brw-rw---- 1 root disk 253, 0 2009-11-12 15:49 virtualmachines-winxphome32 brw-rw---- 1 root disk 253, 22 2009-11-12 18:47 virtualmachines-winxphome32p1 root@sysresccd /dev/mapper % ls -al *winxphome32* brw-rw---- 1 root disk 253, 0 2009-11-12 15:49 virtualmachines-winxphome32 brw-rw---- 1 root disk 253, 22 2009-11-12 18:47 virtualmachines-winxphome32p1 root@sysresccd /dev/mapper % fdisk -l virtualmachines-winxphome32 Disk virtualmachines-winxphome32: 53.7 GB, 53687091200 bytes 255 heads, 63 sectors/track, 6527 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0x2b362b35 Device Boot Start End Blocks Id System virtualmachines-winxphome32p1 * 1 6526 52420063+ 7 HPFS/NTFS Without the losetup and the corresponding overhead, it will speed up cloning of my virtual machines within LVs. -- 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@gmail.com Mobile Phone (Starhub Prepaid): +65-8369-2618 Street: Bedok Reservoir Road Country: Singapore
Mr. Teo En Ming (Zhang Enming)
2009-Nov-12 12:32 UTC
[Fedora-xen] Re: How to Backup and Restore MBR within Logical Volumes?
On Thu, Nov 12, 2009 at 10:55 AM, Mr. Teo En Ming (Zhang Enming) < space.time.universe@gmail.com> wrote:> > > On Thu, Nov 12, 2009 at 10:45 AM, Bryn M. Reeves <bmr@redhat.com> wrote: > >> On Thu, 2009-11-12 at 09:23 +0000, Mr. Teo En Ming (Zhang Enming) wrote: >> > Hi All, >> > >> > I have several Xen virtual machines within logical volumes using LVM2. >> > I did not use disk images for performance reasons. >> > >> > Conventionally, if I want to clone my virtual machines, I have to dd >> > the LV to an image file. But this consumes a lot of time and harddisk >> > space. >> > >> > So, instead of doing that, I want to use losetup and kpartx with my >> > logical volumes, which contain operating systems of virtual machines. >> > >> > I can backup the filesystems of a virtual machine in this way: >> > >> > # losetup /dev/loop1 /dev/virtualmachines/windows7-x64 >> >> What''s the point of adding a loopback device on top of the LV? Running >> kpartx on the LV itself will work just fine and this just adds an >> unnecessary layer of overhead and complexity unless I am missing >> something. >> >> > dd if=/dev/hda of=mbr.hda bs=512 count=1 >> > >> > Because /dev/hda resides in a logical volume. The logical volume is a >> > virtual harddisk for my virtual machine. >> >> Assuming that the LV given above is a whole-disk image containing a DOS >> MBR partition table: >> >> dd if=/dev/virtualmachines/windows7-x64 of=/tmp.mbr.img bs=512 count=1 >> >> You could also do the same with the loopN device that you set up >> earlier, although I still don''t see the need for that step. >> >> > 1) re-create the physical volume (PV) >> > >> > 2) re-create the volume group >> > >> > 3) assign the PV to the volume group >> > >> > 4) restore the LVM metadata, i.e. the configuration files for all the >> > logical volumes >> > >> > 5) restore the MBR of my domU >> > >> > 6) restore the filesystems of my domU >> >> Should work fine, just be sure to test each step so that you are >> confident and comfortable with it before you find yourself needing to do >> this in anger. >> >> Regards, >> Bryn. >> >> >> -- >> fedora-list mailing list >> fedora-list@redhat.com >> To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list >> Guidelines: >> http://fedoraproject.org/wiki/Communicate/MailingListGuidelines >> > > Hi Bryn, > > I have just tried an experiment without the losetup step. I have verified > that it works using kpartx only. > > root@sysresccd /root % kpartx -av /dev/virtualmachines/winxphome32 > add map virtualmachines-winxphome32p1 (253:22): 0 104840127 linear > /dev/virtualmachines/winxphome32 63 > root@sysresccd /root % cd /dev/mapper > root@sysresccd /dev/mapper % ls *winxphome32* > virtualmachines-winxphome32 virtualmachines-winxphome32p1 > root@sysresccd /dev/mapper % ls -al *winxphome32* > brw-rw---- 1 root disk 253, 0 2009-11-12 15:49 virtualmachines-winxphome32 > brw-rw---- 1 root disk 253, 22 2009-11-12 18:47 > virtualmachines-winxphome32p1 > root@sysresccd /dev/mapper % ls -al *winxphome32* > brw-rw---- 1 root disk 253, 0 2009-11-12 15:49 virtualmachines-winxphome32 > brw-rw---- 1 root disk 253, 22 2009-11-12 18:47 > virtualmachines-winxphome32p1 > root@sysresccd /dev/mapper % fdisk -l virtualmachines-winxphome32 > > Disk virtualmachines-winxphome32: 53.7 GB, 53687091200 bytes > 255 heads, 63 sectors/track, 6527 cylinders > > Units = cylinders of 16065 * 512 = 8225280 bytes > Disk identifier: 0x2b362b35 > > > Device Boot Start End Blocks Id > System > virtualmachines-winxphome32p1 * 1 6526 52420063+ 7 > HPFS/NTFS > > Without the losetup and the corresponding overhead, it will speed up > cloning of my virtual machines within LVs. > > > > -- > 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@gmail.com > Mobile Phone (Starhub Prepaid): +65-8369-2618 > Street: Bedok Reservoir Road > Country: Singapore >Hi All, I have performed a backup of my F11 Dom0''s PV (60 GB) of 3 logical volumes using fsarchiver with the maximum possible LZMA compression. The operation took 4 hours with 2 compression threads. The resulting backup archive size is 8.1 GB for a PV of 60 GB. My hardware specs: Intel Pentium Dual Core E6300 2.8 GHz Intel Desktop Board DQ45CB 6 GB DDR2-800 memory -- 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@gmail.com Mobile Phone (Starhub Prepaid): +65-8369-2618 Street: Bedok Reservoir Road Country: Singapore
Mr. Teo En Ming (Zhang Enming)
2009-Nov-12 12:34 UTC
[Fedora-xen] Re: How to Backup and Restore MBR within Logical Volumes?
On Thu, Nov 12, 2009 at 12:32 PM, Mr. Teo En Ming (Zhang Enming) < space.time.universe@gmail.com> wrote:> > > On Thu, Nov 12, 2009 at 10:55 AM, Mr. Teo En Ming (Zhang Enming) < > space.time.universe@gmail.com> wrote: > >> >> >> On Thu, Nov 12, 2009 at 10:45 AM, Bryn M. Reeves <bmr@redhat.com> wrote: >> >>> On Thu, 2009-11-12 at 09:23 +0000, Mr. Teo En Ming (Zhang Enming) wrote: >>> > Hi All, >>> > >>> > I have several Xen virtual machines within logical volumes using LVM2. >>> > I did not use disk images for performance reasons. >>> > >>> > Conventionally, if I want to clone my virtual machines, I have to dd >>> > the LV to an image file. But this consumes a lot of time and harddisk >>> > space. >>> > >>> > So, instead of doing that, I want to use losetup and kpartx with my >>> > logical volumes, which contain operating systems of virtual machines. >>> > >>> > I can backup the filesystems of a virtual machine in this way: >>> > >>> > # losetup /dev/loop1 /dev/virtualmachines/windows7-x64 >>> >>> What''s the point of adding a loopback device on top of the LV? Running >>> kpartx on the LV itself will work just fine and this just adds an >>> unnecessary layer of overhead and complexity unless I am missing >>> something. >>> >>> > dd if=/dev/hda of=mbr.hda bs=512 count=1 >>> > >>> > Because /dev/hda resides in a logical volume. The logical volume is a >>> > virtual harddisk for my virtual machine. >>> >>> Assuming that the LV given above is a whole-disk image containing a DOS >>> MBR partition table: >>> >>> dd if=/dev/virtualmachines/windows7-x64 of=/tmp.mbr.img bs=512 count=1 >>> >>> You could also do the same with the loopN device that you set up >>> earlier, although I still don''t see the need for that step. >>> >>> > 1) re-create the physical volume (PV) >>> > >>> > 2) re-create the volume group >>> > >>> > 3) assign the PV to the volume group >>> > >>> > 4) restore the LVM metadata, i.e. the configuration files for all the >>> > logical volumes >>> > >>> > 5) restore the MBR of my domU >>> > >>> > 6) restore the filesystems of my domU >>> >>> Should work fine, just be sure to test each step so that you are >>> confident and comfortable with it before you find yourself needing to do >>> this in anger. >>> >>> Regards, >>> Bryn. >>> >>> >>> -- >>> fedora-list mailing list >>> fedora-list@redhat.com >>> To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list >>> Guidelines: >>> http://fedoraproject.org/wiki/Communicate/MailingListGuidelines >>> >> >> Hi Bryn, >> >> I have just tried an experiment without the losetup step. I have verified >> that it works using kpartx only. >> >> root@sysresccd /root % kpartx -av /dev/virtualmachines/winxphome32 >> add map virtualmachines-winxphome32p1 (253:22): 0 104840127 linear >> /dev/virtualmachines/winxphome32 63 >> root@sysresccd /root % cd /dev/mapper >> root@sysresccd /dev/mapper % ls *winxphome32* >> virtualmachines-winxphome32 virtualmachines-winxphome32p1 >> root@sysresccd /dev/mapper % ls -al *winxphome32* >> brw-rw---- 1 root disk 253, 0 2009-11-12 15:49 >> virtualmachines-winxphome32 >> brw-rw---- 1 root disk 253, 22 2009-11-12 18:47 >> virtualmachines-winxphome32p1 >> root@sysresccd /dev/mapper % ls -al *winxphome32* >> brw-rw---- 1 root disk 253, 0 2009-11-12 15:49 >> virtualmachines-winxphome32 >> brw-rw---- 1 root disk 253, 22 2009-11-12 18:47 >> virtualmachines-winxphome32p1 >> root@sysresccd /dev/mapper % fdisk -l virtualmachines-winxphome32 >> >> Disk virtualmachines-winxphome32: 53.7 GB, 53687091200 bytes >> 255 heads, 63 sectors/track, 6527 cylinders >> >> Units = cylinders of 16065 * 512 = 8225280 bytes >> Disk identifier: 0x2b362b35 >> >> >> Device Boot Start End Blocks >> Id System >> virtualmachines-winxphome32p1 * 1 6526 52420063+ >> 7 HPFS/NTFS >> >> Without the losetup and the corresponding overhead, it will speed up >> cloning of my virtual machines within LVs. >> >> >> >> -- >> 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@gmail.com >> Mobile Phone (Starhub Prepaid): +65-8369-2618 >> Street: Bedok Reservoir Road >> Country: Singapore >> > > Hi All, > > I have performed a backup of my F11 Dom0''s PV (60 GB) of 3 logical volumes > using fsarchiver with the maximum possible LZMA compression. The operation > took 4 hours with 2 compression threads. The resulting backup archive size > is 8.1 GB for a PV of 60 GB. > > My hardware specs: > > Intel Pentium Dual Core E6300 2.8 GHz > Intel Desktop Board DQ45CB > 6 GB DDR2-800 memory > > > -- > 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@gmail.com > Mobile Phone (Starhub Prepaid): +65-8369-2618 > Street: Bedok Reservoir Road > Country: Singapore >The fsarchiver command I have used is: fsarchiver savefs -v -z 9 -j 2 /mnt/hitachi/test/test.fsa /dev/vg_fedora11_host/lv_home /dev/vg_fedora11_host/lv_root /dev/vg_fedora11_host/lv_var -- 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@gmail.com Mobile Phone (Starhub Prepaid): +65-8369-2618 Street: Bedok Reservoir Road Country: Singapore
Mr. Teo En Ming (Zhang Enming)
2009-Nov-12 12:50 UTC
[Fedora-xen] Re: [Xen-users] How to Backup and Restore MBR within Logical Volumes?
On Thu, Nov 12, 2009 at 6:18 PM, Geert Janssens <info@kobaltwit.be> wrote:> On Thursday 12 November 2009, you wrote: > > > dd if=/dev/virtualmachines/windows7-x64 of=mbr.w7-x64 bs=512 count=1 > > > > I think if you do this, you are only backing up the first 512 bytes of > the > > logical volume, not the MBR. > > > > Someone correct me if I am wrong. > > I did some tests just to be sure. As far as I can tell, dd interacts with > lvm > in exactly the same way as with a physical disk or a loop device. > > In the test I copied the first sector directly from the lvm partition or > via > the loop device. It results in exactly the same sector being copied. > > Also, if you try fdisk -l on the lvm disk or the loop device, it results in > the same output. > > Below is the output from my tests: > > [root@aragorn:~]# losetup /dev/loop1 /dev/base/kobaltwit_f11_disk > > [root@aragorn:~]# fdisk -l /dev/base/kobaltwit_f11_disk > > Disk /dev/base/kobaltwit_f11_disk: 10.7 GB, 10737418240 bytes > 255 heads, 63 sectors/track, 1305 cylinders > Units = cylinders of 16065 * 512 = 8225280 bytes > > Device Boot Start End Blocks Id > System > /dev/base/kobaltwit_f11_disk1 * 1 1305 10482381 83 > Linux > [root@aragorn:~]# fdisk -l /dev/base/kobaltwit_f11_disk > > Disk /dev/base/kobaltwit_f11_disk: 10.7 GB, 10737418240 bytes > 255 heads, 63 sectors/track, 1305 cylinders > Units = cylinders of 16065 * 512 = 8225280 bytes > > Device Boot Start End Blocks Id > System > /dev/base/kobaltwit_f11_disk1 * 1 1305 10482381 83 > Linux > > [root@aragorn:~]# dd if=/dev/base/kobaltwit_f11_disk of=mbr.lvm bs=512 > count=1 > 1+0 records in > 1+0 records out > 512 bytes (512 B) copied, 7.6e-05 seconds, 6.7 MB/s > > [root@aragorn:~]# dd if=/dev/loop1 of=mbr.loop bs=512 count=1 > 1+0 records in > 1+0 records out > 512 bytes (512 B) copied, 0.000151 seconds, 3.4 MB/s > > [root@aragorn:~]# diff mbr.l* > [root@aragorn:~]# > > These test seem to indicate to me that the lvm layer in completely > transparent > to userland tools such as fdisk or dd. > > So I still think the losetup step is superfluous and possibly causing > unnecessary overhead. > > Geert > > -- > Kobalt W.I.T. > Web & Information Technology > Brusselsesteenweg 152 > 1850 Grimbergen > > Tel : +32 479 339 655 > Email: info@kobaltwit.be > >Thank you! I will omit the losetup step. -- 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@gmail.com Mobile Phone (Starhub Prepaid): +65-8369-2618 Street: Bedok Reservoir Road Country: Singapore
Mr. Teo En Ming (Zhang Enming)
2009-Nov-12 12:53 UTC
[Fedora-xen] Re: [Xen-users] Re: How to Backup and Restore MBR within Logical Volumes?
On Thu, Nov 12, 2009 at 6:37 PM, Fajar A. Nugraha <fajar@fajar.net> wrote:> On Thu, Nov 12, 2009 at 5:10 PM, Mr. Teo En Ming (Zhang Enming) > <space.time.universe@gmail.com> wrote: > > Hi, > > > > I don''t think I will be using the LVM snapshot method. I will simply > ensure > > that my domU is not running, > > Ah, so you can live with the down time. It makes things a lot simpler then. > > > then I proceed to do the losetup and kpartx > > procedure. > > Like others mentioned, you don''t need losetup for LVs. It will only > make things slower. > > > Subsequently I will backup the MBR of my domU by dd-ing > > /dev/loopX and clone all the filesystems of the domU using fsarchiver. > > > > I would like to use fsarchiver because it can support LZMA compression. > LZMA > > can compress better than bzip2 and decompress 3x faster than bzip2. > > partimage only supports gzip and bzip2. > > > If your concern is the size and speed of backup, here''s one final note > from me: you might want to look at zfs. Possible use scenarios : > - use opensolaris as dom0. Probably the most supported option when it > comes to xen + zfs, but you need to be familiar with how opensolaris > works. > - use external storage server running solaris/opensolaris as iscsi > SAN. Think of it as poor-man''s Netapp. > - use zfs-fuse inside Linux dom0, and store domU storage as files > - use zfs-fuse on domU, and do backup from domU instead of dom0. > > With zfs, you''d get zfs snapshot (which is like instaneous in-place > backup), incremental block-level send (can greatly reduce backup > storage size if your data doesn''t change often), optional transparent > compression for live data (like what ntfs has). > > -- > Fajar >I am not familiar with OpenSolaris but that may change with time. -- 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@gmail.com Mobile Phone (Starhub Prepaid): +65-8369-2618 Street: Bedok Reservoir Road Country: Singapore
Mr. Teo En Ming (Zhang Enming)
2009-Nov-12 16:57 UTC
[Fedora-xen] Re: [Xen-users] Re: How to Backup and Restore MBR within Logical Volumes?
On Thu, Nov 12, 2009 at 8:53 PM, Mr. Teo En Ming (Zhang Enming) < space.time.universe@gmail.com> wrote:> > > On Thu, Nov 12, 2009 at 6:37 PM, Fajar A. Nugraha <fajar@fajar.net> wrote: > >> On Thu, Nov 12, 2009 at 5:10 PM, Mr. Teo En Ming (Zhang Enming) >> <space.time.universe@gmail.com> wrote: >> > Hi, >> > >> > I don''t think I will be using the LVM snapshot method. I will simply >> ensure >> > that my domU is not running, >> >> Ah, so you can live with the down time. It makes things a lot simpler >> then. >> >> > then I proceed to do the losetup and kpartx >> > procedure. >> >> Like others mentioned, you don''t need losetup for LVs. It will only >> make things slower. >> >> > Subsequently I will backup the MBR of my domU by dd-ing >> > /dev/loopX and clone all the filesystems of the domU using fsarchiver. >> > >> > I would like to use fsarchiver because it can support LZMA compression. >> LZMA >> > can compress better than bzip2 and decompress 3x faster than bzip2. >> > partimage only supports gzip and bzip2. >> >> >> If your concern is the size and speed of backup, here''s one final note >> from me: you might want to look at zfs. Possible use scenarios : >> - use opensolaris as dom0. Probably the most supported option when it >> comes to xen + zfs, but you need to be familiar with how opensolaris >> works. >> - use external storage server running solaris/opensolaris as iscsi >> SAN. Think of it as poor-man''s Netapp. >> - use zfs-fuse inside Linux dom0, and store domU storage as files >> - use zfs-fuse on domU, and do backup from domU instead of dom0. >> >> With zfs, you''d get zfs snapshot (which is like instaneous in-place >> backup), incremental block-level send (can greatly reduce backup >> storage size if your data doesn''t change often), optional transparent >> compression for live data (like what ntfs has). >> >> -- >> Fajar >> > > I am not familiar with OpenSolaris but that may change with time. > > > -- > 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@gmail.com > Mobile Phone (Starhub Prepaid): +65-8369-2618 > Street: Bedok Reservoir Road > Country: Singapore > >Hi, I have just finished writing my backup/cloning script. Could anyone help me verify whether my backup script will work? <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 # Email: space.time.universe@gmail.com # MSN: teoenming@hotmail.com # 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 # 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 computer/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 ############################################################################################################### # Declare Variables ############################################################################################################### HARDDISK=/dev/sda DEST=/media/hitachi/test ############################################################################################################### # Cloning Xen Host/Dom0 ############################################################################################################### # Backup MBR dd if=$HARDDISK of=$DEST/f11-xen-dom0-sda.mbr bs=512 count=1 # Activate all logical volumes in all volume groups vgchange -ay # Backup UUIDs of PVs pvdisplay > $DEST/f11-xen-dom0-pvdisplay.txt # Backup LVM Metadata # Backup the configuration of dedicated volume group for dom0 vgcfgbackup -d -v vg_fedora11_host -f $DEST/vg_fedora11_host.vgcfg.backup # Backup the configuration of dedicated volume group for domUs vgcfgbackup -d -v virtualmachines -f $DEST/virtualmachines.vgcfg.backup # Backup /boot partition and all logical volumes of dedicated volume group for host/dom0 fsarchiver savefs -v -z 9 -j 2 $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 physical volumes, so it is not possible to image using partimage or # fsarchiver directly. The only convenient way is to dd the logical volume for the VM, ie. sector by sector # copy. Other methods would be very tedious. # VM 1: Fedora 11 x86_64 PV domU dd if=/dev/virtualmachines/f11-pv-hpc-node0001 | gzip --fast > $DEST/f11-pv-hpc-node0001.img # VM 2: Fedora 11 x86_64 PV domU dd if=/dev/virtualmachines/f11-pv-hpc-node0002 | gzip --fast > $DEST/f11-pv-hpc-node0002.img # VM 3: Fedora 11 x86_64 PV domU dd if=/dev/virtualmachines/f11-pv-hpc-node0003 | gzip --fast > $DEST/f11-pv-hpc-node0003.img # VM 4: Fedora 11 x86_64 PV domU dd if=/dev/virtualmachines/f11-pv-hpc-node0004 | gzip --fast > $DEST/f11-pv-hpc-node0004.img # VM 5: Fedora 11 x86_64 PV domU dd if=/dev/virtualmachines/f11-pv-hpc-node0005 | gzip --fast > $DEST/f11-pv-hpc-node0005.img # VM 6: Fedora 11 x86_64 PV domU dd if=/dev/virtualmachines/f11-pv-hpc-node0006 | gzip --fast > $DEST/f11-pv-hpc-node0006.img # VM 7: Fedora 11 x86_64 PV domU dd if=/dev/virtualmachines/f11-pv-hpc-node0007 | gzip --fast > $DEST/f11-pv-hpc-node0007.img # VM 8: Fedora 11 x86_64 PV domU dd if=/dev/virtualmachines/f11-pv-hpc-node0008 | gzip --fast > $DEST/f11-pv-hpc-node0008.img # VM 9: FreeBSD 8.0 RC2 UNIX amd64 HVM domU dd if=/dev/virtualmachines/freebsd | gzip --fast > $DEST/freebsd.img # VM 10: OpenSolaris 2009.06 UNIX amd64 PV domU dd if=/dev/virtualmachines/opensolaris | gzip --fast > $DEST/opensolaris.img # 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 kpartx -dv /dev/virtualmachines/rocks0001 # VM 12: Rocks 5.1 x86_64 HPC Compute Cluster HVM domU kpartx -av /dev/virtualmachines/rocks0002 dd if=/dev/virtualmachines/rocks0002 of=$DEST/rocks0002.mbr bs=512 count=1 partimage -d -M -b -z1 save /dev/mapper/virtualmachines-rocks0002p1 $DEST/virtualmachines-rocks0002p1.img partimage -d -M -b -z1 save /dev/mapper/virtualmachines-rocks0002p2 $DEST/virtualmachines-rocks0002p2.img partimage -d -M -b -z1 save /dev/mapper/virtualmachines-rocks0002p5 $DEST/virtualmachines-rocks0002p5.img kpartx -dv /dev/virtualmachines/rocks0002 # VM 13: Rocks 5.1 x86_64 HPC Compute Cluster HVM domU kpartx -av /dev/virtualmachines/rocks0003 dd if=/dev/virtualmachines/rocks0003 of=$DEST/rocks0003.mbr bs=512 count=1 partimage -d -M -b -z1 save /dev/mapper/virtualmachines-rocks0003p1 $DEST/virtualmachines-rocks0003p1.img partimage -d -M -b -z1 save /dev/mapper/virtualmachines-rocks0003p2 $DEST/virtualmachines-rocks0003p2.img partimage -d -M -b -z1 save /dev/mapper/virtualmachines-rocks0003p5 $DEST/virtualmachines-rocks0003p5.img kpartx -dv /dev/virtualmachines/rocks0003 # VM 14: Rocks 5.1 x86_64 HPC Compute Cluster HVM domU kpartx -av /dev/virtualmachines/rocks0004 dd if=/dev/virtualmachines/rocks0004 of=$DEST/rocks0004.mbr bs=512 count=1 partimage -d -M -b -z1 save /dev/mapper/virtualmachines-rocks0004p1 $DEST/virtualmachines-rocks0004p1.img partimage -d -M -b -z1 save /dev/mapper/virtualmachines-rocks0004p2 $DEST/virtualmachines-rocks0004p2.img partimage -d -M -b -z1 save /dev/mapper/virtualmachines-rocks0004p5 $DEST/virtualmachines-rocks0004p5.img kpartx -dv /dev/virtualmachines/rocks0004 # VM 15: Rocks 5.1 x86_64 HPC Compute Cluster HVM domU kpartx -av /dev/virtualmachines/rocks0005 dd if=/dev/virtualmachines/rocks0005 of=$DEST/rocks0005.mbr bs=512 count=1 partimage -d -M -b -z1 save /dev/mapper/virtualmachines-rocks0005p1 $DEST/virtualmachines-rocks0005p1.img partimage -d -M -b -z1 save /dev/mapper/virtualmachines-rocks0005p2 $DEST/virtualmachines-rocks0005p2.img partimage -d -M -b -z1 save /dev/mapper/virtualmachines-rocks0005p5 $DEST/virtualmachines-rocks0005p5.img kpartx -dv /dev/virtualmachines/rocks0005 # VM 16: Slackware64 13.0 amd64 HVM domU kpartx -av /dev/virtualmachines/slackware64 dd if=/dev/virtualmachines/slackware64 of=$DEST/slackware64.mbr bs=512 count=1 partimage -d -M -b -z1 save /dev/mapper/virtualmachines-slackware64p1 $DEST/virtualmachines-slackware64p1.img partimage -d -M -b -z1 save /dev/mapper/virtualmachines-slackware64p2 $DEST/virtualmachines-slackware64p2.img kpartx -dv /dev/virtualmachines/slackware64 # VM 17: Ubuntu 9.10 Karmic Koala Linux HVM domU kpartx -av /dev/virtualmachines/ubuntu910 dd if=/dev/virtualmachines/ubuntu910 of=$DEST/ubuntu910.mbr bs=512 count=1 partimage -d -M -b -z1 save /dev/mapper/virtualmachines-ubuntu910p1 $DEST/virtualmachines-ubuntu910p1.img kpartx -dv /dev/virtualmachines/ubuntu910 # VM 18: Windows XP Home Edition SP3 32-bit HVM domU with VGA passthrough (requires Intel VT-d) kpartx -av /dev/virtualmachines/winxphome32 dd if=/dev/virtualmachines/winxphome32 of=$DEST/winxphome32.mbr bs=512 count=1 partimage -d -M -b -z1 save /dev/mapper/virtualmachines-winxphome32p1 $DEST/virtualmachines-winxphome32p1.img kpartx -dv /dev/virtualmachines/winxphome32 # EOF </SCRIPT> 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@gmail.com Mobile Phone (Starhub Prepaid): +65-8369-2618 Street: Bedok Reservoir Road Country: Singapore
Sergey Vlasov
2009-Nov-12 21:40 UTC
Re: [Xen-users] Re: How to Backup and Restore MBR within Logical Volumes?
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.imgNote 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). _______________________________________________ Xen-users mailing list Xen-users@lists.xensource.com http://lists.xensource.com/xen-users
Mr. Teo En Ming (Zhang Enming)
2009-Nov-13 03:17 UTC
[Fedora-xen] Re: [Xen-users] Re: How to Backup and Restore MBR within Logical Volumes?
On Fri, Nov 13, 2009 at 5:40 AM, Sergey Vlasov <vsu@altlinux.ru> 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@lists.xensource.com > 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@gmail.com Mobile Phone (Starhub Prepaid): +65-8369-2618 Street: Bedok Reservoir Road Country: Singapore
Mr. Teo En Ming (Zhang Enming)
2009-Nov-13 05:25 UTC
Re: [Xen-users] Re: How to Backup and Restore MBR within Logical Volumes?
On Fri, Nov 13, 2009 at 11:17 AM, Mr. Teo En Ming (Zhang Enming) < space.time.universe@gmail.com> wrote:> > > On Fri, Nov 13, 2009 at 5:40 AM, Sergey Vlasov <vsu@altlinux.ru> 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@lists.xensource.com >> 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@gmail.com > 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@gmail.com # MSN: teoenming@hotmail.com # 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@gmail.com Mobile Phone (Starhub Prepaid): +65-8369-2618 Street: Bedok Reservoir Road Country: Singapore _______________________________________________ Xen-users mailing list Xen-users@lists.xensource.com http://lists.xensource.com/xen-users
Mr. Teo En Ming (Zhang Enming)
2009-Nov-13 09:35 UTC
Re: [Xen-users] Re: How to Backup and Restore MBR within Logical Volumes?
On Fri, Nov 13, 2009 at 1:25 PM, Mr. Teo En Ming (Zhang Enming) < space.time.universe@gmail.com> wrote:> > > On Fri, Nov 13, 2009 at 11:17 AM, Mr. Teo En Ming (Zhang Enming) < > space.time.universe@gmail.com> wrote: > >> >> >> On Fri, Nov 13, 2009 at 5:40 AM, Sergey Vlasov <vsu@altlinux.ru> 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@lists.xensource.com >>> 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@gmail.com >> 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@gmail.com > # MSN: teoenming@hotmail.com > > # 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@gmail.com > 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> #!/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@gmail.com # MSN: teoenming@hotmail.com # 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 # Last updated: 13 November 2009 Friday 5:23 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: 1 ############################################################################################################### # 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 for All Volume Groups # 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 (MPICH2 Virtual Supercomputer Center) ############################################################################################################### # Sector by sector copy dd if=/dev/virtualmachines/f11-pv-hpc-node0001 | gzip --$GZIP_COMPLEVEL > \ $DEST/virtualmachines-f11-pv-hpc-node0001.img.gz # VM 2: Fedora 11 x86_64 PV domU (MPICH2 Virtual Supercomputer Center) ############################################################################################################### # Sector by sector copy dd if=/dev/virtualmachines/f11-pv-hpc-node0002 | gzip --$GZIP_COMPLEVEL > \ $DEST/virtualmachines-f11-pv-hpc-node0002.img.gz # VM 3: Fedora 11 x86_64 PV domU (MPICH2 Virtual Supercomputer Center) ############################################################################################################### # Sector by sector copy dd if=/dev/virtualmachines/f11-pv-hpc-node0003 | gzip --$GZIP_COMPLEVEL > \ $DEST/virtualmachines-f11-pv-hpc-node0003.img.gz # VM 4: Fedora 11 x86_64 PV domU (MPICH2 Virtual Supercomputer Center) ############################################################################################################### # Sector by sector copy dd if=/dev/virtualmachines/f11-pv-hpc-node0004 | gzip --$GZIP_COMPLEVEL > \ $DEST/virtualmachines-f11-pv-hpc-node0004.img.gz # VM 5: Fedora 11 x86_64 PV domU (MPICH2 Virtual Supercomputer Center) ############################################################################################################### # Sector by sector copy dd if=/dev/virtualmachines/f11-pv-hpc-node0005 | gzip --$GZIP_COMPLEVEL > \ $DEST/virtualmachines-f11-pv-hpc-node0005.img.gz # VM 6: Fedora 11 x86_64 PV domU (MPICH2 Virtual Supercomputer Center) ############################################################################################################### # Sector by sector copy dd if=/dev/virtualmachines/f11-pv-hpc-node0006 | gzip --$GZIP_COMPLEVEL > \ $DEST/virtualmachines-f11-pv-hpc-node0006.img.gz # VM 7: Fedora 11 x86_64 PV domU (MPICH2 Virtual Supercomputer Center) ############################################################################################################### # Sector by sector copy dd if=/dev/virtualmachines/f11-pv-hpc-node0007 | gzip --$GZIP_COMPLEVEL > \ $DEST/virtualmachines-f11-pv-hpc-node0007.img.gz # VM 8: Fedora 11 x86_64 PV domU (MPICH2 Virtual Supercomputer Center) ############################################################################################################### # Sector by sector copy dd if=/dev/virtualmachines/f11-pv-hpc-node0008 | gzip --$GZIP_COMPLEVEL > \ $DEST/virtualmachines-f11-pv-hpc-node0008.img.gz # 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.gz # 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.gz # 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 # 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 (based on CentOS 5.2) ############################################################################################################### # 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 (based on CentOS 5.2) ############################################################################################################### # 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 (based on CentOS 5.2) ############################################################################################################### # 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 (based on CentOS 5.2) ############################################################################################################### # 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@gmail.com Mobile Phone (Starhub Prepaid): +65-8369-2618 Street: Bedok Reservoir Road Country: Singapore _______________________________________________ Xen-users mailing list Xen-users@lists.xensource.com http://lists.xensource.com/xen-users
Mr. Teo En Ming (Zhang Enming)
2009-Nov-13 12:31 UTC
[Xen-users] Re: Re: How to Backup and Restore MBR within Logical Volumes?
On Fri, Nov 13, 2009 at 5:35 PM, Mr. Teo En Ming (Zhang Enming) < space.time.universe@gmail.com> wrote:> > > On Fri, Nov 13, 2009 at 1:25 PM, Mr. Teo En Ming (Zhang Enming) < > space.time.universe@gmail.com> wrote: > >> >> >> On Fri, Nov 13, 2009 at 11:17 AM, Mr. Teo En Ming (Zhang Enming) < >> space.time.universe@gmail.com> wrote: >> >>> >>> >>> On Fri, Nov 13, 2009 at 5:40 AM, Sergey Vlasov <vsu@altlinux.ru> 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@lists.xensource.com >>>> 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@gmail.com >>> 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@gmail.com >> 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@gmail.com > 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@gmail.com # MSN: teoenming@hotmail.com # 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@gmail.com Mobile Phone (Starhub Prepaid): +65-8369-2618 Street: Bedok Reservoir Road Country: Singapore _______________________________________________ Xen-users mailing list Xen-users@lists.xensource.com http://lists.xensource.com/xen-users
Dustin Henning
2009-Nov-13 13:17 UTC
RE: [Fedora-xen] Re: [Xen-users] How to Backup and Restore MBR within Logical Volumes?
As you are running Windows, I will assume that you are using HVM, and therefore that /dev/virtualmachines/windows7-x64 is a hard disk image. As such, the command you listed will back up the MBR, including the partition table. That isn''t to say that Windows 7 doesn''t have additional boot information outside of the MBR, but that information would be included in a file system backup. Wikipedia has the structure of the MBR in a table at http://en.wikipedia.org/wiki/Master_boot_record. On that note, I often use bs=446 when I want the MBR without the partition table, but if you are backing up the partition as opposed to the file structure, then you might as well keep the partition table (or even just back up the image). Dustin From: fedora-xen-bounces@redhat.com [mailto:fedora-xen-bounces@redhat.com] On Behalf Of Mr. Teo En Ming (Zhang Enming) Sent: Thursday, November 12, 2009 04:45 To: Geert Janssens Cc: Community assistance, encouragement, and advice for using Fedora.; xen-users@lists.xensource.com; Fedora Xen Subject: [Fedora-xen] Re: [Xen-users] How to Backup and Restore MBR within Logical Volumes?> dd if=/dev/virtualmachines/windows7-x64 of=mbr.w7-x64 bs=512 count=1I think if you do this, you are only backing up the first 512 bytes of the logical volume, not the MBR. Someone correct me if I am wrong. -- 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@gmail.com Mobile Phone (Starhub Prepaid): +65-8369-2618 Street: Bedok Reservoir Road Country: Singapore On Thu, Nov 12, 2009 at 9:36 AM, Geert Janssens <info@kobaltwit.be> wrote: On Thursday 12 November 2009, Mr. Teo En Ming (Zhang Enming) wrote:> Hi All, > > I have several Xen virtual machines within logical volumes using LVM2. I > did not use disk images for performance reasons. > > Conventionally, if I want to clone my virtual machines, I have to dd theLV> to an image file. But this consumes a lot of time and harddisk space. > > So, instead of doing that, I want to use losetup and kpartx with mylogical> volumes, which contain operating systems of virtual machines. > > I can backup the filesystems of a virtual machine in this way: > > # losetup /dev/loop1 /dev/virtualmachines/windows7-x64 >Are you sure you need to call losetup first ? I remember I used kpartx directly on the lvm containing my vbd. Also, I think you can treat the lvm based vbd as a real disk. So dd if=/dev/virtualmachines/windows7-x64 of=mbr.w7-x64 bs=512 count=1 should backup your mbr. Anyone correct me if I''m wrong please. Geert -- Kobalt W.I.T. Web & Information Technology Brusselsesteenweg 152 1850 Grimbergen Tel : +32 479 339 655 Email: info@kobaltwit.be _______________________________________________ Xen-users mailing list Xen-users@lists.xensource.com http://lists.xensource.com/xen-users
Mr. Teo En Ming (Zhang Enming)
2009-Nov-13 13:52 UTC
[Xen-users] Re: Re: How to Backup and Restore MBR within Logical Volumes?
On Fri, Nov 13, 2009 at 9:17 PM, Dustin Henning <Dustin.Henning@prd-inc.com>wrote:> As you are running Windows, I will assume that you are using HVM, > and therefore that /dev/virtualmachines/windows7-x64 is a hard disk image. > As such, the command you listed will back up the MBR, including the > partition table. That isn''t to say that Windows 7 doesn''t have additional > boot information outside of the MBR, but that information would be included > in a file system backup. Wikipedia has the structure of the MBR in a table > at http://en.wikipedia.org/wiki/Master_boot_record. On that note, I often > use bs=446 when I want the MBR without the partition table, but if you are > backing up the partition as opposed to the file structure, then you might > as > well keep the partition table (or even just back up the image). > Dustin > > From: fedora-xen-bounces@redhat.com [mailto:fedora-xen-bounces@redhat.com] > On Behalf Of Mr. Teo En Ming (Zhang Enming) > Sent: Thursday, November 12, 2009 04:45 > To: Geert Janssens > Cc: Community assistance, encouragement, and advice for using Fedora.; > xen-users@lists.xensource.com; Fedora Xen > Subject: [Fedora-xen] Re: [Xen-users] How to Backup and Restore MBR within > Logical Volumes? > > > dd if=/dev/virtualmachines/windows7-x64 of=mbr.w7-x64 bs=512 count=1 > > I think if you do this, you are only backing up the first 512 bytes of the > logical volume, not the MBR. > > Someone correct me if I am wrong. > > -- > 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@gmail.com > Mobile Phone (Starhub Prepaid): +65-8369-2618 > Street: Bedok Reservoir Road > Country: Singapore > On Thu, Nov 12, 2009 at 9:36 AM, Geert Janssens <info@kobaltwit.be> wrote: > On Thursday 12 November 2009, Mr. Teo En Ming (Zhang Enming) wrote: > > Hi All, > > > > I have several Xen virtual machines within logical volumes using LVM2. I > > did not use disk images for performance reasons. > > > > Conventionally, if I want to clone my virtual machines, I have to dd the > LV > > to an image file. But this consumes a lot of time and harddisk space. > > > > So, instead of doing that, I want to use losetup and kpartx with my > logical > > volumes, which contain operating systems of virtual machines. > > > > I can backup the filesystems of a virtual machine in this way: > > > > # losetup /dev/loop1 /dev/virtualmachines/windows7-x64 > > > Are you sure you need to call losetup first ? > > I remember I used kpartx directly on the lvm containing my vbd. > > Also, I think you can treat the lvm based vbd as a real disk. > > So > dd if=/dev/virtualmachines/windows7-x64 of=mbr.w7-x64 bs=512 count=1 > > should backup your mbr. > > Anyone correct me if I''m wrong please. > > Geert > > -- > Kobalt W.I.T. > Web & Information Technology > Brusselsesteenweg 152 > 1850 Grimbergen > > Tel : +32 479 339 655 > Email: info@kobaltwit.be > > > _______________________________________________ > Xen-users mailing list > Xen-users@lists.xensource.com > http://lists.xensource.com/xen-users > > > > > >Hi Dustin, The MBR backup guide that I was following is this one: Article: MBR tricks with LinuxLink: http://www.tuxation.com/mbr-tricks-with-linux.htmlHere is the final version of my data restore script. Could you check if there are mistakes in it? <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@gmail.com # MSN: teoenming@hotmail.com # 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 # 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=/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 # 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 /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 /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 /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 /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 /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 # 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 /dev/virtualmachines/ubuntu910 < $SOURCE/virtualmachines-ubuntu910.sfdisk # Restore all filesystems partimage -e -b restore /dev/mapper/virtualmachines-ubuntu910p1 $SOURCE/virtualmachines-ubuntu910p1.img.000 # 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 /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@gmail.com Mobile Phone (Starhub Prepaid): +65-8369-2618 Street: Bedok Reservoir Road Country: Singapore _______________________________________________ Xen-users mailing list Xen-users@lists.xensource.com http://lists.xensource.com/xen-users
Maybe Matching Threads
- Xen patches merged to upstream Linux 2.6.36, plans for 2.6.37?
- Regarding libvirt usage
- Batch mode creates huge diffs, bug(s)?
- Using Xen Virtualization Environment for Development and Testing of Supercomputing and High Performance Computing (HPC) Cluster MPICH2 MPI-2 Applications
- Using Xen Virtualization Environment for Development and Testing of Supercomputing and High Performance Computing (HPC) Cluster MPICH2 MPI-2 Applications