I was recently tasked with creating a hard drive management system on Linux. I needed to write a program that monitored when drives came online and offline and created/removed links to the drive mounts.

That was the easy part.....

What I can't figure out is how to match my GUI with the position of the hard drives in the docks. I need the program to represent how the drives look if someone was staring at the physical docks that hold the drives. Currently I'm just identifying drives by the /sd*, which I know is a terrible method since it changes anytime you hot swap or reboot. Does anyone know a command I might be able to use to pull the physical location of the hard drives?

Thanks in advance!


You can look up the /sys node for the device and find out what port and what controller it is on. From there, you will have to have the user manually configure the physical location of the port. Note that this will only work for SATA since SAS and SCSI have multiple devices connected to a given port.

  • Unfortunately these are SCSI. – Max Sep 26 '11 at 16:40
  • @Max, then the best you can do is track the drives by their serial number and prompt the user to specify the physical location when an unknown drive is detected. – psusi Sep 26 '11 at 17:16

Figure out the mappings the hard way once, and then label the filesystem on each drive so that you know. Adjust your management tool to re-label when a drive is swapped.

  • That assumes one disk = one filesystem. We're talking raid here, so that's a no go. – psusi Sep 27 '11 at 17:47

try to parse the output of:

sudo lshw

or for a more specific result:


for the last you probably need to install the package with the same name of the command

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.