Linux – How to mount virtual machine’s LVM partition on KVM host

kvm-virtualizationlinuxlvmvirtualization

If I trying to do following on KVM host:

# kpartx -av /dev/VolGroup00/kvm101_img
add map kvm101_img1 : 0 208782 linear /dev/VolGroup00/kvm101_img 63
add map kvm101_img2 : 0 125612235 linear /dev/VolGroup00/kvm101_img 208845
# mount /dev/mapper/kvm101_img1 /mnt

then I'm getting /boot partition mounted.
But I'm getting an error if I then type following:

# mount /dev/mapper/kvm101_img2 /mnt
mount: you must specify the filesystem type

Here is a fdisk layout on guest machine:

# fdisk -l
Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1          13      104391   83  Linux
/dev/hda2              14        7832    62806117+  8e  Linux LVM

Is it possible to find a root partition on guest and mount it on host system?

Best Answer

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.

Related Topic