How to get disk name that contains a specific partition

You can observe in /sys the block device for a given partition name. For example, /dev/sda1:

$ ls -l /sys/class/block/sda1
lrwxrwxrwx 1 root root /sys/class/block/sda1 -> \
 ../../devices/pci0000:00/.../ata1/host0/target0:0:0/0:0:0:0/block/sda/sda1

A script to take arg /dev/sda1 and print /dev/sda is:

part=$1
part=${part#/dev/}
disk=$(readlink /sys/class/block/$part)
disk=${disk%/*}
disk=/dev/${disk##*/}
echo $disk

I don't have lvm etc to try out, but there is probably some similar path.


There is also lsblk:

$ lsblk -as /dev/sde1
NAME  MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sde1    8:65   1  7.4G  0 part 
`-sde   8:64   1  7.4G  0 disk 

and as @don_crissti said you can get the parent directly with:

lsblk -no pkname /dev/sda1