Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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!

share|improve this question

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.

share|improve this answer
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.

share|improve this answer
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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.