0

I have a file hdd.img being raw image of a hard disk. The harddisk has a BIOS/DOS partition table and its second partition is setup to serve as a the one single physical volume from which LVM creates logical volumes.

My goal is to access the partitions/filesystems that are represented by those logical volumes.

I setup loopback block device mapping for the hdd.img via the command:

$ sudo losetup --partscan -f hdd.img

which results me seeing the two partitions contained in that image on the loopback device (it was loop17)

$ lsblk | grep 'loop17'
loop17                7:17   0  30G  0 loop
├─loop17p1          259:4    0   1G  0 loop
└─loop17p2          259:5    0  29G  0 loop

The question now is. How can I inform the system to scan /dev/loop17p2 for the logical volumes I actually want to access

Update

Installing the package kpartx and doing this:

$ sudo losetup -f hdd.img
$ sudo kpartx -a /dev/loop17

did generate the lvm mappings to the volumes contained on /dev/loop17p2. While this solves my immediate needs it would yet still be great to know why vgscan does not work once the losetup --partscan -f hdd.img had already created the /dev/loop17p2 block device that contains the logical volumes?

0

Use lvscan. vgscan is to scan Volume Group ...

  • I tested using lvscan, but this has not resulted in any mappings being created. Can you show a how it would be done with the lvscan – humanityANDpeace Nov 19 '19 at 9:51
0

The command vgscan has an command line option --cache that must be used to put the the results of the scan into the cache, allowing a subsequent vgchange -ay <vg> call to genrete the mapping

In short this work:

$ sudo losetup --partscan -f hdd.img
$ sudo vgscan --scan
$ sudo vgchange -ay <vg>

whith vg being the one of the volume group (which the vgscan) has reported.

This would however not work:

$ sudo losetup --partscan -f hdd.img
$ sudo vgscan
$ sudo vgchange -ay <vg>

because the second command would have not put its scanning results into the --cache. Oddly enough my take on the --cache flag was to think it meant to use cached values instead of performing an actual scan.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.