How to mount virtual machine's LVM partition on KVM host?

Seems that I finally figured out how to do things I needed. Here is what I did:

# kpartx -av /dev/VolGroup00/kvm101_img
# vgscan

if VolGroup names identical in guest and host systems, then you have to rename guest VolGroup

# vgrename <uuid> VolGroupXX

uuid of VolGroups you can check in vgdisplay. So, the trick is in activating guest VolGroup:

# lvscan
# vgchange -ay VolGroupXX
# lvscan

After that it's easily mounted:

# mount /dev/VolGroupXX/LogVol00 /mnt

Finally, the backward process is:

# umount /mnt
# vgchange -an VolGroupXX
# kpartx -dv /dev/VolGroup00/kvm101_img
# pvscan

The last command cleans the LVM cache and removes the physical volume created by kpartx from LVM.


I'm glad you figured it out for your situation.

In the more general case, the guest drive could be in a variety of formats such as qcow, qcow2, etc., so you wouldn't be able to work on them directly. In this case, you might use something like on the host:

# modprobe nbd
# kvm-nbd -c /dev/nbd0 file.qcow2

Then you could access /dev/nbd0 as the raw guest drive. To stop using this device you should run:

# nbd-client -d /dev/nbd0

If, on the other hand, the guest drive were in raw format, you would use losetup:

# losetup -f file.raw

This would find and use the first available loop device (e.g., /dev/loop0). To stop using it run:

# losetup -d /dev/loop0

After this you would be able to do the kpartx / vgscan / lvscan / mount procedure you describe in your answer.


you can do it using guestfish - http://libguestfs.org/guestfish.1.html


It might be easier just to use guestfish from the libguestfs package which should work out all the annoying details for you instead of trying to do it manually