KERNEL / SUBSYSTEM / DRIVER / ATTR 只匹配本设备不匹配父设备. 加个S, 就可以在本设备以及父设备整条链上搜索匹配。 KERNELS / SUBSYSTEMS / DRIVERS / ATTRS* - match any character, zero or more times ? - match any character exactly once [] - match any single character specified in the brackets, ranges are also permitted
替换符
$kernel, %k The kernel name for this device. $number, %n The kernel number for this device. For example, "sda3" has kernel number 3. $devpath, %p The devpath of the device. $id, %b The name of the device matched while searching the devpath upwards for SUBSYSTEMS, KERNELS, DRIVERS, and ATTRS. $driver The driver name of the device matched while searching the devpath upwards for SUBSYSTEMS, KERNELS, DRIVERS, and ATTRS. $attr{file}, %s{file} The value of a sysfs attribute found at the device where all keys of the rule have matched. If the matching device does not have such an attribute, and a previous KERNELS, SUBSYSTEMS, DRIVERS, or ATTRS test selected a parent device, then the attribute from that parent device is used. If the attribute is a symlink, the last element of the symlink target is returned as the value. %%: 符号 % 本身。 $$: 符号 $ 本身。
udevadm info 指令 取代 udevinfoudevadm info -a -p /sys/block/sda 获取设备ATTRS各项属性last_rule - 到本条规则为止,后续规则不起作用OPTIONS+="last_rule"udevadm test /sys/block/sda 测试规则udevadm control --reload-rules 修改规则后重新加载生效udevadm control -RNAME= 只对网路设备起作用NAME
The name to use for a network interface. See
systemd.link(5) for a higher-level mechanism
for setting the interface name. The name of a
device node cannot be changed by udev, only
additional symlinks can be created.
/etc/udev/rules.d/10-usb-storage.rules :KERNEL!="sd[a-z][0-9]",GOTO="automount_exit" ACTION=="add", SUBSYSTEM=="block", RUN+="/bin/mkdir -p /media/%k", RUN+="/usr/bin/mount $devnode /media/%k" ACTION=="remove", RUN+="/usr/bin/umount /media/%k",RUN+="/bin/rmdir /media/%k" LABEL="automount_exit"
ACTION=="add", KERNEL=="sd*[0-9]", SUBSYSTEMS=="block", SYMLINK+="sd-myself", ATTRS{model}=="Your_Harddisk_Model"`