This is a quick guide to mounting a qcow2 disk images on your host server. This is useful to reset passwords, edit files, or recover something without the virtual machine running.
Step 1 – Enable NBD on the Host
You will need to enable the nbd (network block device) kernel module on the host. This should be available on all Ubuntu servers after Intrepid.
sudo modprobe nbd max_part=8
Step 2- Connect the QCOW2 as network block device
Use qemu-nbd to connect your qcow2 file as a network block device. Note: You will need to specify the full path of qcow2 file even if you are the directory of the qcow files.
sudo qemu-nbd --connect=/dev/nbd0 /mnt/kvm/wordpress-sites.qcow2
Step 3 – Find The Virtual Machine Partitions
You can find a list of the partitions on the vm using the following command
sudo fdisk /dev/nbd0 -l
Step 4 – Mount the partition from the virtual machine.
For example, I want to mount partition 1 and therefore run:
sudo mount /dev/nbd0p1 /mnt/somepoint/
Step 5 – Browse Your VM
You can then just browse the files in mnt/somepoint/
sudo umount /mnt/somepoint/
Then disconnect the disk:
sudo qemu-nbd --disconnect /dev/nbd0