To check what is the first usable loop device, run
After that, use the output of that command to link the disk image to the loop device file (using root privileges):
losetup -P /dev/loopX example.img
The -P flag searches through the image for partitions, which you need to mount.
After that, create the folder named example and run the command:
mount /dev/loopXpY example
The disk image should now be mounted in that directory. Depending on the Y variable, the right partition was mounted.
Export a QEMU disk image using the NBD protocol.
Enable NBD on the host
modprobe nbd max_part=8
Connect the QCOW2 as a network block device
qemu-nbd -c /dev/nbd0 /var/lib/vz/images/100/vm-100-disk-1.qcow2
List partitions inside the QCOW2
fdisk /dev/nbd0 -l
Mount the partition from the VM
mount /dev/nbd0p1 /mnt/somepoint/
After you’re done, unmount and disconnect
qemu-nbd -d /dev/nbd0