我使用 Ubuntu 20.04 LTS 并在 /etc/udev/rules.d/ 中编写了一个自定义 udev 规则,如果特定的外部 USB 硬盘驱动器是连接的。我的 udev 规则名为 99-datensicherung.rules:
ENV{DEVTYPE}=="usb_device", \
SUBSYSTEM=="usb", \
ATTRS{idVendor}=="174c", \
ATTRS{idProduct}=="55aa", \
ATTRS{bcdDevice}=="0100", \
SYMLINK+="mybackup", \
ACTION=="add", \
RUN+="/usr/bin/logger MY DEVICE CONNECTED."
如果我查看 syslog,我发现了 logger 的消息,并看到创建了符号链接:
Okt 15 11:22:46 SWPITSLNB systemd-udevd[185107]: 2-4: /etc/udev/rules.d/99-datensicherung.rules:9 LINK 'mybackup'
Okt 15 11:22:46 SWPITSLNB systemd-udevd[185107]: 2-4: /etc/udev/rules.d/99-datensicherung.rules:9 RUN '/usr/bin/logger MY DEVICE CONNECTED.'
Okt 15 11:22:46 SWPITSLNB systemd-udevd[185107]: 2-4: Handling device node '/dev/bus/usb/002/055', devnum=c189:182
Okt 15 11:22:46 SWPITSLNB systemd-udevd[185107]: 2-4: Setting permissions /dev/bus/usb/002/055, uid=0, gid=0, mode=0664
Okt 15 11:22:46 SWPITSLNB systemd-udevd[185107]: 2-4: Creating symlink '/dev/char/189:182' to '../bus/usb/002/055'
Okt 15 11:22:46 SWPITSLNB systemd-udevd[185107]: 2-4: Creating symlink '/dev/mybackup' to 'bus/usb/002/055'
但不久之后,系统日志告诉我:
Okt 15 11:22:46 SWPITSLNB systemd-udevd[185107]: 2-4: /usr/lib/udev/rules.d/69-libmtp.rules:2685 Running PROGRAM 'mtp-probe /sys/devices/pci0000:00/0000:00:14.0/usb2/2-4 2 55'
Okt 15 11:22:46 SWPITSLNB systemd-udevd[185107]: 2-4: Starting 'mtp-probe /sys/devices/pci0000:00/0000:00:14.0/usb2/2-4 2 55'
Okt 15 11:22:46 SWPITSLNB systemd-udevd[185107]: Successfully forked off '(spawn)' as PID 185132.
Okt 15 11:22:46 SWPITSLNB mtp-probe[185132]: checking bus 2, device 55: "/sys/devices/pci0000:00/0000:00:14.0/usb2/2-4"
Okt 15 11:22:46 SWPITSLNB mtp-probe[185132]: bus: 2, device: 55 was not an MTP device
Okt 15 11:22:46 SWPITSLNB systemd-udevd[185107]: 2-4: 'mtp-probe /sys/devices/pci0000:00/0000:00:14.0/usb2/2-4 2 55'(out) '0'
Okt 15 11:22:46 SWPITSLNB systemd-udevd[185107]: 2-4: Process 'mtp-probe /sys/devices/pci0000:00/0000:00:14.0/usb2/2-4 2 55' succeeded.
Okt 15 11:22:46 SWPITSLNB systemd-udevd[185107]: 2-4: Updating old name, '/dev/mybackup' no longer belonging to '/devices/pci0000:00/0000:00:14.0/usb2/2-4'
Okt 15 11:22:46 SWPITSLNB systemd-udevd[185107]: 2-4: No reference left, removing '/dev/mybackup'
如何防止从其他 udev 规则中删除我的符号链接?非常感谢!