Skip to content

Instantly share code, notes, and snippets.

@shamil
Last active May 18, 2024 13:09
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
@AggamR
Copy link

AggamR commented Jun 30, 2021

thanks! very useful!

@cindrmon
Copy link

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?

@ololobster
Copy link

ololobster commented Dec 13, 2021

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

Hello from December 2021 :)

  1. Run sudo pvs to get a volume group (column VG) for your device.
  2. Run sudo lvdisplay ⟨your VG⟩ to get a LV Path.
  3. Run sudo vgchange -a y to activate all groups.
  4. Now you can mount it: sudo mount ⟨your LV Path⟩ /mnt/somepoint

@bilalyaqoob
Copy link

How to change the "config.plist" file, I don't have permission to edit it.

@gabrielmoura
Copy link

Thanks

@ra7narajm
Copy link

Is there any way to see path of the qcow2 file connected to nbd device (after successful "qemu-nbd -c")?
for example, want to see file name being mounted on /dev/nbd0 from a monitoring program.

@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