Mounting qcow2 Images

Working directly with qcow2 images without the need to boot a virtual machine can come in handy from time to time. These files represent virtual storage but unlike a raw byte image you cannot just use losetup. Luckily qemu comes with tools to make this task simple.

First verify that NBD is installed and your qemu installation has been compiled with NBD support.

Getting started, as root:

1
2
3
4
5
6
modprobe nbd
qemu-nbd -c /dev/nbd0 <path_to_qcow2_file>
# show partitions:
parted /dev/nbd0 print
# mount a file system
mount /dev/nbd0p1 /mnt

When everything is finished and the file systems unmounted:

1
qemu-nbd -d /dev/nbd0

Don’t forget the ever useful qemu-img command.

Links: