Score:5

How to name drives according to their position in a multi-bay enclosure?

in flag

It is important to know a position of a bad drive in a multi-bay device, however default naming of drives e.g /dev/sda, /dev/sdb etc. does not provide a clue where a particular drive is residing physically.

I have an 8-bay external JBOD enclosure used for backup. It hosts a ZFS pool and is connected to an Arch Linux box. Is it possible on a Linux system which uses systemd/udev to name drives according to their physical location in the enclosure instead of /dev/sd*?

I would like the names to reflect the physical position of a drive in the enclosure /dev/encl1, /dev/encl2... or similar. I would prefer these labels to appear by default instead of /dev/sd* in lsblk and zpool status.

I do know location of every drive in the enclosure, and keep this information in a file, but it would be way better to see it with lsblk and other commands directly.

I tried to create rules at /etc/udev/rules.d like

SUBSYSTEM=="block" KERNEL=="sd*" ENV{ID_SERIAL_SHORT}=="ZR5CTR4V" SYMLINK+="encl1"

And I do get such symlinks after running udevadm trigger, but they are not equivalent to /dev/sd* and I was not able to use them as a substitution.

pt flag
There are *already* names that are more informative than `/dev/sd*`. Take a look at `/dev/disk/by-id/` and the other directories under `/dev/disk`.
dimus avatar
in flag
@larsks, my specific usecase it to know the position of a drive in the enclosure by its name, so I can find it quickly in case of trouble.
vidarlo avatar
ar flag
How about the `by-path`?
dimus avatar
in flag
@vidarlo, `by-path` still does not allow to tell that this particular drive is for example located 2nd from the top in the enclosure
jm flag
Can you use `lshw -c disk -c storage | grep -E 'bus info|logical name` to give you a hint on the disk bays? I expect that the bus info will be incrementing uniformly following the bay numbers.
dimus avatar
in flag
@doneal24, very cool command, I did not know about it! Actually, in my case, I do know positions of each drive, and I just keep this information in a file, but it is much less convenient than directly seeing this information by running `lsblk` for example. I edited question to clarify this.
Score:3
jm flag

Writing up my comment as an answer.

Use the command

lshw -c disk -c storage | grep -E 'bus info|logical name’

to map device names to pci devices. The device id’s will increment uniformly, with the lowest id for bay 1.

You can also use udevadm to get the device id in devices.

udevadm info --name=/dev/nvme6

You can now give the disk devices names corresponding to the physical slot they are installed in. Edit or create /etc/udev/rules.d/my.rules. You can rename the device with the rules.

KERNEL=="nvme*", SUBSYSTEM=="nvme", ENV{PHYSDEVPATH}=="*pci0000:20/0000:20:01.3/0000:25:00.0*", NAME="bay6"
KERNEL=="nvme*", ENV{DEVTYPE}=="partition", SUBSYSTEM=="nvme", ENV{PHYSDEVPATH}=="*pci0000:20/0000:20:01.3/0000:25:00.0*", NAME="bay6p%n"

If you have sd devices instead or nvme, change the SUBSYSTEM to block.

It's possible to put in an alias instead of renaming the device. Look at SYMLINK+="bay6" in the udev documentation.

dimus avatar
in flag
in my case it is already known where drives are located in the enclosure, the question is how to show this information conveniently in the name of the drives. For example `multipath` does it well by creating an `alias` to `wwid` data, and this alias appears as the default name for a drive
jm flag
@dimus Added device renaming to my answer.
dimus avatar
in flag
Thank you for expansion of your answer @doneal24, as you can see in my question, I did succeed in making aliases, how can I make them show by default though?
jm flag
@dimus I don't use zfs so this is a guess. Look at [this](https://plantroon.com/changing-disk-identifiers-in-zpool/) and the man page for zpool-import. It looks like you can use something like `zpool-import -d /dev/bay1 -d /dev/bay2 -d... poolname`.
dimus avatar
in flag
yes, i did post an answer about doing just that, but it is only a partial answer, I would love to be able to change default names for drives to have a more general solution.
Score:0
in flag

This is only a partial answer to the question which does work to provide a bay position information for ZFS:

  1. I used parted to change labels for ZFS paritions to something like encl1-3DS where the first part is the bay position and the second is the unique part of the drive's serial.
(parted) p
Model: xxx (scsi)
Disk /dev/sdc: 4001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name       Flags
 1      1049kB  4001GB  4001GB               encl4-28P
 9      4001GB  4001GB  8389kB
  1. zpool export <zpool-name>

  2. zpool import -d /dev/disk/by-partlabel <zpool-name>

  3. Now zpool status -v shows

❯ zpool status -v
  pool: ext
 state: ONLINE
  scan: scrub repaired 0B in 05:42:24 with 0 errors on Fri Jan  6 20:15:57 2023
config:

    NAME           STATE     READ WRITE CKSUM
    ext            ONLINE       0     0     0
      raidz1-0     ONLINE       0     0     0
        encl1-PT8  ONLINE       0     0     0
        encl7-C32  ONLINE       0     0     0
        encl4-28P  ONLINE       0     0     0
        encl2-N75  ONLINE       0     0     0
        encl5-ZT1  ONLINE       0     0     0
        encl6-9RP  ONLINE       0     0     0
        encl8-88F  ONLINE       0     0     0

errors: No known data errors

Not sorted, but it is already much better than /dev/sd*

Still, I would love to have a more general solution that would make a custom alias a default.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.