2016年11月7日 星期一

[Linux] 使用udev偵測device



  • Rule syntax
    KERNEL - match against the kernel name for the device
    SUBSYSTEM - match against the subsystem of the device
    DRIVER - match against the name of the driver backing the device
    NAME - the name that shall be used for the device node
    SYMLINK - a list of symbolic links which act as alternative names for the device node
    RUN - Running external programs upon certain events
    ATTR - device attribue

  • List attribute
    #udevinfo -a -p $(udevinfo -q path -n /dev/lp0)
        KERNEL=="lp0"
        SUBSYSTEM=="usb"
        DRIVER==""
        ATTR{dev}=="180:0"

  • Reload config
    #udevadm control --reload-rules

  • Example 
    KERNEL="sd*", ACTION=="add", SUBSYSTEMS=="scsi", RUN+="/bin/sh /tmp/test.sh"


Reference :
[1] Writing udev rules

沒有留言:

張貼留言