udevadm/persistent USB 名称无效(权限错误)

udevadm/persistent USB names not working (permission error)

我有 2 个相同的蓝牙接收器连接到一个 Raspberry Pi 我需要监控房间不同位置的蓝牙信号。 不幸的是,这两个设备具有相同的 idVendor 和 idProduct 所以我 已经求助于使用 ATTR{serial} 希望 udev 可以 区分两者。

问题是在我创建了 udev 规则(使用新的 SYMLINK)之后, 只有 1 个蓝牙接收器显示正确名称的 DEVLINK 我在规则中提供了。另一个蓝牙接收器的DEVLINK名称是 从未显示。我尝试了很多事情:重新启动,重新加载 udev 规则,重新启动 udevadm。控制台提供以下错误 在 dm 测试中时(下面提供了完整的输出——我认为 根据此输出的后半部分,可能是权限问题?):

udev_event_execute_rules: no node name set, will use kernel supplied
name 'bus/usb/001/006'
udev_node_add: creating device node '/dev/bus/usb/001/006',
devnum=189:5, mode=01664, uid=0, gid=0
udev_node_mknod: preserve file '/dev/bus/usb/001/006', because it has
correct dev_t
udev_node_mknod: preserve permissions /dev/bus/usb/001/006, 021664, uid=0, gid=0
node_symlink: preserve already existing symlink '/dev/char/189:5' to
'../bus/usb/001/006'
udev_device_update_db: unable to create temporary db file
'/run/udev/data/c189:5.tmp': Permission denied
ACTION=add
BUSNUM=001
DEVNAME=/dev/bus/usb/001/006

如果有帮助,这是我为创建规则所做的 执行测试:

首先,我 运行 udevadm info 来识别不同的属性 2 个接收器。 1 台设备上的 idVendor、serial 和 idProduct 如下:

ATTR{idVendor}=="0a5c"
ATTR{serial}=="0002723FAE6C"
ATTR{idProduct}=="21e8"

在另一台设备上...

ATTR{idVendor}=="0a5c"
ATTR{serial}=="5CF37067320A"
ATTR{idProduct}=="21e8"

我创建了一个名为“00-my-usb-device.rules”的新规则文件,看起来 像下面这样:

SUBSYSTEM=="usb", ATTR{idVendor}=="0a5c",
ATTRS{serial}=="5CF37067320A", SYMLINK+="driverBT"

