Skip to content

Instantly share code, notes, and snippets.

@polprog
Forked from shamil/mount_qcow2.md
Last active August 23, 2019 09:02
Show Gist options
  • Save polprog/41a0f4c4600bef82631d89161f2cb056 to your computer and use it in GitHub Desktop.
Save polprog/41a0f4c4600bef82631d89161f2cb056 to your computer and use it in GitHub Desktop.
How to mount a qcow2 disk image

How to mount a qcow2 disk image

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

modprobe nbd max_part=8

Step 2 - Connect the QCOW2 as network block device

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

Step 3 - Find The Virtual Machine Partitions

fdisk /dev/nbd0 -l

Step 4 - Create the /dev/nbdXpY devices

According to [1] the partition device files don't appear just like that, you have to run

sudo partprobe /dev/nbd0

1 - https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=824553

Step 5 - Mount the partition from the VM

mount /dev/nbd0p1 /mnt/somepoint/

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

umount /mnt/somepoint/
qemu-nbd --disconnect /dev/nbd0
rmmod nbd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment