4

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!

5
  • You do realize the RH disk manager is open source, right?
    – Ramhound
    Commented Jul 13, 2015 at 18:24
  • 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
    Commented Jul 13, 2015 at 18:39
  • @geewee orbdesigns.com/wp/wp-content/uploads/2012/11/… It's the third option down in the left column of the right pane. Commented Jul 13, 2015 at 20:49
  • lshw should give you the information you need. Commented Jul 13, 2015 at 22:30
  • you can get some hints from ls -l /dev/disk/by-path/
    – user371366
    Commented May 18, 2017 at 1:42

3 Answers 3

6

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

0

The proper SATA port mapping is what "user371366" have mentioned.

Although I highly advice to not rely on what SATA port number is printed on the motherboard PCB.

Because there are hardware/software issues or bugs which makes them unreliable.

There will be times when SATA port#1 labeled on motherboard PCB, will be shown as SDB or SDx (where x is any letter shown on your PC terminal or whatnot) and not SDA.

This happened to me few times such as using the "clonezilla" backup software, where it shows SATA port#1 as SDB when it should be SDA.

The best approach is to write down the hard drive serial number and use that as reference of which hard drive is being targeted.

0

using /sys is more straight-forward and simple

# ls -l /sys/block
lrwxrwxrwx 1 root root 0 Jun 19 04:00 sda -> ../devices/pci0000:00/0000:00:13.0/ata2/host1/target1:0:0/1:0:0:0/block/sda
lrwxrwxrwx 1 root root 0 Jun 19 04:00 sdb -> ../devices/pci0000:00/0000:00:1c.2/0000:03:00.0/ata3/host2/target2:0:0/2:0:0:0/block/sdb
lrwxrwxrwx 1 root root 0 Jun 19 04:00 sdc -> ../devices/pci0000:00/0000:00:1c.2/0000:03:00.0/ata4/host3/target3:0:0/3:0:0:0/block/sdc
lrwxrwxrwx 1 root root 0 Jun 19 04:00 sdd -> ../devices/pci0000:00/0000:00:1c.2/0000:03:00.0/ata5/host4/target4:0:0/4:0:0:0/block/sdd
lrwxrwxrwx 1 root root 0 Jun 19 04:00 sde -> ../devices/pci0000:00/0000:00:1c.2/0000:03:00.0/ata6/host5/target5:0:0/5:0:0:0/block/sde

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .