This is a quick guide to mounting a qcow2 disk images on your host server. This is useful to reset passwords, edit files, or recover something without the virtual machine running.
Step 1 - Enable NBD on the Host
modprobe nbd max_part=8
Step 2 - Connect the QCOW2 as network block device
qemu-nbd --connect=/dev/nbd0 /var/lib/vz/images/100/vm-100-disk-1.qcow2
Step 3 - Find The Virtual Machine Partitions
fdisk /dev/nbd0 -l
Step 4 - Mount the partition from the VM
mount /dev/nbd0p1 /mnt/somepoint/
Step 5 - After you done, unmount and disconnect
umount /mnt/somepoint/
qemu-nbd --disconnect /dev/nbd0
rmmod nbd
I had the same problem as @poma.
fdisk
listed the partitions but there were no corresponding device files.partx
did not help. Run aspartx -v -a /dev/nbd0
it complained about "invalid argument" and did not create anything.kpartx
helped. First I checked withkpartx -l /dev/nbd0
, then actually created the device files withkpartx -a /dev/nbd0
. The device files appeared in/dev/mapper
.