Exercise: Accessing the virtual drive of a VM
If a VM fails to boot for some reason, you may need to access the virtual drive, analyse the system logs, and fix the configuration.
Below is the procedure how to mount the qcow2 disk image.
Load nbd kernel module for two partitions. It allows to create a mountable block device from the qcow2 file:
modprobe nbd max_part=2
qemu-nbd --connect=/dev/nbd0 kvm3.qcow2
Create a mounting point, /mnt/vm, and mount the root partition of the
mkdir -p /mnt/vm
fdisk /dev/nbd0 -l
mount /dev/nbd0p1 /mnt/vm
Now you should be able to access the virtual drive content in directory
Unmount and disconnect the drive:
qemu-nbd --disconnect /dev/nbd0