How to mount qcow2 image

Thanks to Gilles for pointing out guestmount. Mounting a qcow2 image is very simple on RHEL/Centos/Fedora:

  1. First install guestmount (comes as part of libguestfs-tools in Centos6)

    yum install libguestfs-tools libguestfs
    
  2. Then you should be able to auto-magically mount your qcow2 image using the -i option

    guestmount -a path_to_image.qcow2 -i --ro /mount_point
    

    You can manually specify mount points (within the image) using the -m option.
    As always read the man page on guestmount for more details...

Note: This only addresses the question title. Please see Peter's answer for the differences between qcow2 and ISOs...


Step 1 - Enable NBD on the host

modprobe nbd max_part=8

Step 2 - Connect the QCOW2 as a network block device

qemu-nbd --connect=/dev/nbd0 /var/lib/vz/images/100/vm-100-disk-1.qcow2

Step 3 - List partitions inside the QCOW2

fdisk /dev/nbd0 -l

Step 4 - Mount the partition from the VM

mount /dev/nbd0p1 /mnt/somepoint/

You can also mount the filesystem with normal user permissions, ie. non-root:

mount /dev/nbd0p1 /mnt/somepoint -o uid=$UID,gid=$(id -g)

Step 5 - After you're done, unmount and disconnect

umount /mnt/somepoint/
qemu-nbd --disconnect /dev/nbd0
rmmod nbd

Shamefully stolen from: https://gist.github.com/shamil/62935d9b456a6f9877b5


A loop device just turns a file into a block device. If the file has some special internal mapping of its blocks, the loop device won't translate any of it. qcow2 is special... it has special mapping inside that handles different snapshots of the same blocks stored in different places. If you mount that as a loop device, you'll just get one big block device that doesn't represent the actual data in the image.

Another option is to convert to raw and mount as a loop device:

qemu-img convert -p -O raw oldfile.qcow2 newfile.raw

But then you have to convert it back to qcow2 to use it again as before.

I think using qemu-nbd is not the most efficient IO, but is easy. Mounting it in a VM, like one booted with a live usb, is easy too. Converting doesn't make much sense... it was just an example of how they're different.