Matching Linux ata numbers to the device names
Many thanks to Dirk Tilger for the information on his blog. I am just providing the more manageable commands to type
Recently we had to recover data from a 8-drive soft-RAID5 on Linux. It had 3 devices failed out of 8. 2 of the drives just had some bad sectors on them. The problem is, the Linux kernel reports errors on the device as ata channel numbers, for example as “ata1.00″. All 8 drives were the same model, the serial number is not reported via dmesg, so how to know the device name (like /dev/sda) that is causing these error messages?
The command
grep '[0-9]' /sys/class/scsi_host/host{0..9}/unique_id
will provide output like this:
/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.