Moving a Xen Guest into an LVM container from a loopback sparse image is easy enough.
You’ll need to power down the VM using xm shutdown mymachine
Once done, create the logical volume with: lvcreate –name mymachine-disk –size 10G myvg 10G should match the exact size (if not more) of your current VM. Now create the same for the swap file: lvcreate -name mymachine-swap -size 128M myvg. Now edit your machine’s config (/etc/xen/mymachine.cfg), replacing the disk part from:
disk = [
'file:/xen/mymachine/mymachine-swap,sda1,w',
'file:/xen/mymachine/mymachine-disk,sda2,w',
]
to
disk = [
'phy:/dev/myvg/mymachine-swap,sda1,w',
'phy:/dev/myvg/mymachine-disk,sda2,w',
]
And use dd to write the disk to your new LVM filesystem:
dd if=/xen/mymachine/mymachine-disk of=/dev/myvg/mymachine-disk
dd if=/xen/mymachine/mymachine-swap of=/dev/myvg/mymachine-swap
Remembering that you can use killall -SIGUSR1 dd at any time to gain a status update on dd’s IO.
Once done, power up your VM again with xm create mymachine.cfg
Tags: dd, disk, dom0, domu, killall, lvm, xen, xm
Setting up an LVM filesystem is quite easy assuming you have the right tools installed and a recent kernel. LVM has a lot of advantages, most notably the ability to take snapshots of the current filesystem – this is why LVM is often used in live database environments.
Assuming a Debian Lenny machine, get the relevant packages. Some may already be installed: apt-get install lvm2 dmsetup mdadm
In this example, we will assuming that /dev/sda is your boot drive, and that you want to leave it out of your LVM array, but include /dev/sdb and /dev/sdc. Both /dev/sdb and /dev/sdc should be of equal sizes.
Firstly, using fdisk, remove any existing partitions with ‘d’, on /dev/sdb and /dev/sdc, and create one new partition to span the drive. Change the partition type to ‘8e’ which is the LVM type.
Now prepare your physical disk for LVM with the ‘pvcreate’ tool:
pvcreate /dev/sdb1 /dev/sdc1
Note that you can reverse this with pvremove. You can also use pvdisplay now to display information on all physical volumes.
Oh – you do realie that you can use /dev/mdX just as easily to create LVM on your RAID devices?
Now, we need to create a ‘volume group’: vgcreate myvg /dev/sdb1 /dev/sdc1
Tags: dd, ext3, kernel, Linux, lvcreate, lvdisplay, lvm, lvremove, mkfs, mount, pvcreate, pvdisplay, pvremove, resize, tar, vgcreate, vgdisplay, vgremove, xen
I’m going to write 3 articles next, the first on installing Xen on a Debian Lenny host (Dom0) with Debian Lenny guests (DomU) on a regular loopback filesystem. Next I’m going to write about setting up LVM and some basic working examples, and then finally how to move your Xen over to LVM once you realise that you don’t want loopback. This is the same order in which I performed my installation, and covers Xen setup, LVM setup and migration from loopback to LVM which is a valid upgrade path. My Xen installation is entirely automated. Watch this space..