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 /
.
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.770lshw 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