Skip to content

Instantly share code, notes, and snippets.

@pshchelo
Last active March 6, 2024 19:05
Show Gist options
  • Star 37 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save pshchelo/6ffabbffaedc46456b39c037d16e1d8c to your computer and use it in GitHub Desktop.
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

Thanks!

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