Ubuntu Server 17.04 - 蓝光驱动器的 udev 规则

Ubuntu Server 17.04 - 蓝光驱动器的 udev 规则

我正在尝试创建一条udev规则,允许非 root 用户在任意挂载点上挂载插入蓝光驱动器的磁盘。

由于驱动器是永久性的,但磁盘不是,所以我没有使用/etc/fstab- 我的理解可能是错误的,因为这/etc/fstab不适合这种情况。

10-bluray.rules我在非 root 主目录中创建了一个名为 的文件,并将其符号链接到/etc/udev/rules.d/10-bluray.rules。我定义的规则是:

ACTION=="change", SUBSYSTEM=="block", KERNEL=="sr[0-9]*", ENV{ID_CDROM_MEDIA_STATE}=="complete", GROUP="users"

sudo udevadm control --reload-rules然而,运行并弹出并插入磁盘后,我的/dev仍然看起来像这样:

brw-rw---- 1 root cdrom    11,   0 2017-09-09 00:52 sr0
lrwxrwxrwx 1 root root           3 2017-09-09 00:52 dvdrw -> sr0
lrwxrwxrwx 1 root root           3 2017-09-09 00:52 dvd -> sr0
lrwxrwxrwx 1 root root           3 2017-09-09 00:52 cdrw -> sr0
lrwxrwxrwx 1 root root           3 2017-09-09 00:52 cdrom -> sr0

将组设置为 ,cdrom而不是 ,如规则users中指定的那样udev

我甚至已经检查过sudo udevadm test /dev/sr0并且它没有表明规则存在任何问题:

