Listing unused SATA ports on Linux

I have a physical machine running Linux (CentOS 6.3, specifically), and I want to know how many SATA ports are currently unused (i.e. nothing is plugged in). Of course, I could just pull the machine open, but let's say I don't have physical access. Is there a command I can use to show which SATA ports are unused?

I already know about the lshw command, but as far as I can tell, it only lists used SATA ports and not free ones.


Solution 1:

Is there a command I can use to show which SATA ports are unused?

No, but you can do the reverse. You can list which ports are being used. Then look up (in the manual) how many ports there are on the motherboard, subtract how many are already in use and get the number of remaining ports.

This assumes that you have one SATA drive connected per SATA connector (e.g. no port multipliers).


There are several ways to to this.

If all SATA controllers have drivers loaded (fairly normal), then I find fdisk -l to list all disks the easiest way.

If you no longer have fdisk (it is being replaced my more modern variants such as gpart), then you can read the boot log. Some googling show that CentOS has this available via dmesg, but you can also read the log files directly. There are probably in /var/log/dmesg.log, /var/run/dmesg.boot or in /var/log/boot. (Keeping this a tad generic for people not using CentOS).

Then there is lspci. This lists all PCI and PCI-e devices, inclusding SATA controllers. Add -v to get easier readable output.

Or use dmidecode. This asks the BIOS for information. If the output from this command seems overwhelming, limit it with the -t NR option.

Solution 2:

It's been three years, but if somebody comes through Google, here goes: If you have EPEL enabled, then install lsscsi, it mostly gives info about connected devices, but its -H parameter is what you need:

--hosts|-H lists scsi hosts rather than scsi devices

Compare with other output mode and you have the difference:

root@server1:~# lsscsi -H
[0]    ata_piix  
[1]    ata_piix  
[2]    ata_piix  
[3]    ata_piix  
[4]    usb-storage
root@server1:~# lsscsi -g
[0:0:0:0]    disk    ATA      WDC WD2004FBYZ-0 RR03  /dev/sda   /dev/sg0
[0:0:1:0]    disk    ATA      WDC WD2004FBYZ-0 RR04  /dev/sdb   /dev/sg1
[1:0:0:0]    disk    ATA      WDC WD2004FBYZ-0 RR03  /dev/sdc   /dev/sg2
[4:0:0:0]    disk    Seagate  Backup+  Desk    0342  /dev/sdd   /dev/sg3

UPDATE: Disregard that, without installing anything:

dmesg | grep 'SATA link down'

will show you unused ports.