Last active
March 22, 2025 12:59
-
-
Save pshchelo/6ffabbffaedc46456b39c037d16e1d8c to your computer and use it in GitHub Desktop.
List of commands to mount/unmount a qcow2 image conatining LVM partitions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!