Article directory
UEDV rules file
The rule file is the most important part of udev and is stored under /etc/udev/rule.d/ by default. All rule files must have the suffix ".rules".
Here's a simple rule:
KERNEL=="sda", NAME="my_disk", MODE="0660"
KERNEL is the matching key, NAME and MODE are the assignment keys. The meaning of this rule is: if there is a device with a kernel name of sda, this condition will take effect and the subsequent assignment will be performed: create a device file named my_disk under /dev and set the permissions of the device file to 0660.
udevadm info --query=all --name=sda 查询sda的所有信息
udevadm info --query=path --name=sda 查看sda的path
udevadm info --attribute-walk --name=/dev/nvme0n1 查看nvme0n1的所有父设备一直到sysfs的根节点
Hang the rules on the USB disk, create .ruiles and put the decentralized code into
ACTION=="add", SUBSYSTEMS=="usb", SUBSYSTEM=="block", RUN{
program}+="/bin/mkdir/media/%k",RUN{
program}+="/usr/bin/systemd-mount --no-block --collect $devnode/media/%k"
ACTION
: Event (uevent) behavior, such as: add (add device), remove (delete device); :
KERNEL
Kernel device name, such as: sda, cdrom;
DEVPATH
: Devpath path of the device;
SUBSYSTEM
: Subsystem name of the device, such as: sda The system is block;
BUS
: The bus name of the device in the devpath, for example: usb; :
DRIVER
The device driver name of the device in the devpath, for example: ide-cdrom; :
ID
The identification number of the device in the devpath;
SYSFS{filename}
: Under the devpath path of the device, the device's The contents of the properties file "filename";
ENV{key}
: environment variable. In a rule, you can set the matching keys of up to five environment variables;
PROGRAM
: Call external commands;
RESULT
: Return results of external command PROGRAM.