添加 /dev/disk 的路径

添加 /dev/disk 的路径

我有一个依赖于 的脚本/dev/disk/by-path,但该子目录不存在。当我 时ls /dev/disk,我得到:

by-id         by-label        by-uuid

如何得到by-path

(grep -ri 'by-path' /lib/udev/rules.d/60-persistent-storage.rules 的输出为:

# persistent storage links: /dev/disk/{by-id,by-uuid,by-label,by-path}
# by-path (parent device path)
ENV{DEVTYPE}=="disk", ENV{ID_PATH}=="?*", SYMLINK+="disk/by-path/$env{ID_PATH}"
ENV{DEVTYPE}=="partition", ENV{ID_PATH}=="?*", SYMLINK+="disk/by-path/$env{ID_PATH}-part%n"

(sudo udevadm info --root --name=/dev/sdc | grep DEVTYPE 的输出为:

E: DEVTYPE=disk

答案1

/dev/disk/by-path当您将 SD 卡添加到系统时(不是通过) ,该路径会自动创建mount。负责此操作的是udev,并且规则

/lib/udev/rules.d/60-persistent-storage.rules

通过一个简单的命令你就可以看到规则:

% grep -ri 'by-path' /lib/udev/rules.d/60-persistent-storage.rules
# persistent storage links: /dev/disk/{by-id,by-uuid,by-label,by-path}
# by-path (parent device path)
ENV{DEVTYPE}=="disk", ENV{ID_PATH}=="?*", SYMLINK+="disk/by-path/$env{ID_PATH}"
ENV{DEVTYPE}=="partition", ENV{ID_PATH}=="?*", SYMLINK+="disk/by-path/$env{ID_PATH}-part%n"

你不应该使用它ls /dev/disk/by-path来获取变量的值。使用

for f in /dev/disk/by-path/*; do echo "$f"; done

反而。

相关内容