Linux: Mapping kernel ataXX to device /dev/sdX

Linux howto's, compile information, information on whatever we learned on working with linux, MACOs and - of course - Products of the big evil....
Post Reply
User avatar
Posts: 338
Joined: Tue Nov 12, 2013 2:05 am

Linux: Mapping kernel ataXX to device /dev/sdX

Post 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*
  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"
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: ... sical-disk
Post Reply