如何调试简单的 udev 规则

如何调试简单的 udev 规则

我对编写 udev 规则非常陌生,读得越多,我就越困惑。我正尝试将 USB 驱动器的文件系统挂载到持久设备名称。以下是输出udevadm info(为了便于阅读,在第 3 块之后截断):

looking at device '/devices/pci0000:00/0000:00:14.0/usb2/2-4/2-4:1.0/host2/target2:0:0/2:0:0:0/block/sda/sda1':
KERNEL=="sda1"
SUBSYSTEM=="block"
DRIVER==""
ATTR{SUBSYSTEM}=="block"
ATTR{DEVTYPE}=="partition"
ATTR{PARTN}=="1"
ATTR{MAJOR}=="8"
ATTR{MINOR}=="1"
ATTR{USEC_INITIALIZED}=="1235172438"
ATTR{ID_VENDOR}=="SanDisk"
ATTR{ID_VENDOR_ENC}=="SanDisk\x20"
ATTR{ID_VENDOR_ID}=="0781"
ATTR{ID_MODEL}=="Ultra"
ATTR{ID_MODEL_ENC}=="Ultra\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20"
ATTR{ID_MODEL_ID}=="5581"
ATTR{ID_REVISION}=="1.00"
ATTR{ID_SERIAL}=="SanDisk_Ultra_4C530001080716117381-0:0"
ATTR{ID_SERIAL_SHORT}=="4C530001080716117381"
ATTR{ID_TYPE}=="disk"
ATTR{ID_INSTANCE}=="0:0"
ATTR{ID_BUS}=="usb"
ATTR{ID_USB_INTERFACES}==":080650:"
ATTR{ID_USB_INTERFACE_NUM}=="00"
ATTR{ID_USB_DRIVER}=="usb-storage"
ATTR{ID_PATH}=="pci-0000:00:14.0-usb-0:4:1.0-scsi-0:0:0:0"
ATTR{ID_PATH_TAG}=="pci-0000_00_14_0-usb-0_4_1_0-scsi-0_0_0_0"
ATTR{ID_PART_TABLE_UUID}=="7a6efb82"
ATTR{ID_PART_TABLE_TYPE}=="dos"
ATTR{ID_FS_UUID}=="f3f13dad-53c9-4f1b-b9af-95d504904a9f"
ATTR{ID_FS_UUID_ENC}=="f3f13dad-53c9-4f1b-b9af-95d504904a9f"
ATTR{ID_FS_VERSION}=="1.0"
ATTR{ID_FS_TYPE}=="ext4"
ATTR{ID_FS_USAGE}=="filesystem"
ATTR{ID_PART_ENTRY_SCHEME}=="dos"
ATTR{ID_PART_ENTRY_UUID}=="7a6efb82-01"
ATTR{ID_PART_ENTRY_TYPE}=="0x83"
ATTR{ID_PART_ENTRY_NUMBER}=="1"
ATTR{ID_PART_ENTRY_OFFSET}=="2048"
ATTR{ID_PART_ENTRY_SIZE}=="30029824"
ATTR{ID_PART_ENTRY_DISK}=="8:0"
ATTR{TAGS}==":systemd:"
looking at device '/devices/pci0000:00/0000:00:14.0/usb2/2-4/2-4:1.0/host2/target2:0:0/2:0:0:0/block/sda/sda1':
KERNEL=="sda1"
SUBSYSTEM=="block"
DRIVER==""
ATTR{SUBSYSTEM}=="block"
ATTR{DEVTYPE}=="partition"
ATTR{PARTN}=="1"
ATTR{MAJOR}=="8"
ATTR{MINOR}=="1"
ATTR{USEC_INITIALIZED}=="1235172438"
ATTR{ID_VENDOR}=="SanDisk"
ATTR{ID_VENDOR_ENC}=="SanDisk\x20"
ATTR{ID_VENDOR_ID}=="0781"
ATTR{ID_MODEL}=="Ultra"
ATTR{ID_MODEL_ENC}=="Ultra\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20"
ATTR{ID_MODEL_ID}=="5581"
ATTR{ID_REVISION}=="1.00"
ATTR{ID_SERIAL}=="SanDisk_Ultra_4C530001080716117381-0:0"
ATTR{ID_SERIAL_SHORT}=="4C530001080716117381"
ATTR{ID_TYPE}=="disk"
ATTR{ID_INSTANCE}=="0:0"
ATTR{ID_BUS}=="usb"
ATTR{ID_USB_INTERFACES}==":080650:"
ATTR{ID_USB_INTERFACE_NUM}=="00"
ATTR{ID_USB_DRIVER}=="usb-storage"
ATTR{ID_PATH}=="pci-0000:00:14.0-usb-0:4:1.0-scsi-0:0:0:0"
ATTR{ID_PATH_TAG}=="pci-0000_00_14_0-usb-0_4_1_0-scsi-0_0_0_0"
ATTR{ID_PART_TABLE_UUID}=="7a6efb82"
ATTR{ID_PART_TABLE_TYPE}=="dos"
ATTR{ID_FS_UUID}=="f3f13dad-53c9-4f1b-b9af-95d504904a9f"
ATTR{ID_FS_UUID_ENC}=="f3f13dad-53c9-4f1b-b9af-95d504904a9f"
ATTR{ID_FS_VERSION}=="1.0"
ATTR{ID_FS_TYPE}=="ext4"
ATTR{ID_FS_USAGE}=="filesystem"
ATTR{ID_PART_ENTRY_SCHEME}=="dos"
ATTR{ID_PART_ENTRY_UUID}=="7a6efb82-01"
ATTR{ID_PART_ENTRY_TYPE}=="0x83"
ATTR{ID_PART_ENTRY_NUMBER}=="1"
ATTR{ID_PART_ENTRY_OFFSET}=="2048"
ATTR{ID_PART_ENTRY_SIZE}=="30029824"
ATTR{ID_PART_ENTRY_DISK}=="8:0"
ATTR{TAGS}==":systemd:"
looking at parent device '/devices/pci0000:00/0000:00:14.0/usb2/2-4/2-4:1.0/host2/target2:0:0/2:0:0:0/block/sda':
KERNELS=="sda"
SUBSYSTEMS=="block"
DRIVERS==""
ATTRS{SUBSYSTEM}=="block"
ATTRS{DEVTYPE}=="disk"
ATTRS{MAJOR}=="8"
ATTRS{MINOR}=="0"
ATTRS{USEC_INITIALIZED}=="1235109014"
ATTRS{ID_VENDOR}=="SanDisk"
ATTRS{ID_VENDOR_ENC}=="SanDisk\x20"
ATTRS{ID_VENDOR_ID}=="0781"
ATTRS{ID_MODEL}=="Ultra"
ATTRS{ID_MODEL_ENC}=="Ultra\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20"
ATTRS{ID_MODEL_ID}=="5581"
ATTRS{ID_REVISION}=="1.00"
ATTRS{ID_SERIAL}=="SanDisk_Ultra_4C530001080716117381-0:0"
ATTRS{ID_SERIAL_SHORT}=="4C530001080716117381"
ATTRS{ID_TYPE}=="disk"
ATTRS{ID_INSTANCE}=="0:0"
ATTRS{ID_BUS}=="usb"
ATTRS{ID_USB_INTERFACES}==":080650:"
ATTRS{ID_USB_INTERFACE_NUM}=="00"
ATTRS{ID_USB_DRIVER}=="usb-storage"
ATTRS{ID_PATH}=="pci-0000:00:14.0-usb-0:4:1.0-scsi-0:0:0:0"
ATTRS{ID_PATH_TAG}=="pci-0000_00_14_0-usb-0_4_1_0-scsi-0_0_0_0"
ATTRS{ID_PART_TABLE_UUID}=="7a6efb82"
ATTRS{ID_PART_TABLE_TYPE}=="dos"
ATTRS{TAGS}==":systemd:"
looking at parent device '/devices/pci0000:00/0000:00:14.0/usb2/2-4/2-4:1.0/host2/target2:0:0/2:0:0:0':
KERNELS=="2:0:0:0"
SUBSYSTEMS=="scsi"
DRIVERS=="sd"
ATTRS{SUBSYSTEM}=="scsi"
ATTRS{DRIVER}=="sd"
ATTRS{DEVTYPE}=="scsi_device"
ATTRS{MODALIAS}=="scsi:t-0x00"
looking at parent device '/devices/pci0000:00/0000:00:14.0/usb2/2-4/2-4:1.0/host2/target2:0:0/2:0:0:0':
KERNELS=="2:0:0:0"
SUBSYSTEMS=="scsi"
DRIVERS=="sd"
ATTRS{SUBSYSTEM}=="scsi"
ATTRS{DRIVER}=="sd"
ATTRS{DEVTYPE}=="scsi_device"
ATTRS{MODALIAS}=="scsi:t-0x00"

根据输出我生成了以下规则:

KERNEL=="sd?1", SUBSYSTEM=="block", ATTR{ID_VENDOR_ID}=="0781", ATTR{ID_SERIAL_SHORT}=="4C530001080716117381", OWNER="ft", SYMLINK+="music"

我无法调试为什么这不起作用。没有/dev/music创建,该棒仍然安装到一个神秘的安装点。

答案1

由于类型或属性名称错误,它不起作用。请尝试以下规则之一:

使用 udev 环境(ENV)

KERNEL=="sd?1", SUBSYSTEM=="block", ENV{ID_VENDOR_ID}=="0781", ENV{ID_SERIAL_SHORT}=="4C530001080716117381", OWNER="ft", SYMLINK+="music"

使用 ATTRS 和内核命名方案

KERNEL=="sd?1", SUBSYSTEM=="block", ATTRS{idVendor}=="0781", ATTRS{serial}=="4C530001080716117381", OWNER="ft", SYMLINK+="music"

使用 ATTRS 而不是 ATTR 也可以从更高级别检查父级属性。查看内核属性:/sys/bus/usb/devices/2-4

相关内容