Skip to content

Instantly share code, notes, and snippets.

@pshchelo
Last active December 30, 2025 08:44
Show Gist options
  • Select an option

  • Save pshchelo/6ffabbffaedc46456b39c037d16e1d8c to your computer and use it in GitHub Desktop.

Select an option

Save pshchelo/6ffabbffaedc46456b39c037d16e1d8c to your computer and use it in GitHub Desktop.
List of commands to mount/unmount a qcow2 image conatining LVM partitions.
# kudos to dzaku at consolechars.wordpress.com
### MOUNT qcow2 image with lvm partitions
# ensure nbd can handle that many partitions
sudo modprobe nbd max_part=8
# present image as block device through NBD
sudo qemu-nbd --connect=/dev/nbd0 <image.qcow2>
# check the disk partitions, see if LVM_member is there
sudo fdisk /dev/nbd0 -l
# some time partition devices are not created, use partx for that
sudo partx -a /dev/nbd0
# list devices corresponding to partitions
sudo ls /dev/nbd0*
# refresh PhysVolume cache for this device
sudo pvscan --cache /dev/nbd0p<N>
# find VolGroups
sudo vgscan
# find Volumes, check what is found and their status
sudo lvscan
# activate newly found VolGroups
sudo vgchange -ay
# mount the lvm partition to /mnt
sudo mount /dev/mapper/<lvm-partition> /mnt
### USE the mounted partition, e.g
ls /mnt
### UNMOUNT
# unmount LVM partition
sudo umount /mnt
# deactivate VolGroup
sudo vgchange -an <lv-volume>
# disconnect image from NBD
sudo qemu-nbd -d /dev/nbd0
@bryzgalovkv
Copy link
Copy Markdown

Thanks!

@veaviticus
Copy link
Copy Markdown

If, during the pvscan step, you get a message like /dev/nbd0p<N> excluded: device is not in devices file., you may need to add your nbd device to LVM with lvmdevices --adddev /dev/nbd0p<N> before you can pvscan it.

@huypn12
Copy link
Copy Markdown

huypn12 commented Dec 7, 2025

Thanks, this helped me

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