If like me you find yourself screwing up a virtual machine Xorg configuration so badly that you can’t even switch to any virtual console anymore or, for whatever reason, you need to access the content of a qcow2 image from outside of the VM, most probably from the host, here is an easy way to do it thanks to qemu-nbd:
# modprobe nbd # qemu-nbd -c /dev/nbd0 /path/to/image.qcow2
At this point we have loaded the Network Block Device kernel module and easily created and NBD device backed by our disk image thanks to the qemu-nbd program provided by qemu-kvm.
Now, we just have to identify tha partition(s) we’d like to mount and then mount it/them in the desired directory:
# fdisk -l /dev/nbd0 # mount /dev/nbd0p3 /mnt/vmroot
You can now work in the image as in local filesystem !
Once you’re done, you need to unmount the partition, remove the device and unload the kernel module:
# umount /mnt/vmroot # qemu-nbd -d /dev/nbd0 # rmmod nbd
Hope this little trick found here will help you like it did for me.
EDIT: If you happen to have I/O errors, try using ‘-n’ option of qemu-nbd which disables host cache (as suggested here).