Virtualization With KVM On Ubuntu 8.10 - Page 4
6 Creating An LVM-Based VM
LVM-based VMs have some advantages over image-based VMs. They are not as heavy on hard disk IO, and they are easier to back up (using LVM snapshots).
To use LVM-based VMs, you need a volume group that has some free space that is not allocated to any logical volume. In this example, I use the volume group /dev/vg01 with a size of approx. 454GB...
... that contains the logical volume /dev/vg01/root with a size of approx. 292GB - the rest is not allocated and can be used for VMs:
I will now create the virtual machine vm5 as an LVM-based VM. We can use the vmbuilder command again. vmbuilder knows the --raw option which allows to write the VM to a block device (e.g. /dev/vg01/vm5) - I've tried this, and it gave back no errors, however, I was not able to boot the VM (start vm5 didn't show any errors either, but I've never been able to access the VM). Therefore, I will create vm5 as an image-based VM first and then convert it into an LVM-based VM.
mkdir -p ~/vm5/mytemplates/libvirt
Make sure that you create all partitions in just one image file, so don't use --- in the vmbuilder.partition file:
As you see from the vmbuilder.partition file, the VM will use a max. of 20GB, so we create a logical volume called /dev/vg01/vm5 with a size of 20GB now:
lvcreate -L20G -n vm5 vg01
Don't create a file system in the new logical volume!
We will use the qemu-img command to convert the image to an LVM-based VM. The qemu-img command is part of the qemu package which we must install now:
apt-get install qemu
Then we go to the VM's ubuntu-kvm/ directory...
... and convert the image as follows:
qemu-img convert disk0.qcow2 -O raw /dev/vg01/vm5
Afterwards you can delete the disk image:
rm -f disk0.qcow2
Now we must open the VM's xml configuration file /etc/libvirt/qemu/vm5.xml...
... and change the following section...
... so that it looks as follows:
That's it! You can now use virsh to manage the VM.