20

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.

5 Answers 5

15

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.

0
11

sudo lshw -c storage -c disk gives you a lot of info regarding your hard-drives. Eg:

 *-scsi:1
      physical id: 2
      logical name: scsi2
      capabilities: emulated
    *-disk
         description: ATA Disk
         product: ST31000524AS
         vendor: Seagate
         physical id: 0.0.0
         bus info: scsi@2:0.0.0
         logical name: /dev/sdb
         version: JC4B
         serial: 5VPDESM5
         size: 931GiB (1TB)
         capabilities: gpt-1.00 partitioned partitioned:gpt
         configuration: ansiversion=5 guid=d6e747d2-3e9c-47c2-865b-44f8d7cc5808 sectorsize=512
       *-volume
            description: EXT4 volume
            vendor: Linux
            physical id: 1
            bus info: scsi@2:0.0.0,1
            logical name: /dev/sdb1
            logical name: /mnt/hdd0
            version: 1.0
            serial: 2de34713-f0ee-4a12-9214-21a5431a7b7b
            size: 931GiB
            capabilities: journaled extended_attributes large_files huge_files dir_nlink recover extents ext4 ext2 initialized
            configuration: created=2013-07-20 14:14:09 filesystem=ext4 lastmountpoint=/mnt/hdd0 modified=2013-08-29 21:29:24 mount.fstype=ext4 mount.options=rw,relatime,errors=remount-ro,data=ordered mounted=2013-08-29 21:29:24 state=mounted

I suspect physical id gives you the physical port the HDD is connected to (2 in this case).

5
  • 2
    I have SATA ports numbered: 0,1,2,3. lshw reports physical id's: 5,6,7,8. This answer does not seem to be correct.
    – user14654
    Sep 7, 2014 at 18:18
  • 1
    I think "*-scsi:1" of the lshw report is referring to SATA port 1.
    – user14654
    Sep 7, 2014 at 18:35
  • didn't work for me. The SATA port was 7, lshw physical id was 9. Use with caution!
    – Preexo
    Aug 26, 2015 at 4:08
  • 2
    @Preexo Try lsscsi --verbose
    – Elder Geek
    Dec 31, 2015 at 23:55
  • The field you are looking for is bus info. Since extensive anwer editing is discouraged, I've split that off into a separate answer with a more in-depth example.
    – n.st
    Dec 13, 2018 at 15:06
5

sudo apt-get install lsscsi

tech@tech:~$ lsscsi
[2:0:0:0]    disk    ATA      SAMSUNG HD040GJ/ ZG10  /dev/sda
[3:0:1:0]    disk    ATA      WDC WD3200AAJS-0 03.0  /dev/sdb
[4:0:0:0]    disk    Generic- Compact Flash    1.00  /dev/sdc
[4:0:0:1]    disk    Generic- SM/xD-Picture    1.00  /dev/sdd
[4:0:0:2]    disk    Generic- SD/MMC           1.00  /dev/sde
[4:0:0:3]    disk    Generic- MS/MS-Pro/HG     1.00  /dev/sdf

this utility will give you ATA port 0 to 3.

4
  • Can I know if I have a Gigabyte motherboard? If I use that command, will it damage my hardware? Because the way you wrote your answer sounds as if I would damage my hardware if I try it right now ;)
    – Dan
    Oct 4, 2013 at 14:39
  • It works pefectly fine on intel motherboards. Dec 11, 2014 at 14:42
  • works on Supermicro boards, too. Jan 9, 2017 at 15:24
  • 2
    @Rahim where is 0-3 in your sample output? I see 2,3,4
    – simpleuser
    Jan 23, 2017 at 0:55
1

sudo lshw -c storage -c disk gives you a lot of info regarding your hard-drives.

The bus info fields give you the physical port each HDD/SSD is connected to (ports 0 and 2 in this case).
Note that the number may differ if your system has multiple SATA controllers (on-board or via extension cards).

For example:

  *-scsi:0
       physical id: 1
       logical name: scsi0
       capabilities: emulated
     *-disk
          description: ATA Disk
          product: Samsung SSD 840
          physical id: 0.0.0
          bus info: scsi@0:0.0.0
          logical name: /dev/sda
          version: BB6Q
          serial: S1DBNSAF791657P
          size: 232GiB (250GB)
          capabilities: partitioned partitioned:dos
          configuration: ansiversion=5 sectorsize=512 signature=d6cfe005
  *-scsi:1
       physical id: 2
       logical name: scsi2
       capabilities: emulated
     *-disk
          description: ATA Disk
          product: CT500MX500SSD1
          physical id: 0.0.0
          bus info: scsi@2:0.0.0
          logical name: /dev/sdb
          version: 010
          serial: 1810E132AC1E
          size: 465GiB (500GB)
          capabilities: partitioned partitioned:dos
          configuration: ansiversion=5 sectorsize=4096 signature=0007569c
1
  • (Extending @Cubiq's answer beyond the scope of editing, therefore as a separate answer.)
    – n.st
    Dec 13, 2018 at 15:08
0

Probably too late for this question, but 10 years later I had the same need:

I always have an issue to find out quickly which disk is which port on my desktop. So, given I have labeled cables on disk side (they are very difficult to follow from motherboard), I wrote a quick and dirty script, which uses /dev/disk/by-path information :

#!/usr/bin/env bash
#
# output sata/disk relationship.

find /dev/disk/by-path/ -regex '^.*ata-[0-9]+$' -print |
    while read -r file; do
        sata=$(echo "$file" | sed -n 's|.*\(ata\)-\([0-9]*\).*|s\1\2|p')
        drive=$(readlink -f "$file")
        printf "%s %s \n" "$sata" "${drive##*/}"
    done | sort
exit 0

Output example:

$ sata2disk.sh 
sata1 sda 
sata2 sdb 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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