LVM within LVM?

| 2 Comments

I wrote about how to arrange disks on a host that needs to support RH-style virtual machines (VMs) in a flexible way.

And what should you do on the guest (the VM itself)?

Well, following the cited scheme, the VM will be handed an LVM "logical volume" to use.

The VM will treat those bits as a disk (as it would if you created a big file and handed that over, instead). Your only real choice is to partition that virtual disk, and use the resulting partitions in the usual ways.

If you know exactly how to use the VM's disk space, and "it will never change", then create fixed partition(s), slap filesystem(s) on them, and you're done.

If, however, we again assume a need for "flexibility", then LVM is again a good idea -- yes, LVM(guest)-within-LVM(host).

I have been told (but not tried myself) that LVM on the host can "see" the inner-LVM stuff (the guest's) and do things with it, e.g. snapshot it.

(Apparently important: the volume group(s) on the guest must have different names from the volume group(s) on the host.)

But the main virtue of LVM-within-LVM is that it's relatively simple to increase the "disk space" on the guest...

Stop the VM: virsh shutdown guest

On the host, extend the logical volume that is the guest's "disk":

lvextend -L20G /dev/vg0/guest-disk

Restart the VM: virsh start guest

The guest's "disk" just got magically bigger. Use fdisk (or equiv) to make a new "partition" out of the extra space, giving it the LVM type (8e).

Make the new "partition" an LVM "physical volume" (PV):

pvcreate /dev/xvda3

Add the PV to the VM's "volume group" (VG):

vgextend guestvg0 /dev/xvda3

Now you can make one of the "inner" (guest) "logical volumes" (LVs) bigger:

lvextend /dev/guestvg0/lvroot ...

Finally, the filesystem sitting on that LV will need resizing:

resize2fs /dev/guestvg0/lvroot

2 Comments

Why go to all this trouble, when you can just provide the necessary partitions as separate volumes from the outer LVM?

Yes, a reasonable approach. LVM on the host if you don't know
exactly how you'll use the host disk; LVM on the guest if you
don't know what its disk needs will be. For instance, I had a VM
"suddenly" need 80GB instead of 5GB.

There is also the business of "host can do things to/with guest's
logical volumes"... I haven't tried it myself. I can imagine it
useful in some circumstances.

Leave a comment

About this Entry

This page contains a single entry by Will Partain published on March 22, 2010 1:23 AM.

Partitioning for virtualization: RAID and LVM was the previous entry in this blog.

Windows Tedious Transfer (thanks, Microsoft) is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.