How to use LVM and Guests

Post Reply
expirobo
Member
Member
Posts: 7
Joined: November 6th, 2011, 6:39 pm

How to use LVM and Guests

Post by expirobo »

If you are interested in running your guest os's from a Logical Volume to reduce the wear on the hard drive, here is one simple way that I used:

First, build and install your Guest OS but make sure it is SHUTDOWN.

Second, create a raw file from you qcow os file:

Code: Select all

qemu-img convert /path/to/image.qcow2 -O raw /path/to/save/disk0.raw


This file 'disk0.raw' is also the exact size the logical volume should be. If you a nervous, make it a little bigger.

Third, go into webmin and click on Logical Volume Management under Hardware:
Create a new logical volume, specifying the size to be exactly or greater than the disk0.raw file size.

Once this is created

Code: Select all

dd if=/path/to/your/saved/disk0.raw of=/dev/<your volume group>/<new logical volume>


Ok, we're done with the conversion. Now edit the "vm1.xml" file (the file that contains the metadata for your guest). This file on my system is located:
/etc/libvirt/qemu/vm1.xml

Edit the lines:

Code: Select all

<disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/vm2/tmpbAUtxu.qcow2'/>
      <target dev='hda' bus='ide'/>
      <address type='drive' controller='0' bus='0' unit='0'/>
</disk>

and change them to

Code: Select all

<disk type='block' device='disk'>
      <driver name='qemu' type='raw'/>
      <source dev='/dev/<your volume group>/<new logical volume>'/>
      <target dev='hda' bus='ide'/>
      <address type='drive' controller='0' bus='0' unit='0'/>
</disk>


Last and most important step. Go into virsh. Type:

Code: Select all

define /etc/libvirt/qemu/your_meta.xml

and hit enter. This will propagate the changes to qemu. Now try booting. If you did everything correctly, you now have your guest running under and LVM. This makes life a little easier!
Post Reply