=== trie on-disk ===
tool version:          232
file size:         8775171 bytes
header size             80 bytes
strings            1849483 bytes
nodes              6925608 bytes
Load module index
Found container virtualization none
timestamp of '/etc/systemd/network' changed
timestamp of '/lib/systemd/network' changed
Parsed configuration file /lib/systemd/network/99-default.link
Created link configuration context.
timestamp of '/etc/udev/rules.d' changed
Reading rules file: /etc/udev/rules.d/10-bluray.rules
Reading rules file: /lib/udev/rules.d/40-vm-hotadd.rules
Reading rules file: /lib/udev/rules.d/50-apport.rules
Reading rules file: /lib/udev/rules.d/50-firmware.rules
Reading rules file: /lib/udev/rules.d/50-udev-default.rules
Reading rules file: /etc/udev/rules.d/51-android.rules
Reading rules file: /lib/udev/rules.d/55-dm.rules
Reading rules file: /lib/udev/rules.d/56-lvm.rules
Reading rules file: /lib/udev/rules.d/60-block.rules
Reading rules file: /lib/udev/rules.d/60-bridge-network-interface.rules
Reading rules file: /lib/udev/rules.d/60-cdrom_id.rules
Reading rules file: /lib/udev/rules.d/60-crda.rules
Reading rules file: /lib/udev/rules.d/60-drm.rules
Reading rules file: /lib/udev/rules.d/60-evdev.rules
Reading rules file: /lib/udev/rules.d/60-libgphoto2-6.rules
Reading rules file: /lib/udev/rules.d/60-libsane.rules
Reading rules file: /lib/udev/rules.d/60-open-vm-tools.rules
Reading rules file: /lib/udev/rules.d/60-persistent-alsa.rules
Reading rules file: /lib/udev/rules.d/60-persistent-input.rules
Reading rules file: /lib/udev/rules.d/60-persistent-storage-dm.rules
Reading rules file: /lib/udev/rules.d/60-persistent-storage-tape.rules
Reading rules file: /lib/udev/rules.d/60-persistent-storage.rules
Reading rules file: /lib/udev/rules.d/60-persistent-v4l.rules
Reading rules file: /lib/udev/rules.d/60-qemu-system-common.rules
Reading rules file: /lib/udev/rules.d/60-serial.rules
Reading rules file: /lib/udev/rules.d/60-tvbutler-perms.rules
Reading rules file: /lib/udev/rules.d/60-vlan-network-interface.rules
Reading rules file: /lib/udev/rules.d/61-persistent-storage-android.rules
Reading rules file: /lib/udev/rules.d/63-md-raid-arrays.rules
Reading rules file: /lib/udev/rules.d/64-btrfs-dm.rules
Reading rules file: /lib/udev/rules.d/64-btrfs.rules
Reading rules file: /lib/udev/rules.d/64-md-raid-assembly.rules
Reading rules file: /lib/udev/rules.d/66-snapd-autoimport.rules
Reading rules file: /lib/udev/rules.d/69-bcache.rules
Reading rules file: /lib/udev/rules.d/69-cd-sensors.rules
Reading rules file: /lib/udev/rules.d/69-libmtp.rules
Reading rules file: /lib/udev/rules.d/69-lvm-metad.rules
Reading rules file: /lib/udev/rules.d/70-android-tools-adb.rules
Reading rules file: /lib/udev/rules.d/70-android-tools-fastboot.rules
Reading rules file: /lib/udev/rules.d/70-debian-uaccess.rules
Reading rules file: /lib/udev/rules.d/70-iscsi-network-interface.rules
Reading rules file: /lib/udev/rules.d/70-mouse.rules
Reading rules file: /lib/udev/rules.d/70-power-switch.rules
Reading rules file: /etc/udev/rules.d/70-snap.core.rules
Reading rules file: /lib/udev/rules.d/70-touchpad.rules
Reading rules file: /lib/udev/rules.d/70-uaccess.rules
Reading rules file: /lib/udev/rules.d/71-power-switch-proliant.rules
Reading rules file: /lib/udev/rules.d/71-seat.rules
Reading rules file: /lib/udev/rules.d/71-u-d-c-gpu-detection.rules
Reading rules file: /lib/udev/rules.d/73-seat-late.rules
Reading rules file: /lib/udev/rules.d/73-special-net-names.rules
Reading rules file: /lib/udev/rules.d/73-usb-net-by-mac.rules
Reading rules file: /lib/udev/rules.d/75-net-description.rules
Reading rules file: /lib/udev/rules.d/75-probe_mtd.rules
Reading rules file: /lib/udev/rules.d/78-graphics-card.rules
Reading rules file: /lib/udev/rules.d/78-sound-card.rules
Reading rules file: /lib/udev/rules.d/80-debian-compat.rules
Reading rules file: /lib/udev/rules.d/80-docker.io.rules
Reading rules file: /lib/udev/rules.d/80-drivers.rules
Reading rules file: /lib/udev/rules.d/80-ifupdown.rules
Reading rules file: /lib/udev/rules.d/80-net-setup-link.rules
Reading rules file: /lib/udev/rules.d/80-snappy-assign.rules
Reading rules file: /lib/udev/rules.d/80-udisks2.rules
Reading rules file: /lib/udev/rules.d/85-hdparm.rules
Reading rules file: /lib/udev/rules.d/85-keyboard-configuration.rules
Reading rules file: /lib/udev/rules.d/85-regulatory.rules
Reading rules file: /lib/udev/rules.d/90-alsa-restore.rules
Reading rules file: /lib/udev/rules.d/90-console-setup.rules
Reading rules file: /lib/udev/rules.d/95-cd-devices.rules
Reading rules file: /lib/udev/rules.d/99-systemd.rules
Reading rules file: /lib/udev/rules.d/99-vmware-scsi-udev.rules
rules contain 393216 bytes tokens (32768 * 12 bytes), 31005 bytes strings
21448 strings (173557 bytes), 18376 de-duplicated (145625 bytes), 3073 trie nodes used
unable to open device '/sys/dev/sr0'
Unload module index
Unloaded link configuration context.

我对udev规则处理的理解是,规则会/etc/udev/rules.d/覆盖定义的任何规则/lib/udev/rules.d/(显然,其中大多数规则都位于此处) - 这不正确吗?

最终,我的目标是允许用户mount /dev/sr0 /<blah>/<blah>在不使用的情况下进行发行sudo- 这可能吗?

答案1

  • 据我所知,让普通用户访问 CDROM 的正确方法是将他们添加到cdrom组中。

    1. 将现有用户添加到cdrom
    2. 将组添加到文件中cdrom的默认组中。参考:useradd/etc/default/useraddLinux 上默认组和用户背后的原因
  • 如果您仍想尝试udev该方法。

    是的,中的规则/etc会覆盖中的规则/lib,但仅限于在两个文件夹中匹配相同文件名的规则。因此不会忽略所有其他具有唯一名称的文件。

    1. 对我来说,使用非常低的顺序10-不利于用户自定义规则。任何使用>10-(字母数字顺序)的规则,如果GROUP为同一节点设置了 ,都会覆盖您的自定义规则。因此,请尝试将其至少更改为99-或。90-

    2. 对于ACTION=="change",检查当 CD 驱动器具有热插拔选项时是否触发此事件,使用udevadm monitor。否则,使用ACTION=="add"

相关内容