HowTo: Access files in qcow2 Image

How to access files inside a virtual drive image like qcow2, vmdk,...

Sometimes you might access files inside a virtual drive image to, for example, recover some deleted files, or whatsoever.

Follow these steps to mount the virtual partition and get access to all files.

modprobe nbd max_part=4
qemu-nbd -c /dev/nbd0 -f vmdk /var/tmp/UCS 3.1-0/UCS 3.1-0.vmdk

If nbd is already loaded you might be unable to unload it so qemu-nbd may fail to load partitions and only provides the device itself. In that case you might parse the device to be able to provide the partitions with kpartx.

kpartx -a /dev/nbd0

Now you are able to mount each partition to access them.

# Mount
mount /dev/nbd0p3 /mnt/qemu_image/root
chroot /floppy
# (fast) alles rückgängig machen
umount /mnt/qemu_image
kpartx -d /dev/nbd0
nbd-client -d /dev/nbd0