Linux 7.x 中UDEV生效的方法是什么

2023-04-11 04:14:00 linux 方法 生效
UDEV是一个用于动态管理设备的工具,它可以根据设备的属性来动态创建设备节点。UDEV的规则是用来描述设备的属性和设备节点的映射关系。 要使UDEV生效,首先需要在/etc/udev/rules.d/目录下创建一个规则文件,然后使用udevadm命令来重新加载规则文件。 下面是一个简单的UDEV规则文件: # This is a sample udev rule file # It will create a node named /dev/mydevice with the major number 10 and the minor number 20 # The rule will match the device with the ID_VENDOR="myvendor" and the ID_MODEL="mymodel" # # To match multiple devices, you can use multiple matches, like this: # # SUBSYSTEM=="usb", ATTRS{idVendor}=="1234", ATTRS{idProduct}=="5678", NAME="mydevice" # SUBSYSTEM=="usb", ATTRS{idVendor}=="1234", ATTRS{idProduct}=="abcd", NAME="mydevice" # # If you want to match the device by its path, you can use this: # # SUBSYSTEM=="usb", ATTRS{idVendor}=="1234", ATTRS{idProduct}=="5678", SYMLINK+="mydevice", NAME="mydevice" # # You can also create multiple symlinks for a device, like this: # # SUBSYSTEM=="usb", ATTRS{idVendor}=="1234", ATTRS{idProduct}=="5678", SYMLINK+="mydevice1", SYMLINK+="mydevice2" # # # If you want to run a program when the device is added or removed, you can use this: # # SUBSYSTEM=="usb", ATTRS{idVendor}=="1234", ATTRS{idProduct}=="5678", ACTION=="add", RUN+="/path/to/program" # SUBSYSTEM=="usb", ATTRS{idVendor}=="1234", ATTRS{idProduct}=="5678", ACTION=="remove", RUN+="/path/to/program" # # # If you want to create a device with a specific major and minor number, you can use this: # # SUBSYSTEM=="usb", ATTRS{idVendor}=="1234", ATTRS{idProduct}=="5678", NAME="mydevice", MAJOR="10", MINOR="20" # # # If you want to specify permissions for the device, you can use this: # # SUBSYSTEM=="usb", ATTRS{idVendor}=="1234", ATTRS{idProduct}=="5678", NAME="mydevice", MODE="0666" # # # If you want to create a symlink to the device with a different name, you can use this: # # SUBSYSTEM=="usb", ATTRS{idVendor}=="1234", ATTRS{idProduct}=="5678", SYMLINK+="mydevice", NAME="mydevice1" # # # If you want to match the device by its serial number, you can use this: # # SUBSYSTEM=="usb", ATTRS{idVendor}=="1234", ATTRS{idProduct}=="5678", ATTRS{serial}=="12345678", NAME="mydevice"

相关文章