USB & UDEV¶
USB¶
- List usb devices:
lshw
,lsusb # -vvv
,usb-devices
. GUI:sudo usbview
. -
Get paths of a device: When you insert a device a number of paths on filesystem gets associated with it. Here is how you can find all of them.
- While running:
udevadm monitor --property
- Insert your device, and find string like
DEVNAME=/dev/bus/usb/003/006
in the output.
- While running:
-
Get extended permissions:
getfacl /dev/bus/usb/001/002
udev¶
Docs: debian.org/udev, freedesktop.org multiseat, intro.
Config file discovery rules¶
/run/udev/rules.d
: supposed to for overwriting by administrator/etc/udev/rules.d
: supposed to for overwriting by administrator/lib/udev/rules.d
: Packages install rules here.
If a file with the same name is present in more than one of these directories then 1st one wins.
Files in there are parsed in alphabetical order, as long as the name ends with .rules
.
Attributes by path¶
Once you have a device path (see above), you can:
-
Get canonical path:
udevadm info -q path -n /dev/bus/usb/001/002
will print/devices/pci0000:00/0000:00:01.2/0000:02:00.0/0000:03:08.0/0000:05:00.1/usb1/1-1
. -
Get all its attributes:
udevadm info -a -n /dev/bus/usb/001/002
orudevadm info -a -p (udevadm info -q path -n /dev/bus/usb/001/002)
-
Simulate rule execution:
udevadm test (udevadm info -q path -n /dev/bus/usb/003/006)
Example¶
Example of running a script on new flash-drive insertion.
Add the following file:
/etc/udev/rules.d/80-local.rules | |
---|---|
Reload rules: udevadm control --reload
Refining the rule into something useful:
lsusb: Bus 003 Device 005: ID 03f0:3307 TyCoon Corp.
In this example, the03f0:3307
beforeTyCoon Corp.
denotes theidVendor
andidProduct
attributes. You can also see these numbers in the output ofudevadm info -a -n /dev/sdb | grep vendor
, but I find the output of lsusb a little easier on the eyes.- You can now include these attributes in your rule:
/etc/udev/rules.d/80-local.rules
Example of removing tags uaccess and seat tags¶
/etc/udev/rules.d/99-multiseat-fixes.rules | |
---|---|
Unfortunately, it means that the file associated with the device will have root as its owner, and therefore it will not be accessible by neither of the users. Solution is to add both users to video group: