一、列出设备所有属性,用来编写udev规则
# udevadm info -a -n [device name]
将 [device name]
替换为系统中存在的设备,比如 /dev/sda
或 /dev/ttyUSB0
。
如果你不知道设备名,你也可以列出某个系统路径的属性:
-a :所有属性
-n:后面跟设备节点node
查看video设备节点所有属性
# udevadm info -a -n /dev/video16
root:/ # udevadm info -a -n /dev/video16
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/platform/soc/e6ef4000.video/video4linux/video16':
KERNEL=="video16"
SUBSYSTEM=="video4linux"
DRIVER==""
ATTR{dev_debug}=="0"
ATTR{index}=="2"
ATTR{name}=="VIN4 output"
looking at parent device '/devices/platform/soc/e6ef4000.video':
KERNELS=="e6ef4000.video"
SUBSYSTEMS=="platform"
DRIVERS=="rcar-vin"
ATTRS{driver_override}=="(null)"
ATTRS{modalias}=="of:NvideoT<NULL>Crenesas,vin-r8a7795"
looking at parent device '/devices/platform/soc':
KERNELS=="soc"
SUBSYSTEMS=="platform"
DRIVERS==""
ATTRS{driver_override}=="(null)"
ATTRS{modalias}=="of:NsocT<NULL>Csimple-bus"
looking at parent device '/devices/platform':
KERNELS=="platform"
SUBSYSTEMS==""
DRIVERS==""
二、根据规则,在/etc/udev/rules/目录下创建规则66-video-camera.rules
# There are a number of modifiers that are allowed to be used in some
# of the different fields. They provide the following subsitutions:
#
# %n the "kernel number" of the device.
# For example, 'sda3' has a "kernel number" of '3'
# %e the smallest number for that name which does not matches an existing node
# %k the kernel name for the device
# %M the kernel major number for the device
# %m the kernel minor number for the device
# %b the bus id for the device
# %c the string returned by the PROGRAM
# %s{filename} the content of a sysfs attribute
# %% the '%' char itself
#
ACTION=="add", KERNEL=="video*", KERNELS=="e6ef4000.video",DRIVERS=="rcar-vin",SYMLINK="video-camera"
三、查看创建软链接节点
root:/ # root@ivi-c229-vm-linux:/ # ls /dev/video-camera -l
lrwxrwxrwx 1 root inet 7 Jan 1 1970 /dev/video-camera -> video16
root:/ #
参考文章:https://wiki.archlinux.org/index.php/Udev_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)