Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Consider following kern.log snippet:

 ata4.00: failed command: WRITE FPDMA QUEUED
 ata4.00: cmd 61/00:78:40:1e:6c/04:00:f0:00:00/40 tag 15 ncq 524288 out
        res 41/04:00:00:00:00/04:00:00:00:00/00 Emask 0x1 (device error)
 ata4.00: status: { DRDY ERR }
 ata4.00: error: { ABRT }
 ata4: hard resetting link
 ata4: nv: skipping hardreset on occupied port
 ata4: SATA link up 3.0 Gbps (SStatus 123 SControl 300)
 ata4.00: configured for UDMA/133
 ata4: EH complete

How can I identify which hard drive the kernel actually means when it talks about ata4.00?

How can I find the corresponding /dev/sdY device name?

share|improve this question

3 Answers 3

Just had this same problem and found a another solution which one might like.

The lsscsi tool lists SCSI devices (or hosts) and their attribute.

With lsscsi one gets the ata name and the device name.

Looks like this:

$ lsscsi --long
[0:0:1:0]    cd/dvd  MATSHITA DVD-ROM UJDA780  1.50  /dev/sr0
  state=running queue_depth=1 scsi_level=6 type=5 device_blocked=0 timeout=30
[2:0:0:0]    disk    ATA      WDC WD3000FYYZ-0 01.0  /dev/sda
  state=running queue_depth=1 scsi_level=6 type=0 device_blocked=0 timeout=30
[3:0:0:0]    disk    ATA      WDC WD1002FBYS-0 03.0  /dev/sdb
  state=running queue_depth=1 scsi_level=6 type=0 device_blocked=0 timeout=30
[4:0:0:0]    disk    ATA      WDC WD1002FBYS-0 03.0  /dev/sdc
  state=running queue_depth=1 scsi_level=6 type=0 device_blocked=0 timeout=30
[5:0:0:0]    disk    ATA      WDC WD1002FBYS-0 03.0  /dev/sdd
  state=running queue_depth=1 scsi_level=6 type=0 device_blocked=0 timeout=30
[6:0:0:0]    disk    ATA      WDC WD3000FYYZ-0 01.0  /dev/sde
  state=running queue_depth=1 scsi_level=6 type=0 device_blocked=0 timeout=30
[7:0:0:0]    disk    ATA      WDC WD1002FBYS-0 03.0  /dev/sdf
  state=running queue_depth=1 scsi_level=6 type=0 device_blocked=0 timeout=30

On Ubuntu one can install lsscsi simply with

$ sudo apt-get install lsscsi
share|improve this answer
    
hm, and how do the ataX map to what part in the lsscsi output? –  maxschlepzig Oct 15 '13 at 18:35

Here's my version, modified from above. Since I don't know the exact date the system was booted (for testing this it was 27 days ago), and I don't know which kern.log contains the data I need (some may be gzipped on my system), I use uptime and date to calculate an approximate system boot date (to the day, anyway), then use zgrep to search through all available kern.log files.

I also slightly modified the second grep statement, since it will now also show an ATAPI CD/DVD drive as well as ATA-* drives.

It could still use refinement (i.e. if system uptime is greater than a year), but should work OK for now.

#!/bin/bash

uptime=$(uptime | awk -F' '  '{ print $3" "$4 }' | sed s/,//)
date=$(date -d "$uptime ago" | awk '{print $2" "$3 }')
zgrep "$date"  /var/log/kern.log*  | \
grep 'ata[0-9]\+.[0-9][0-9]: ATA'  | \
sed 's/^.*\] ata//' | \
sort -n | sed 's/:.*//' | \
awk ' { a="ata" $1; printf("%10s is /dev/sd%c\n", a, 96+NR); }'
share|improve this answer
up vote 5 down vote accepted

I puzzled a bit around what would be the enumeration scheme on my systems and I've came up with following algorithm:

The /dev/sdY devices are created in the same order as the ataX identifiers are enumerated in the kern.log while ignoring non-disk devices (ATAPI) and not-connected links.

Thus, following command displays the mapping:

$ grep '^May 28 2'  /var/log/kern.log.0  | \
   grep 'ata[0-9]\+.[0-9][0-9]: ATA-' | \
   sed 's/^.*\] ata//' | \
   sort -n | sed 's/:.*//' | \
   awk ' { a="ata" $1; printf("%10s is /dev/sd%c\n", a, 96+NR); }'
ata1.00 is /dev/sda
ata3.00 is /dev/sdb
ata5.00 is /dev/sdc
ata7.00 is /dev/sdd
ata8.00 is /dev/sde
ata10.00 is /dev/sdf

(Note that ata4 is not displayed because the above log messages are from another system.)

I am using /var/log/kern.log.0 and not /var/log/kern.log because the boot messages are already rotated. I grep for May 28 2 because this was the last boot time and I want to ignore previous messages.

To verify the mapping you can do some checks via looking at the output of:

$ grep '^May 28 2'  /var/log/kern.log.0  | \
grep 'ata[0-9]\+.[0-9][0-9]: ATA-'
May 28 20:43:26 hn kernel: [    1.260488] ata1.00: ATA-7: SAMSUNG SV0802N, max UDMA/100
May 28 20:43:26 hn kernel: [    1.676400] ata5.00: ATA-5: ST380021A, 3.19, max UDMA/10
[..]

And you can compare this output with hdparm output, e.g.:

$ hdparm -i /dev/sda

/dev/sda:

Model=SAMSUNG SV0802N [..]

(using Kernel 2.6.32-31)

I am still interested in alternative solutions, e.g. in a solution which does not need to access the kernel log (perhaps using some information from the /sys tree or something like that).

share|improve this answer
    
This is just awesome, thank you so much for this excellent reply... –  stuartc Dec 15 '11 at 9:15
    
@stuarte, you are welcome - btw, cks has done a writeup about all the different naming schemes of SATA devices on current Linux systems. Regarding ataX identifiers he writes: 'These names do not appear in sysfs at all as far as I can see' –  maxschlepzig Dec 16 '11 at 21:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.