【Debian】udev规则编写依据

1. udev规则文件路径一般在:

/etc/udev/rules

2. udev规则文件命名方式为 [优先级]-[描述].rules

3. udev规则文件中可以有很多条规则(毕竟文件扩展名是rules),一行为一条规则

4. 一条规则的编写方式为 :

ACTION==[规则触发条件],[匹配属性]==[属性值],[匹配属性]==[属性值],......,[设置属性]=[设置值]
# eg.
ACTION=="add",SUBSYSTEM=="net",DRIVER=="r8152",NAME="eth1"

5. ACTION支持的条件:

add:当设备被添加到系统时触发规则。
remove:当设备被从系统中移除时触发规则。
change:当设备的某些属性发生变化时触发规则。
move:当设备被移动到另一个位置时触发规则。
online:当设备从离线状态变为在线状态时触发规则。
offline:当设备从在线状态变为离线状态时触发规则。

6. 常见属性:

ATTRS:设备的属性,例如ATTRS{idVendor}ATTRS{idProduct}等。

KERNEL:设备的内核名称,例如KERNEL=="sd*"匹配所有块设备。

SUBSYSTEM:设备所属的子系统,例如SUBSYSTEM=="block"匹配所有块设备。

ACTION:设备的操作,例如ACTION=="add"匹配设备插入事件。

DRIVER:设备的驱动程序,例如DRIVER=="usb"匹配所有USB设备。

ENV:设置环境变量,例如ENV{ID_BUS}="usb"

SYMLINK:创建符号链接,例如SYMLINK+="mydevice"

PROGRAM:执行外部程序,例如PROGRAM="/path/to/script.sh"

RUN:执行内联命令,例如RUN+="/bin/command"

NAME: 重命名设备

7. 具体的attr查看方式为:

udevadm info -a -n [设备路径]
# eg.
udevadm info -a -n /dev/urandom

Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.

  looking at device '/devices/virtual/mem/urandom':
    KERNEL=="urandom"
    SUBSYSTEM=="mem"
    DRIVER==""
    ATTR{power/control}=="auto"
    ATTR{power/runtime_active_time}=="0"
    ATTR{power/runtime_status}=="unsupported"
    ATTR{power/runtime_suspended_time}=="0"

8. 查看USB设备用

lsusb -t 
udevadm info  -a -n /dev/bus/usb/*
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值