0

Is there a way to name devices such that any drive plugged into slot 1 is always named /dev/sda? Rather than just first drive inserted sda even though it's plugged into the last slot, second sdb wherever it goes, etc...

Edit (after more research): How does /dev/disk/by-path work? Does part of the name map to a physical port?

Edit again: by-path does not seem to work at all with the hotswap drives. They do not show up.

  • I need a way to distinguish ports. So that my program can alert that the drive in port __ is ready to be removed. – Duke Silver Aug 07 '12 at 19:46

1 Answers1

5

Rather than rely on device names being always the same, why not use filesystem labels? Those are a lot easier to deal with.

To set a label on a partiton (ext2/3/4 in this case):

$ e2label /dev/sda1 FOOBAR

Then in /etc/fstab:

LABEL=FOOBAR     /mnt/foobar    ext3   defaults 0 0
EEAA
  • 108,414
  • 18
  • 172
  • 242
  • 2
    UUIDs are good too, though more painful to read. – Zoredache Aug 07 '12 at 19:25
  • These drives will only be plugged in once for a few hours before a completely new drive comes in. Will this map the physical location of the drive or the drive itself? – Duke Silver Aug 07 '12 at 19:37
  • This will give the kernel a clue as to where to mount the drive when it's presented, regardless of physical slot. – rnxrx Aug 07 '12 at 19:40
  • 1
    It will label a device, not a port. – Hennes Aug 07 '12 at 19:40
  • I need a way to distinguish ports. So that it can alert that the drive in port __ is ready to be removed. Without writing specific information about each drive before plugging it in. – Duke Silver Aug 07 '12 at 19:42