Which SATA port is my disk connected to?

2

We have a computer with multiple boot drives, all of which contain the same software. The selection of the boot disk is via multi-position switch on the front panel. If disk 1 is selected, the disk on SATA Port 0 is booted. If disk 2 is selected, the disk on SATA Port 1 is booted. Etc.

The disk manager on RH can show which SATA port the hard disks are plugged in. It's a graphical UI on top of something, and that something is what I want.

How can I get this information on the command line? I connect via an ssh connection and I'd like to find out what the boot disk is connected to. Where is this information kept?

Thanks!

Paxton Sanders

Posted 2015-07-13T17:47:50.863

Reputation: 123

You do realize the RH disk manager is open source, right? – Ramhound – 2015-07-13T18:24:10.823

AFAIK, disk-manager only shows the device paths of every installed drive, like /dev/(sda|sdb), which don't necessarily correspond to the physical ports the drives are attached to. – Larssend – 2015-07-13T18:39:45.170

@geewee http://www.orbdesigns.com/wp/wp-content/uploads/2012/11/GnomeDiskUtility.png It's the third option down in the left column of the right pane.

– Paxton Sanders – 2015-07-13T20:49:39.770

lshw should give you the information you need. – ssnobody – 2015-07-13T22:30:49.880

you can get some hints from ls -l /dev/disk/by-path/ – user371366 – 2017-05-18T01:42:12.260

Answers

2

Matching up port numbers to devices

I found this question because I was trying to figure out the same thing. Here's what I figured out; it should work in bash or zsh:

for i in /dev/disk/by-path/*;do [[ ! "$i" =~ '-part[0-9]+$' ]] && echo "Port $(basename "$i"|grep -Po '(?<=ata-)[0-9]+'): $(readlink -f "$i")";done

The output should look something like this:

Port 1: /dev/sda
Port 2: /dev/sdb
Port 3: /dev/sdc

These port numbers SHOULD correspond with the numbers printed on your motherboard, although this assumes your motherboard vendor was considerate enough to match the numbers printed on the board to the port numbers in the SATA controller chip. At very least, device paths remain stable, so once you establish a mapping between the listed port numbers and the numbers on the panel, it won't ever change.

This snippet iterates over the /dev/disk/by-path directory. It skips over files that end in -part<number> as these are just partitions, and extracts the port number from the -ata<number> at the end of the remaining filenames. These files are symlinks to the traditional /dev/sdX nodes, which it gets using readlink -f.

If you have multiple SATA controllers, you'll get multiple devices listed for the same port numbers, because each controller has its own port 1, port 2, etc. So, just run ls -l /dev/disk/by-path and parse it out manually.

Figuring out which device is your boot device

To figure out which one is your boot device, run mount | grep ' on / ' | cut -f 1 -d ' '. This shows the device mounted at /.

user371366

Posted 2015-07-13T17:47:50.863

Reputation: 136