How to mount a QEMU Image

Sometimes it is helpful to be able to mount an image under the host system. If you wish to mount a QEMU / KVM disk image you could use qemu-nbd.

First you need to load the module:

 sudo modprobe nbd max_part=8

Then you can share the disk on the network and create the device entries:

 sudo qemu-nbd --connect=/dev/nbd0 file.qcow2

Then you mount it:

 mount /dev/nbd0 /mnt

When done, unmount and unshare it:

 umount /mnt/kvm
 nbd-client -d /dev/nbd0

NB: never mount a QEMU image while QEMU is using it (unless -snapshot is used), or you are likely to corrupt the filesystem on the image.