Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm getting kernel messages about 'ata3'. How do I figure out what device (/dev/sd_) that corresponds to?

share|improve this question
up vote 3 down vote accepted

From http://www.phuket-data-wizards.com/blog/2011/07/16/matching-linux-ata-numbers-to-the-device-names/:
The command grep '[0-9]' /sys/class/scsi_host/host{0..9}/unique_id will provide output like
/sys/class/scsi_host/host0/unique_id:1
/sys/class/scsi_host/host1/unique_id:2
/sys/class/scsi_host/host2/unique_id:0
/sys/class/scsi_host/host3/unique_id:0
/sys/class/scsi_host/host4/unique_id:3
/sys/class/scsi_host/host5/unique_id:4
/sys/class/scsi_host/host6/unique_id:5
/sys/class/scsi_host/host7/unique_id:6

so we can match the unique id used in kernel error messages to the host number. Then the command ls -l /sys/block/sd* will show us which device name belongs to which host number:
/sys/block/sda -> ../devices/pci0000:00/0000:00:13.2/usb1/1-6/1-6:1.0/host2/target2:0:0/2:0:0:0/block/sda
/sys/block/sdb -> ../devices/pci0000:00/0000:00:13.2/usb1/1-8/1-8:1.0/host3/target3:0:0/3:0:0:0/block/sdb
/sys/block/sdc -> ../devices/pci0000:00/0000:00:12.0/host6/target6:0:0/6:0:0:0/block/sdc /sys/block/sdd -> ../devices/pci0000:00/0000:00:13.2/usb1/1-8/1-8:1.0/host3/target3:0:0/3:0:0:1/block/sdd
/sys/block/sde -> ../devices/pci0000:00/0000:00:13.2/usb1/1-8/1-8:1.0/host3/target3:0:0/3:0:0:2/block/sde /sys/block/sdf -> ../devices/pci0000:00/0000:00:13.2/usb1/1-8/1-8:1.0/host3/target3:0:0/3:0:0:3/block/sdf
/sys/block/sdg -> ../devices/pci0000:00/0000:00:12.0/host7/target7:0:0/7:0:0:0/block/sdg

From these two outputs we can see that the unique id 6 maps to host7, and host7 maps to /dev/sdg. And finally, with the command hdparm -i /dev/sdg:
/dev/sdg: Model=ST3500418AS, FwRev=CC34, SerialNo=6VM2KSFD
we can find the serial number of the drive.

share|improve this answer
1  
I wrapped your answer in a one-liner so it can be more easier to use: ata=3; ls -l /sys/block/sd* | grep $(grep $ata /sys/class/scsi_host/host*/unique_id | awk -F'/' '{print $5}') – insider Jan 15 '14 at 10:20

Can't comment on previous answer, but for that one liner, you want to change the grep to be a little more restrictive as 1 and 10 are both valid ata#'s:

$ grep 1 /sys/class/scsi_host/host*/unique_id
/sys/class/scsi_host/host0/unique_id:1
/sys/class/scsi_host/host9/unique_id:10
$ grep ^1$ /sys/class/scsi_host/host*/unique_id
/sys/class/scsi_host/host0/unique_id:1

So...

ata=3; ls -l /sys/block/sd* | grep $(grep ^$ata$ /sys/class/scsi_host/host*/unique_id | awk -F'/' '{print $5}')

For my needs, I wanted to map a drive letter to an ata, so I wrote this, and on my system the ata string wasn't always the 5th component of the path:

#!/bin/sh                                                                       
dev=$1                                                                         
name=`basename $dev`                                                            
readlink /sys/block/$name | perl -ne'm{/(ata\d+)/} && print "$1\n"'             

Use it like this:

$ ./map2ata /dev/sda
ata2
share|improve this answer
    
I run this on CentOS 6 and it always returns blank output. Where is this getting $dev value from? – Edward_178118 Jun 25 '15 at 4:59
    
See the "Use it like this" section. You pass your device path to the script. – rrauenza Jun 25 '15 at 19:07
    
I did do that, and it always returns blank output. – Edward_178118 Jun 26 '15 at 10:19
    
Run each command in the script one by one. basename $dev just takes /path/whatever/xyz and returns xyz. It assigns xyz to name. readlink returns what /sys/block/$name actually points to, which is piped into perl to grab the ata[0-9]+ identifier and print it. – rrauenza Jun 26 '15 at 14:24

Just so we are clear the ATA number maps to the UNIQUE_ID, directly (they are the same number). So ATA #3 is UNIQUE_ID #3. Then you look up what HOST # is associated to the UNIQUE_ID

/sys/class/scsi_host/host4/unique_id:3

So here ATA #3 is UNIQUE_ID #3 is HOST #4

Then to get the drive letter just run “ls -lisah /sys/block” and find the HOST #4.

Here is a good stackexchange/superuser talking about this: Mapping ata device number to logical device name

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .