Skip to content

Instantly share code, notes, and snippets.

@shamil
Last active May 27, 2024 10:36
Show Gist options
  • Save shamil/62935d9b456a6f9877b5 to your computer and use it in GitHub Desktop.
Save shamil/62935d9b456a6f9877b5 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 - Mount the partition from the VM

mount /dev/nbd0p1 /mnt/somepoint/

Step 5 - After you done, unmount and disconnect

umount /mnt/somepoint/
qemu-nbd --disconnect /dev/nbd0
rmmod nbd
@AysadKozanoglu
Copy link

AysadKozanoglu commented Nov 28, 2023

works fine under OS

lsb_release -a
LSB Version:	core-11.1.0ubuntu4-noarch:printing-11.1.0ubuntu4-noarch:security-11.1.0ubuntu4-noarch
Distributor ID:	Ubuntu
Description:	Ubuntu 22.04.1 LTS
Release:	22.04
Codename:	jammy

i had .img file ending instead of .qcow2

after i checked with qemu-img info XXXX.img

i see that it is a qcow2 format

thanks a lot

@AysadKozanoglu
Copy link

AysadKozanoglu commented Nov 28, 2023

gives me this error, since i made my qcow2 an LVM

“mount: unknown filesystem type LVM2_member”

Is there any other way for me to mount this as an LVM?

you have to remove missing disk from LVM member group, you can read my howto to fix it here:
(http://aysad.cloudns.cc/blog/2023/11/28/lvm/raid1/disk/mount/recovery/howto/)

@marXtevens
Copy link

Thanks. Ckear, concise. Worked on Fedora Server 38.

@SzczurekYT
Copy link

Very useful, but I think it worth to add nbds_max=1 (or 2) to the modprobe, so it only creates one or two devices, instead of 16.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment