Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
fuss:udev [2017/07/05 20:07]
office
fuss:udev [2019/03/08 22:40] (current)
office [Reloading Udev Rules]
Line 1: Line 1:
 +====== Creating Specific Rules for Devices ======
 +
 +Usually, rules are placed in files under the ''/​etc/​udev/​rules.d''​ directory where each rule performs some action depending on some user-specified criteria that matches a connected devices. For instance, a modem may be connected to a computer and the kernel will assign via udev a device node under ''/​dev/''​ - however, in most cases, the actual name is chosen by the kernel (conventionally incrementally,​ depending on the number of already connected devices). Unfortunately,​ one cannot know beforehand if, following the example, a modem device will be assigned to ''/​dev/​ttyACM0''​ or ''/​dev/​ttyACM1'',​ etc...
 +
 +To make sure that a device gets the same node under devfs via udev, rules can be added under ''/​etc/​udev/​rules.d''​ and those rules can match hardware criteria such as vendor ID, revision, etc... The first step is to issue the command:
 +<code bash>
 +udevadm info -q all -n /​dev/​ttyACM0 --attribute-walk
 +</​code>​
 +
 +where:
 +  * ''/​dev/​ttyACM0''​ is the connected device you want to query for hardware details.
 +
 +The command will output attributes, such as ''​ATTRS{idProduct}'',​ ''​ATTRS{idVendor}'',​ etc... Information that can then be used to construct an udev rule.
 +
 +For instance, to match and USB device with an ''​idProduct''​ attribute of ''​0723''​ and an ''​idVendor''​ of ''​05e3'',​ one could create a file at ''/​etc/​udev.d/​rules/​80-mydevice.rules''​ containing:
 +<​code>​
 +SUBSYSTEM=="​usb",​ATTRS{idProduct}=="​0723",​ATTRS{idVendor}=="​05e3",​SYMLINK+="​mydevice",​RUN+="​echo boo >/​dev/​null"​
 +</​code>​
 +which will:
 +  * match a device connected through the USB subsystem,
 +  * that has an ''​idProduct''​ of ''​0723'',​
 +  * and an ''​idVendor''​ of ''​05e3'',​
 +  * as well as creating a convenient symlink in ''/​dev/''​ as ''/​dev/​mydevice'',​
 +  * and additionally execute the command ''​echo boo >/​dev/​null''​
 +
 +
 +====== Reloading Udev Rules ======
 +
 +Remember that issuing:
 +<code bash>
 +udevadm control --reload-rules
 +</​code>​
 +
 +is insufficient and that you have to issue:
 +<code bash>
 +systemctl restart udev.service
 +</​code>​
 +
 +to make the rules effective.
 +
 +====== Trigger Action for Particular Set of Rules ======
 +
 +To trigger the ''​net''​ subsystem rules that bind to the ''​add''​ action, issue:
 +<code bash>
 +udevadm trigger --attr-match=subsystem=net --action="​add"​
 +</​code>​
 +
  

fuss/udev.txt ยท Last modified: 2019/03/08 22:40 by office

Access website using Tor Access website using i2p


For the copyright, license, warranty and privacy terms for the usage of this website please see the license, privacy and plagiarism pages.