我创建了一个非常简单的 udev 规则/etc/udev/rules.d/99-local.rules
,当 USB 密钥插入我的计算机时,它会运行一个脚本来在 /tmp 中创建一个文件。我在运行 Ubuntu Server 20.04 的 Raspberry Pi 4 和运行 Manjaro 的 Dell Inspiron 上对此进行了测试。在这两种情况下,规则都会触发并创建文件。
所以这可能不是一个问题,但我对命令的输出很好奇:
sudo udevadm test /sys/class/block/sda1
当我在两个操作系统上运行此命令时,我得到大致相同的输出,但在 Ubuntu 的情况下,我收到两个警告:
Ubuntu
ubuntu@ubuntu:/etc/default$ sudo udevadm test /sys/class/block/sda1
This program is for debugging only, it does not run any program
specified by a RUN key. It may show incorrect results, because
some values may be different, or not available at a simulation run.
Load module index
Network interface NamePolicy= disabled on kernel command line, ignoring.
Parsed configuration file /usr/lib/systemd/network/99-default.link
Parsed configuration file /usr/lib/systemd/network/73-usb-net-by-mac.link
Created link configuration context.
Reading rules file: /usr/lib/udev/rules.d/01-md-raid-creating.rules
Reading rules file: /usr/lib/udev/rules.d/40-usb_modeswitch.rules
Reading rules file: /usr/lib/udev/rules.d/40-vm-hotadd.rules
Reading rules file: /usr/lib/udev/rules.d/50-apport.rules
...
...
...
Reading rules file: /usr/lib/udev/rules.d/96-e2scrub.rules
Reading rules file: /etc/udev/rules.d/99-local.rules
Reading rules file: /usr/lib/udev/rules.d/99-systemd.rules
Invalid inotify descriptor.
DEVPATH=/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.3/1-1.3:1.0/host0/target0:0:0/0:0:0:0/block/sda/sda1
DEVNAME=/dev/sda1
DEVTYPE=partition
PARTN=1
PARTNAME=Main Data Partition
MAJOR=8
MINOR=1
ACTION=add
SUBSYSTEM=block
ID_SCSI=1
ID_SCSI_INQUIRY=1
ID_VENDOR=Lexar
...
...
...
ID_FS_TYPE_NEW=vfat
TAGS=:systemd:
USEC_INITIALIZED=10879865388
run: '/usr/bin/unshare -m /usr/bin/snap auto-import --mount=/dev/sda1'
run: '/usr/local/bin/test_script2.sh'
Unload module index
Unloaded link configuration context.
我在 Manjaro 中没有收到这些警告,并且还可以看到一些更有用的输出,因为它明确列出了输出,我可以将正在处理的 udev 规则与正在连接的 USB 密钥的设备块关联起来。
曼扎罗
[flex-inspiron7520 tmp]# udevadm test /sys/class/block/sdb1
This program is for debugging only, it does not run any program
specified by a RUN key. It may show incorrect results, because
some values may be different, or not available at a simulation run.
Trying to open "/etc/systemd/hwdb/hwdb.bin"...
Trying to open "/etc/udev/hwdb.bin"...
Trying to open "/usr/lib/systemd/hwdb/hwdb.bin"...
Trying to open "/usr/lib/udev/hwdb.bin"...
=== trie on-disk ===
tool version: 250
file size: 11819111 bytes
header size 80 bytes
strings 2415199 bytes
nodes 9403832 bytes
Load module index
Found cgroup2 on /sys/fs/cgroup/, full unified hierarchy
Found container virtualization none.
Loaded timestamp for '/etc/systemd/network'.
Loaded timestamp for '/usr/lib/systemd/network'.
Parsed configuration file /usr/lib/systemd/network/99-default.link
Created link configuration context.
Loaded timestamp for '/etc/udev/rules.d'.
Reading rules file: /usr/lib/udev/rules.d/01-md-raid-creating.rules
...
...
...
Reading rules file: /etc/udev/rules.d/99-local.rules
Reading rules file: /usr/lib/udev/rules.d/99-systemd.rules
sdb1: /usr/lib/udev/rules.d/50-udev-default.rules:71 GROUP 995
sdb1: /usr/lib/udev/rules.d/60-persistent-storage.rules:69 LINK 'disk/by-id/usb-Lexar_JD_FireFly_<< redacted >>'
sdb1: /usr/lib/udev/rules.d/60-persistent-storage.rules:93 LINK 'disk/by-path/pci-0000:00:14.0-usb-0:3:1.0-scsi-0:0:0:0-part1'
sdb1: /usr/lib/udev/rules.d/60-persistent-storage.rules:110 Importing properties from results of builtin command 'blkid'
sdb1: Probe /dev/sdb1 with raid and offset=0
sdb1: /usr/lib/udev/rules.d/60-persistent-storage.rules:113 LINK 'disk/by-uuid/<< redacted >>'
sdb1: /usr/lib/udev/rules.d/60-persistent-storage.rules:114 LINK 'disk/by-label/RESCUE'
sdb1: /usr/lib/udev/rules.d/60-persistent-storage.rules:121 LINK 'disk/by-partuuid/<< redacted >>'
sdb1: /usr/lib/udev/rules.d/60-persistent-storage.rules:122 LINK 'disk/by-partlabel/Main\x20Data\x20Partition'
sdb1: /etc/udev/rules.d/99-local.rules:3 RUN '/usr/local/bin/test_script.sh'
sdb1: Preserve permissions of /dev/sdb1, uid=0, gid=995, mode=0660
sdb1: Handling device node '/dev/sdb1', devnum=b8:17
sdb1: sd-device: Created db file '/run/udev/data/b8:17' for '/devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3:1.0/host6/target6:0:
0/6:0:0:0/block/sdb/sdb1'
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3:1.0/host6/target6:0:0/6:0:0:0/block/sdb/sdb1
DEVNAME=/dev/sdb1
DEVTYPE=partition
DISKSEQ=16
PARTN=1
PARTNAME=Main Data Partition
MAJOR=8
MINOR=17
ACTION=add
SUBSYSTEM=block
TAGS=:systemd:
ID_VENDOR=Lexar
...
...
...
CURRENT_TAGS=:systemd:
USEC_INITIALIZED=5699747586
run: '/usr/local/bin/test_script.sh'
Unload module index
Unloaded link configuration context.
我的发行版
ubuntu@ubuntu:/etc/default$ uname -a
Linux ubuntu 5.4.0-1059-raspi #67-Ubuntu SMP PREEMPT Mon Apr 11 14:16:01 UTC 2022 aarch64 aarch64 aarch64 GNU/Linux
和...
[flex@flex-inspiron7520 bin]$ uname -a
Linux flex-inspiron7520 5.15.32-1-MANJARO #1 SMP PREEMPT Mon Mar 28 09:16:36 UTC 2022 x86_64 GNU/Linux
我的问题:
我是否需要担心 Ubuntu 中 udevadm test ... 输出中的错误/警告?这是否会阻止 udev 规则在 Ubuntu 上正常工作?
有谁知道如何修复这些错误,以便我可以看到与在 Manjaro 中得到的完整输出相同的输出?
干杯!
附加信息
(为了便于阅读,我添加了反斜杠)
ubuntu@ubuntu:~$ cat /proc/cmdline
coherent_pool=1M 8250.nr_uarts=1 snd_bcm2835.enable_compat_alsa=0 \
snd_bcm2835.enable_hdmi=1 bcm2708_fb.fbwidth=0 bcm2708_fb.fbheight=0 \
bcm2708_fb.fbswap=1 smsc95xx.macaddr=<< Redacted >> \
vc_mem.mem_base=0x3ec00000 vc_mem.mem_size=0x40000000 \
elevator=deadline net.ifnames=0 console=ttyS0,115200 \
dwc_otg.lpm_enable=0 console=tty1 root=LABEL=writable \
rootfstype=ext4 rootwait fixrtc quiet splash quiet splash
再次阅读后Debian 错误报告我尝试在 Ubuntu 20.04 上启用持久(?可预测)接口名称。由于它在 Pi 4 上运行,所以我必须在启动分区中将 cmdline.txt
sudo nano /boot/firmware/cmdline.txt
改为:.. 然后net.ifnames=0
重新net.ifnames=1
启动。现在,当我运行命令时sudo udevadm test /sys/class/block/sda1
,我得到的输出与之前在 Ubuntu 上得到的输出完全相同,只是少了一条消息:Network interface NamePolicy= disabled on kernel command line, ignoring.
所以现在我不知道这是否是一个需要担心的问题。
我认为 Ubuntu 和 Manjaro 之间前几行输出存在差异的原因udevadm
部分在于不仅在两个不同的系统上运行的命令,而且每个操作系统上的 udev/udevadm 软件版本也不同。Manjaro (250) vs Ubuntu (245)。
答案1
Invalid inotify descriptor
我将 Raspberry Pi 4 升级到最新版本(2022 年 4 月)的 Ubuntu Server 22.04,在命令输出中不再看到该消息udevadm test
。
Ubuntu Server 20.04(至少对于 Raspberry Pi 而言)包含 Systemd v245,但 Raspberry Pi 的 Ubuntu Server 22.04 包含 Systemd v249.11。Manjaro 21.2.5 有 Systemd v250。
因此,我猜测 Ubuntu Server 20.04 和 Manjaro 21.2.5 之间的命令输出差异udevadm test
是由于每个发行版中 systemd 的版本不同造成的。
我仍然想了解为什么我invalid inotify descriptor
在 Raspberry Pi 上的 Ubuntu Server 20.04 上收到该消息,但目前的解决方案是升级到 Ubuntu Server 22.04。