Ubuntu – Identification of HDD by SATA port number

hard drivesata

How do I find out which motherboard SATA port number is an HDD connected to?

We want to build a hdd copy software based on physical identification of SATA.

Best Answer

lsscsi --verbose will provide output similar to this:

[0:0:0:0]    disk    ATA      TOSHIBA THNSNH12 HTRA  /dev/sda 
  dir: /sys/bus/scsi/devices/0:0:0:0  [/sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0]
[1:0:0:0]    disk    ATA      WDC WD2003FZEX-0 01.0  /dev/sdb 
  dir: /sys/bus/scsi/devices/1:0:0:0  [/sys/devices/pci0000:00/0000:00:1f.2/ata2/host1/target1:0:0/1:0:0:0]
[2:0:0:0]    disk    ATA      WDC WD3001FAEX-0 01.0  /dev/sdc 
  dir: /sys/bus/scsi/devices/2:0:0:0  [/sys/devices/pci0000:00/0000:00:1f.2/ata3/host2/target2:0:0/2:0:0:0]
[3:0:0:0]    cd/dvd  Optiarc  DVD RW AD-7280S  1.01  /dev/sr0 
  dir: /sys/bus/scsi/devices/3:0:0:0  [/sys/devices/pci0000:00/0000:00:1f.2/ata4/host3/target3:0:0/3:0:0:0]

which provides the ataN port which can matchup with information found in the syslog. Useful if you are trying to determine where an error is coming from .

Edit: If which lsscsi provides no output you need to install it:

sudo apt-get install lsscsi

Further Edit:

This probably goes without saying, but of course you can filter the output with grep to locate what you are interested in for instance if you find an error like ata4: status: { DRDY ERR } you could simple issue the command

lsscsi --verbose | grep -P1 -A1 ata4 Which would produce output like this:

[3:0:0:0]    cd/dvd  Optiarc  DVD RW AD-7280S  1.01  /dev/sr0 
  dir: /sys/bus/scsi/devices/3:0:0:0  [/sys/devices/pci0000:00/0000:00:1f.2/ata4/host3/target3:0:0/3:0:0:0]

Which would indicate that the device (Optiarc DVD RW AD-7280S on ata4) wasn't ready when called upon.

This should be enough information to allow you to locate the troubled device.

Related Question