I want to list all the physical volume associated with logical volume.

I know lvdisplay, pvscan, pvdisplay -m could do the job. but I don't want to use these commands. Is there any other way to do it without using lvm2 package commands?

Any thoughts on comparing the major and minor numbers of devices?

  • 1
    The kernel numbers for a LV are not related to the base device(s). They can even change from one boot to the next. Jul 4 '13 at 12:03

There are two possibilities:

If you accept dmsetup as a non-lvm package command (at openSUSE the is a separate package device-mapper) then you can do this:

dmsetup table "${vg_name}-${lv_name}"

Or you do this:

start cmd: # ls -l /dev/mapper/linux-rootfs 
lrwxrwxrwx 1 root root 7 27. Jun 21:34 /dev/mapper/linux-rootfs -> ../dm-0

start cmd: # ls /sys/block/dm-0/slaves/
  • @captain My /dev/mapper/linux-rootfs has been created with LVM. dmsetup uses just the part after /dev/mapper/. The LV rootfs in the VG linux gets the DM name linux-rootfs. Jul 4 '13 at 12:54
  • @ Hauke Laging Let me correct it I created volume named 'test' using dmsetup and tried command ls /sys/block/dm-0/slaves/.I am not seeing any output. Jul 4 '13 at 13:03
  • @captain And your test is dm-0? Jul 4 '13 at 13:06
  • @captain Strange. I am not familiar enough with the sysfs details in order to explain that. You could make that a separate question. Jul 4 '13 at 13:12
  • 1
    My mistake.ls /sys/block/dm-0/slaves/ worked for me. Jul 12 '13 at 6:18

Folks , If you certainly needs to dive inside it then you can give thoughts on comparing Major and minor number

ubuntu@ubuntu-OptiPlex-3010:~$ sudo dmsetup ls
vgpool-lvstuff  (253, 0)

I created this logical volume using disk sda1

ubuntu@ubuntu-OptiPlex-3010:~$ sudo dmsetup deps vgpool-lvstuff
1 dependencies  : (8, 1)

(8, 1) gives me the (major,minor) number of disk on which lvm is dependent which I will compare using following command.

ubuntu@ubuntu-OptiPlex-3010:~$ sudo cat /proc/partitions
major minor  #blocks  name
8        0  488386584 sda
8        1     305368 sda1
8        2    3150112 sda2

List all mappers and get all information for each identifier in one line using native commands:

for file in $(ls -la /dev/mapper/* | grep "\->" | grep -oP "\-> .+" | grep -oP " .+"); do echo "MAPPER:"$(F=$(echo $file | grep -oP "[a-z0-9-]+");echo $F":"$(ls "/sys/block/${F}/slaves/");)":"$(df -h "/dev/mapper/${file}" | sed 1d); done;

Result like as:

MAPPER:dm-0:sdd1:/dev/mapper/luks-00000000-0000-0000-0000-000000000000 916G 487G 384G 56% /media/whk/Secure1
MAPPER:dm-1:sde1:/dev/mapper/luks-00000000-0000-0000-0000-000000000000 916G 487G 384G 56% /media/whk/Secure2

The las out is a df -h command.

Thanks to @hauke-laging for the comprension of the structure.


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.