Lvm – Accessing linux guest OS filesystem in qcow2 image

libvirtlvmqcow2

I'm attaching VM qcow2 image to get access to files which inside:

modprobe nbd max_part=63
qemu-nbd -n -c /dev/nbd0 /var/lib/libvirt/images/vm-image.qcow2

scanning for volume groups vgscan:

Reading all physical volumes. This may take a while…
No volume groups found

fdisk -l /dev/nbd0 shows only one partition /dev/nbd0p1

And of course when I try to mount mount /dev/nbd0p1 /mnt I got the following:

NTFS signature is missing.
Failed to mount '/dev/nbd0p1': Invalid argument
The device '/dev/nbd0p1' doesn't seem to have a valid NTFS.

Meanwhile, if I boot onto the VM the LVM partitions are present and system looks like ok. The host OS is well, I think, because the qemu-nbd based solution to access the qcow2 images is working well for other guest images where also LVM is present (guest OSes are slightly different releases of the same Linux distributive).

Also tried qemu-img check /var/lib/libvirt/images/vm-image.qcow2:

No errors were found on the image.

So what could be the issue with accessing/activating LVM of guest OS?

Best Answer

Alternatively have a look at guestfish, guestmont or virt-copy-out (both from libguestfs.org).