然后我创建了一个名为“01-my-usb-device.rules”的单独规则文件 (最初我在 1 个文件中有两个规则,但想尝试所有 可能性。该文件如下所示:

SUBSYSTEM=="USB", ATTR{serial}=="0002723FAE6C",
ATTR{idVendor}=="0a5c", SYMLINK+="rearBT"

运行 第一个端口上的 devadm 序列号为“5CF37067320A”(也 是我设定的第一条规则): udevadm 测试 /devices/platform/bcm2708_usb/usb1/1-1/1-1.5/1-1.5.2 run_command: 调用: 测试 adm_test: 版本 175 此程序仅用于调试,它不 运行 任何程序, 由 运行 键指定。它可能显示不正确的结果,因为 有些值可能不同,或者在模拟中不可用 运行。

parse_file: reading '/etc/udev/rules.d/00-my-usb-device.rules' as rules file
parse_file: reading '/etc/udev/rules.d/01-my-usb-device.rules' as rules file
parse_file: reading '/lib/udev/rules.d/10-local-rpi.rules' as rules file
parse_file: reading '/etc/udev/rules.d/40-scratch.rules' as rules file
parse_file: reading '/lib/udev/rules.d/42-qemu-usb.rules' as rules file
parse_file: reading '/lib/udev/rules.d/50-udev-default.rules' as rules file
parse_file: reading '/lib/udev/rules.d/55-dm.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-cdrom_id.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-fuse.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-gnupg.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-gpsd.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-i2c-tools.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-ifplugd.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-libgphoto2-2.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-persistent-alsa.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-persistent-input.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-persistent-serial.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-persistent-storage-dm.rules'
as rules file
parse_file: reading
'/lib/udev/rules.d/60-persistent-storage-tape.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-persistent-storage.rules' as
rules file
parse_file: reading '/lib/udev/rules.d/60-persistent-v4l.rules' as rules     file
parse_file: reading '/lib/udev/rules.d/60-python-pifacecommon.rules'
as rules file
parse_file: reading '/lib/udev/rules.d/60-python3-pifacecommon.rules'
as rules file
parse_file: reading '/lib/udev/rules.d/60-triggerhappy.rules' as rules file
parse_file: reading '/lib/udev/rules.d/61-accelerometer.rules' as rules file
parse_file: reading '/run/udev/rules.d/61-dev-root-link.rules' as rules file
parse_file: reading '/lib/udev/rules.d/64-xorg-xkb.rules' as rules file
parse_file: reading '/lib/udev/rules.d/70-uaccess.rules' as rules file
add_rule: IMPORT found builtin 'usb_id', replacing
/lib/udev/rules.d/70-uaccess.rules:13
parse_file: reading '/lib/udev/rules.d/70-udev-acl.rules' as rules file
parse_file: reading '/lib/udev/rules.d/71-seat.rules' as rules file
add_rule: IMPORT found builtin 'path_id', replacing
/lib/udev/rules.d/71-seat.rules:23
parse_file: reading '/lib/udev/rules.d/73-seat-late.rules' as rules file
parse_file: reading '/lib/udev/rules.d/75-cd-aliases-generator.rules'
as rules file
parse_file: reading '/lib/udev/rules.d/75-net-description.rules' as rules file
parse_file: reading
'/lib/udev/rules.d/75-persistent-net-generator.rules' as rules file
parse_file: reading '/lib/udev/rules.d/75-probe_mtd.rules' as rules file
parse_file: reading '/lib/udev/rules.d/75-tty-description.rules' as rules file
parse_file: reading '/lib/udev/rules.d/78-sound-card.rules' as rules file
parse_file: reading '/lib/udev/rules.d/80-drivers.rules' as rules file
parse_file: reading '/lib/udev/rules.d/80-networking.rules' as rules file
parse_file: reading '/lib/udev/rules.d/80-udisks.rules' as rules file
parse_file: reading '/lib/udev/rules.d/85-hwclock.rules' as rules file
parse_file: reading '/lib/udev/rules.d/85-usbmuxd.rules' as rules file
parse_file: reading '/lib/udev/rules.d/90-alsa-restore.rules' as rules file
parse_file: reading '/lib/udev/rules.d/91-permissions.rules' as rules file
parse_file: reading
'/lib/udev/rules.d/95-keyboard-force-release.rules' as rules file
parse_file: reading '/lib/udev/rules.d/95-keymap.rules' as rules file
parse_file: reading '/lib/udev/rules.d/95-udev-late.rules' as rules file
parse_file: reading '/lib/udev/rules.d/97-hid2hci.rules' as rules file
parse_file: reading '/etc/udev/rules.d/99-input.rules' as rules file
parse_file: reading '/lib/udev/rules.d/99-systemd.rules' as rules file
udev_rules_new: rules use 145392 bytes tokens (12116 * 12 bytes),
24358 bytes buffer
udev_rules_new: temporary index used 39920 bytes (1996 * 20 bytes)
udev_device_new_from_syspath: device 0x18b5748 has devpath
'/devices/platform/bcm2708_usb/usb1/1-1/1-1.5/1-1.5.2'
udev_device_new_from_syspath: device 0x18b2258 has devpath
'/devices/platform/bcm2708_usb/usb1/1-1/1-1.5/1-1.5.2'
udev_device_read_db: device 0x18b2258 filled with db file data
udev_rules_apply_to_event: LINK 'driverBT'
/etc/udev/rules.d/00-my-usb-device.rules:1
udev_device_new_from_syspath: device 0x18b3188 has devpath
'/devices/platform/bcm2708_usb/usb1/1-1/1-1.5'
udev_device_new_from_syspath: device 0x18b3640 has devpath
'/devices/platform/bcm2708_usb/usb1/1-1'
udev_device_new_from_syspath: device 0x18b3ae8 has devpath
'/devices/platform/bcm2708_usb/usb1'
udev_device_new_from_syspath: device 0x18b3f88 has devpath
'/devices/platform/bcm2708_usb'
udev_device_new_from_syspath: device 0x18b42d8 has devpath         '/devices/platform'
udev_rules_apply_to_event: IMPORT builtin 'usb_id'
/lib/udev/rules.d/60-libgphoto2-2.rules:11
udev_builtin_add_property: ID_VENDOR=Broadcom_Corp
udev_builtin_add_property: ID_VENDOR_ENC=Broadcom\x20Corp
udev_builtin_add_property: ID_VENDOR_ID=0a5c
udev_builtin_add_property: ID_MODEL=BCM20702A0
udev_builtin_add_property: ID_MODEL_ENC=BCM20702A0
udev_builtin_add_property: ID_MODEL_ID=21e8
udev_builtin_add_property: ID_REVISION=0112
udev_builtin_add_property: ID_SERIAL=Broadcom_Corp_BCM20702A0_5CF37067320A
udev_builtin_add_property: ID_SERIAL_SHORT=5CF37067320A
udev_builtin_add_property: ID_BUS=usb
udev_builtin_add_property: ID_USB_INTERFACES=:ff0101:ffffff:fe0101:
udev_rules_apply_to_event: MODE 0664 /lib/udev/rules.d/91-permissions.rules:36
udev_event_execute_rules: no node name set, will use kernel supplied
name 'bus/usb/001/009'
udev_node_add: creating device node '/dev/bus/usb/001/009',
devnum=189:8, mode=01664, uid=0, gid=0
udev_node_mknod: preserve file '/dev/bus/usb/001/009', because it has
correct dev_t
udev_node_mknod: preserve permissions /dev/bus/usb/001/009, 021664, uid=0,     gid=0
node_symlink: preserve already existing symlink '/dev/char/189:8' to
'../bus/usb/001/009'
link_find_prioritized: found 'c189:8' claiming '/run/udev/links/driverBT'
link_update: creating link '/dev/driverBT' to '/dev/bus/usb/001/009'
node_symlink: preserve already existing symlink '/dev/driverBT' to
'bus/usb/001/009'
udev_device_update_db: unable to create temporary db file
'/run/udev/data/c189:8.tmp': Permission denied
ACTION=add
BUSNUM=001
DEVLINKS=/dev/driverBT
DEVNAME=/dev/bus/usb/001/009
DEVNUM=009
DEVPATH=/devices/platform/bcm2708_usb/usb1/1-1/1-1.5/1-1.5.2
DEVTYPE=usb_device
DRIVER=usb
ID_BUS=usb
ID_MODEL=BCM20702A0
ID_MODEL_ENC=BCM20702A0
ID_MODEL_ID=21e8
ID_REVISION=0112
ID_SERIAL=Broadcom_Corp_BCM20702A0_5CF37067320A
ID_SERIAL_SHORT=5CF37067320A
ID_USB_INTERFACES=:ff0101:ffffff:fe0101:
ID_VENDOR=Broadcom_Corp
ID_VENDOR_ENC=Broadcom\x20Corp
ID_VENDOR_ID=0a5c
MAJOR=189
MINOR=8
PRODUCT=a5c/21e8/112
SUBSYSTEM=usb
TYPE=255/1/1
UDEV_LOG=6
USEC_INITIALIZED=465479898

运行 在第二个端口上进行 udevadm 测试(此处不存在 DEVLINK,因为 与其他设备相比):

udevadm 测试 /devices/platform/bcm2708_usb/usb1/1-1/1-1.5 run_command: 调用: 测试 adm_test: 版本 175 此程序仅用于调试,它不 运行 任何程序, 由 运行 键指定。它可能显示不正确的结果,因为 有些值可能不同,或者在模拟中不可用 运行。

parse_file: reading '/etc/udev/rules.d/00-my-usb-device.rules' as rules file
parse_file: reading '/etc/udev/rules.d/01-my-usb-device.rules' as rules file
parse_file: reading '/lib/udev/rules.d/10-local-rpi.rules' as rules file
parse_file: reading '/etc/udev/rules.d/40-scratch.rules' as rules file
parse_file: reading '/lib/udev/rules.d/42-qemu-usb.rules' as rules file
parse_file: reading '/lib/udev/rules.d/50-udev-default.rules' as rules file
parse_file: reading '/lib/udev/rules.d/55-dm.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-cdrom_id.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-fuse.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-gnupg.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-gpsd.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-i2c-tools.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-ifplugd.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-libgphoto2-2.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-persistent-alsa.rules' as rules file    
parse_file: reading '/lib/udev/rules.d/60-persistent-input.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-persistent-serial.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-persistent-storage-dm.rules'
as rules file
parse_file: reading
'/lib/udev/rules.d/60-persistent-storage-tape.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-persistent-storage.rules' as
rules file
parse_file: reading '/lib/udev/rules.d/60-persistent-v4l.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-python-pifacecommon.rules'
as rules file
parse_file: reading '/lib/udev/rules.d/60-python3-pifacecommon.rules'
as rules file
parse_file: reading '/lib/udev/rules.d/60-triggerhappy.rules' as rules file
parse_file: reading '/lib/udev/rules.d/61-accelerometer.rules' as rules file
parse_file: reading '/run/udev/rules.d/61-dev-root-link.rules' as rules file
parse_file: reading '/lib/udev/rules.d/64-xorg-xkb.rules' as rules file
parse_file: reading '/lib/udev/rules.d/70-uaccess.rules' as rules file
add_rule: IMPORT found builtin 'usb_id', replacing
/lib/udev/rules.d/70-uaccess.rules:13
parse_file: reading '/lib/udev/rules.d/70-udev-acl.rules' as rules file
parse_file: reading '/lib/udev/rules.d/71-seat.rules' as rules file
add_rule: IMPORT found builtin 'path_id', replacing
/lib/udev/rules.d/71-seat.rules:23
parse_file: reading '/lib/udev/rules.d/73-seat-late.rules' as rules file
parse_file: reading '/lib/udev/rules.d/75-cd-aliases-generator.rules'
as rules file
parse_file: reading '/lib/udev/rules.d/75-net-description.rules' as rules file
parse_file: reading
'/lib/udev/rules.d/75-persistent-net-generator.rules' as rules file
parse_file: reading '/lib/udev/rules.d/75-probe_mtd.rules' as rules file
parse_file: reading '/lib/udev/rules.d/75-tty-description.rules' as rules file
parse_file: reading '/lib/udev/rules.d/78-sound-card.rules' as rules file
parse_file: reading '/lib/udev/rules.d/80-drivers.rules' as rules file
parse_file: reading '/lib/udev/rules.d/80-networking.rules' as rules file
parse_file: reading '/lib/udev/rules.d/80-udisks.rules' as rules file
parse_file: reading '/lib/udev/rules.d/85-hwclock.rules' as rules file
parse_file: reading '/lib/udev/rules.d/85-usbmuxd.rules' as rules file
parse_file: reading '/lib/udev/rules.d/90-alsa-restore.rules' as rules file
parse_file: reading '/lib/udev/rules.d/91-permissions.rules' as rules file
parse_file: reading
'/lib/udev/rules.d/95-keyboard-force-release.rules' as rules file
parse_file: reading '/lib/udev/rules.d/95-keymap.rules' as rules file
parse_file: reading '/lib/udev/rules.d/95-udev-late.rules' as rules file
parse_file: reading '/lib/udev/rules.d/97-hid2hci.rules' as rules file
parse_file: reading '/etc/udev/rules.d/99-input.rules' as rules file
parse_file: reading '/lib/udev/rules.d/99-systemd.rules' as rules file
udev_rules_new: rules use 145392 bytes tokens (12116 * 12 bytes),
24358 bytes buffer
udev_rules_new: temporary index used 39920 bytes (1996 * 20 bytes)
udev_device_new_from_syspath: device 0x17a748 has devpath
'/devices/platform/bcm2708_usb/usb1/1-1/1-1.5'
udev_device_new_from_syspath: device 0x177258 has devpath
'/devices/platform/bcm2708_usb/usb1/1-1/1-1.5'
udev_device_read_db: device 0x177258 filled with db file data
udev_device_new_from_syspath: device 0x177db8 has devpath
'/devices/platform/bcm2708_usb/usb1/1-1'
udev_device_new_from_syspath: device 0x178260 has devpath
'/devices/platform/bcm2708_usb/usb1'
udev_device_new_from_syspath: device 0x1786d8 has devpath
'/devices/platform/bcm2708_usb'
udev_device_new_from_syspath: device 0x178a28 has devpath '/devices/platform'
udev_rules_apply_to_event: IMPORT builtin 'usb_id'
/lib/udev/rules.d/60-libgphoto2-2.rules:11
udev_builtin_add_property: ID_VENDOR=050d
udev_builtin_add_property: ID_VENDOR_ENC=050d
udev_builtin_add_property: ID_VENDOR_ID=050d
udev_builtin_add_property: ID_MODEL=0234
udev_builtin_add_property: ID_MODEL_ENC=0234
udev_builtin_add_property: ID_MODEL_ID=0234
udev_builtin_add_property: ID_REVISION=3298
udev_builtin_add_property: ID_SERIAL=050d_0234
udev_builtin_add_property: ID_BUS=usb
udev_builtin_add_property: ID_USB_INTERFACES=:090001:090002:
udev_rules_apply_to_event: MODE 0664 /lib/udev/rules.d/91-    permissions.rules:36
udev_event_execute_rules: no node name set, will use kernel supplied
name 'bus/usb/001/006'
udev_node_add: creating device node '/dev/bus/usb/001/006',
devnum=189:5, mode=01664, uid=0, gid=0
udev_node_mknod: preserve file '/dev/bus/usb/001/006', because it has
correct dev_t
udev_node_mknod: preserve permissions /dev/bus/usb/001/006, 021664, uid=0,     gid=0
node_symlink: preserve already existing symlink '/dev/char/189:5' to
'../bus/usb/001/006'
udev_device_update_db: unable to create temporary db file
'/run/udev/data/c189:5.tmp': Permission denied
ACTION=add
BUSNUM=001
DEVNAME=/dev/bus/usb/001/006
DEVNUM=006
DEVPATH=/devices/platform/bcm2708_usb/usb1/1-1/1-1.5
DEVTYPE=usb_device
DRIVER=usb
ID_BUS=usb
ID_MODEL=0234
ID_MODEL_ENC=0234
ID_MODEL_ID=0234
ID_REVISION=3298
ID_SERIAL=050d_0234
ID_USB_INTERFACES=:090001:090002:
ID_VENDOR=050d
ID_VENDOR_ENC=050d
ID_VENDOR_ID=050d
MAJOR=189
MINOR=5
PRODUCT=50d/234/3298
SUBSYSTEM=usb
TYPE=9/0/2
UDEV_LOG=6
USEC_INITIALIZED=200440100

需要内核。 2 个 BT 适配器连接到 4 端口集线器。一旦我在这 2 个规则中的每一个中指定了内核,一切都正常。

产品和序列号也用于区分这两个设备(产品可能不是必需的,因为它与其他 BT 设备匹配,但序列号肯定是必需的)。