How to Mount qcow2 Image Using QEMU

loop-devicenbdqemu

I've read that with qemu-nbd and the network block device kernel module, I can mount a qcow2 image. I haven't seen any tutorials on mounting a qcow2 via a loop device. Is it possible? If not, why?

I don't really understand the difference between a qcow2 and an iso.

Best Answer

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.

Related Question