Page 1 of 1

Linux: Mapping kernel ataXX to device /dev/sdX

Posted: Mon Feb 08, 2016 4:19 pm
by peter_b
Here is a short commandline script for finding the mapping between kernel adressing of disk devices (eg harddisks) to something like sda, sdb, etc:

Code: Select all

for d in /sys/block/sd*
do
  s=`basename $d`
  h=`ls -l $d | egrep -o "host[0-9]+"`
  t=`ls -l $d | egrep -o "target[0-9:]*"`
  a2=`echo $t | egrep -o "[0-9]:[0-9]$" | sed 's/://'`
  a=`cat /sys/class/scsi_host/$h/unique_id`
  echo "$s -> ata$a.$a2"
done
This returns a mapping like this:
sda -> ata4.00
sdb -> ata7.00
sdc -> ata8.00
sdd -> ata9.00
sde -> ata10.00
sdf -> ata11.00
sdg -> ata12.00
sdh -> ata14.00
sdi -> ata14.01
Tested on CentOS 6.5.

Source: http://askubuntu.com/questions/64351/ho ... sical-disk