0

Looking for a reliable (and hopefully simple) way to trace a directory in an lvm or other dm mounted fs back to the physical disk it resides on. Goal is to get the model and serial number of the drive no matter where the script wakes up.

Not a problem when the fs mount is on a physical partition, but gets messy when layers of lvm and/or loopbacks are in between. The lsblk tree shows the dm relationships back to /dev/sda in the following example, but wouldn't be very easy or desirable to parse:

# lsblk -po NAME,MODEL,SERIAL,MOUNTPOINT,MAJ:MIN
NAME                               MODEL                   SERIAL       MOUNTPOINT MAJ:MIN
/dev/loop0                                                              /mnt/test    7:0  
/dev/sda                           AT1000MX500SSD1         21035FEA05B8              8:0  
├─/dev/sda1                                                             /boot        8:1  
├─/dev/sda2                                                                          8:2  
└─/dev/sda5                                                                          8:5  
  └─/dev/mapper/sda5_crypt                                                         254:0  
    ├─/dev/mapper/test5--vg-root                                        /          254:1  
    └─/dev/mapper/test5--vg-swap_1                                      [SWAP]     254:2  

Tried udevadm info, stat and a few other variations, but they all dead end at the device mapper without a way (that I can see) of connecting the dots to the backing disk and it's model/serial number.

Adriaan
  • 17,741
  • 7
  • 42
  • 75
netdxr
  • 1
  • 1

1 Answers1

0

Got enough solution by enumerating the base /dev/sd? devices, looping through each one and its partitions with lsblk -ln devpart and looking for the mountpoint in column 7. In the following example, the desired / shows up in the mappings to the /dev/sda5 partition. The serial number (and a lot of other data) for the base device can then be returned with udevadm info /dev/sda:

sda5               8:5    0  931G  0 part  
sda5_crypt       254:0    0  931G  0 crypt 
test5--vg-root   254:1    0  651G  0 lvm   /
test5--vg-swap_1 254:2    0  976M  0 lvm   [SWAP]
netdxr
  • 1
  • 1