Disclaimer

This information HAS errors and is made available WITHOUT ANY WARRANTY OF ANY KIND and without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. It is not permissible to be read by anyone who has ever met a lawyer or attorney. Use is confined to Engineers with more than 370 course hours of engineering.
If you see an error contact:
+1(785) 841 3089
inform@xtronics.com

udev Rules Tricks and More


Persitant Name

Very often this is the reason to write a rule.  Imagine you have USB-2-serial adapters that you don't want the name to change.  You plug it in and in /dev you find

$ ll /dev
crw-rw---- 1 root nut     188,   0 2017-05-18 21:21 ttyUSB0
So first we run this command
$ udevadm info -a -n /dev/ttyUSB0
Mixed in with the output is
  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1/1-8':
KERNELS=="1-8"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{authorized}=="1"
ATTRS{avoid_reset_quirk}=="0"
ATTRS{bConfigurationValue}=="1"
ATTRS{bDeviceClass}=="00"
ATTRS{bDeviceProtocol}=="00"
ATTRS{bDeviceSubClass}=="00"
ATTRS{bMaxPacketSize0}=="8"
ATTRS{bMaxPower}=="90mA"
ATTRS{bNumConfigurations}=="1"
ATTRS{bNumInterfaces}==" 1"
ATTRS{bcdDevice}=="0600"
ATTRS{bmAttributes}=="a0"
ATTRS{busnum}=="1"
ATTRS{configuration}==""
ATTRS{devnum}=="17"
ATTRS{devpath}=="8"
ATTRS{idProduct}=="6001"
ATTRS{idVendor}=="0403"
ATTRS{ltm_capable}=="no"
ATTRS{manufacturer}=="FTDI"
ATTRS{maxchild}=="0"
ATTRS{product}=="FT232R USB UART"
ATTRS{quirks}=="0x0"
ATTRS{removable}=="removable"
ATTRS{serial}=="AJV9MKOY"
ATTRS{speed}=="12"
ATTRS{urbnum}=="87835"
ATTRS{version}==" 2.00"

Most of it we don't need, but if we grab:

ATTRS{idVendor}=="0403"
ATTRS{idProduct}=="6001"
ATTRS{serial}=="AJV9MKOY"
We have everything needed to make our own custom udev rule. The last fields - SYMLINK+ creates our persistant name - and while we are here we set the group.
ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="AJV9MKOY", SYMLINK+="ttyUSB-nut",GROUP = "nut"
#this device is refered to by /etc/nut/ups.conf
We save it in /etc/udev/rules.d/52_nut-serialups.rules ( or something similar in name - the number matters - controls the order they are run ).  A gentel nudge to reload may be needed..
$ udevadm control --reload
So now we get:
$ ll /dev |grep nut
crw-rw---- 1 root nut 188, 0 2017-05-18 21:38 ttyUSB0
lrwxrwxrwx 1 root root 7 2017-05-18 21:04 ttyUSB-nut -> ttyUSB0
Correct group and a persistant symlink.

Top Page wiki Index

Email

(C) Copyright 1994-2019
All trademarks are the property of their respective owners.