大网数据广告活动
服务器运维问答

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

· 52CE 我爱测

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 exter…

问题原文

原帖链接 · dimus · CC BY-SA 4.0

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.

社区高分解答

原帖链接 · doneal24 · CC BY-SA 4.0

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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2023-01-07)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。