When using XEN virtualization it's good practice to use LVM volumes as raw disk devices for the vm guests. The main advantage is that there is no file system for the Xen host to manage and the guest has direct access to the physical volume = better performance!
Another advantage is that you can leverage LVM snapshots adding a similar function to your Xen setup as known in VMWare.
One drawback when using LVM for your virtual guests is that the vm's disk is less portable. There are tools that can handle LVM imaging, but dd is the OSS tool giving you a 1:1 copy of your disk. It's free & it's proven.
dd's known drawback is that the dd dump files get big and time to backup/restore a LVM volume can be lengthy.
Here's how to speed things up and also save on space needed for your LVM images & backups by combining dd with gzip. On modern hardware you can get speeds up to ~90Mb/sec - meaning you can restore a template or image of 15 GB in 3 to 4 minutes.
NOTE: With big data partitions containing a small percentage of data (25% or less of the disk total), it's better to use traditional backup methods. Here dd will lose you precious time backing up parts that contain no real data.
To create an image from the LVM volume:
NOTE: Always make sure your guest is shutdown to ensure data integrity.
dd if=/dev/[lvmsystem]/[lvmpartition] bs=64k | gzip -c > /[path for your image file]/[machine_disk name].img.gz
This command tells dd to use your LVM volume as input using a block size of 64k, the pipe then hands this input stream over to gzip and that zips the stream to the given img.gz file.
* If your source LVM volume contains errors due to disk failure or other, you can tell dd to copy all parts of the disk it can acces. To do this add options conv=sync,noerror before the bs=64k statement.
Restore and Image / Template to an LVM volume:
*If necessary first create a LVM volume where you want the copy written back. It must be at lease the same size (or bigger) than the original LVM volume where the image was taken from.
gunzip -c /[path containing your image file]/[machine_disk name].img.gz | dd of=/dev/[lvmsystem]/[lvmpartition] bs=64k
LVM with multiple hosts
Hi, I'm using SLES10SP2 with XEN and PlatespinOrchestrate 2.0. I have an EMC array disk (CX4) and 3 hosts whith ~20 guests.
Actually I'm using OSF2 filesystem to make a cluster, so I can provide guest on differents hosts (not at the same time :-).
But OSF is not so really fun (no snapshot, ...).
Do you know if it's possible to do the same with LVM ?
My 3 hosts must have access of all guests drives, so I can start guest on each host.
Thanks for you reply (*munged*)
LVM vs OCFS2
Yes, LVM can be used in clustered environments & it will perform very well. There is one drawback in this as LVM2 is not cluster aware. This can be a major drawback if not calculated in to your setup.
In short that means that if you use LVM2 in a Xen cluster environment you'll have to make sure that the VM's don't end up in the situation that they will be running on two or more Xen hosts at the same time (not a good thing!).
We do have LVM in setups upto 5 SLES 10 Xen nodes, but have either disabled automatic HA we normally use with heartbeat or use Convirt to manage the VM's. The last one is a very cost effective management tool.
With SLES 11 there is cLVM, but that requires the HAE extension. That should however work well with PlateSpin Orchestrate you are already using.
Having said that, when using OCFS's you already have a good clone/DR scenario as you are able to manage the disk based VM files. If OCFS2 is working for you, than that might be a better scenario for you.
We did however have performance issues and did not like the limitations OCFS2 had. Haven't looked into the improvements of the latest OCFS2 code.. so this could well be a dated impression.
Any way to mount the image?
Is there anyway to mount the image that was create?
re: Any way to mount the image?
Seeing the zipped file contains a disk dump, there is no way I know of to mount the image directly. Could be there are tools out there for the task.
The way to do it in this case:
If you want to edit the image contents, you have the option to create a new (temporary) LVM volume and write back the dd image to the LVM volume. After having dumped the image back to the LVM volume, you can mount it and edit the contents (or boot it up as VM - of course be careful with duplicate ip assignments).
If you want to save the modified LVM contents as the new state, just dump back the LVM volume to a new image file.
It may not be as instant as a tool like Ghost Explorer or such, but just as powerful as you also have the added option to maintain your templates by adding the latest updates and so forth.
After having done your maintenance you can simply remove the temporary LVM volume you created.
RE: Any way to mount the image
This is a /really/ late comment...
It depends on whether your VM has LVM inside it or not. (NOTE that it /shouldn't/ - there's no reason to load down the VM with LVM, do all the disk management at the dom0)
If you do have LVM inside, this URL discusses how to mount it using mapper, kpartx and pvscan. The system you are mounting it on must already be running LVM.
http://forums.fedoraforum.org/showthread.php?t=211093
If the VM image isn't using LVM inside, the image can be mounted using the offset and loopback mount options.
Your image is called xyz.img and uses ext2 or ext3. You will mount it on /mnt.
fdisk -lu xyz.img | grep Linux | grep -w '83' | grep xyz \
grep -v swap
where the output has 7 fields, take the 3rd field and multiply by 512 to get the offset, if there are 6 fields, take the 2nd field and multiply by 512 for it's offset
mount -o loop,offset=<offset> -t ext2 xyz.img /mnt
The 'fdisk -lu' displays the partition offsets in 512byte blocks. The boot partition has 7 fields in the output, all other partitions have 6 (boot is marked with '*').
The offset option of mount says to skip X bytes of the file before looking for the magic number of the filesystem to mount. The loop option invokes the loopback device mechanism to mount a file as a device.