chiark / gitweb /
udev: fix rules sort order
[elogind.git] / man / udev.xml
1 <?xml version='1.0'?>
2 <?xml-stylesheet type="text/xsl" href="http://docbook.sourceforge.net/release/xsl/current/xhtml/docbook.xsl"?>
3 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
4   "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
5
6 <refentry id="udev">
7   <refentryinfo>
8     <title>udev</title>
9     <productname>systemd</productname>
10     <authorgroup>
11       <author>
12         <contrib>Developer</contrib>
13         <firstname>Greg</firstname>
14         <surname>Kroah-Hartmann</surname>
15         <email>greg@kroah.com</email>
16       </author>
17       <author>
18         <contrib>Developer</contrib>
19         <firstname>Kay</firstname>
20         <surname>Sievers</surname>
21         <email>kay@vrfy.org</email>
22       </author>
23     </authorgroup>
24   </refentryinfo>
25
26   <refmeta>
27     <refentrytitle>udev</refentrytitle>
28     <manvolnum>7</manvolnum>
29   </refmeta>
30
31   <refnamediv>
32     <refname>udev</refname>
33     <refpurpose>Linux dynamic device management</refpurpose>
34   </refnamediv>
35
36   <refsect1><title>Description</title>
37     <para>udev supplies the system software with device events, manages permissions
38     of device nodes and may create additional symlinks in the <filename>/dev</filename>
39     directory, or renames network interfaces. The kernel usually just assigns unpredictable
40     device names based on the order of discovery. Meaningful symlinks or network device
41     names provide a way to reliably identify devices based on their properties or
42     current configuration.</para>
43
44     <para>The udev daemon, <citerefentry><refentrytitle>udevd</refentrytitle>
45     <manvolnum>8</manvolnum></citerefentry>, receives device uevents directly from
46     the kernel whenever a device is added or removed from the system, or it changes its
47     state. When udev receives a device event, it matches its configured set of rules
48     against various device attributes to identify the device. Rules that match may
49     provide additional device information to be stored in the udev database or
50     to be used to create meaningful symlink names.</para>
51
52     <para>All device information udev processes is stored in the udev database and
53     sent out to possible event subscribers. Access to all stored data and the event
54     sources is provided by the library libudev.</para>
55   </refsect1>
56
57   <refsect1><title>Configuration</title>
58     <para>udev configuration files are placed in <filename>/etc/udev</filename>
59     and <filename>/usr/lib/udev</filename>. All empty lines or lines beginning with
60     '#' are ignored.</para>
61
62     <refsect2><title>Configuration file</title>
63       <para>udev expects its main configuration file at <filename>/etc/udev/udev.conf</filename>.
64       It consists of a set of variables allowing the user to override default udev values.
65       The following variables can be set:</para>
66       <variablelist>
67         <varlistentry>
68           <term><option>udev_root</option></term>
69           <listitem>
70             <para>Specifies where to place the device nodes in the filesystem.
71             The default value is <filename>/dev</filename>.</para>
72           </listitem>
73         </varlistentry>
74
75         <varlistentry>
76           <term><option>udev_log</option></term>
77           <listitem>
78             <para>The logging priority. Valid values are the numerical syslog priorities
79             or their textual representations: <option>err</option>, <option>info</option>
80             and <option>debug</option>.</para>
81           </listitem>
82         </varlistentry>
83       </variablelist>
84     </refsect2>
85
86     <refsect2><title>Rules files</title>
87       <para>The udev rules are read from the files located in the
88       system rules directory <filename>/usr/lib/udev/rules.d</filename>,
89       the volatile runtime directory <filename>/run/udev/rules.d</filename>
90       and the local administration directory <filename>/etc/udev/rules.d</filename>.
91       All rules files are collectively sorted and processed in lexical order,
92       regardless of the directories in which they live. However, files with
93       identical file names replace each other. Files in <filename>/etc</filename>
94       have the highest priority, files in <filename>/run</filename> take precedence
95       over files with the same name in <filename>/lib</filename>. This can be
96       used to override a system-supplied rules file with a local file if needed;
97       a symlink in <filename>/etc</filename> with the same name as a rules file in
98       <filename>/lib</filename>, pointing to <filename>/dev/null</filename>,
99       disables the rules file entirely.</para>
100
101       <para>Rule files must have the extension <filename>.rules</filename>; other
102       extensions are ignored.</para>
103
104       <para>Every line in the rules file contains at least one key-value pair.
105       There are two kind of keys: match and assignment.
106       If all match keys are matching against its value, the rule gets applied and the
107       assignment keys get the specified value assigned.</para>
108
109       <para>A matching rule may rename a network interface, add symlinks
110       pointing to the device node, or run a specified program as part of
111       the event handling.</para>
112
113       <para>A rule consists of a comma-separated list of one or more key-value pairs.
114       Each key has a distinct operation, depending on the used operator. Valid
115       operators are:</para>
116       <variablelist>
117         <varlistentry>
118           <term><option>==</option></term>
119           <listitem>
120             <para>Compare for equality.</para>
121           </listitem>
122         </varlistentry>
123
124         <varlistentry>
125           <term><option>!=</option></term>
126           <listitem>
127             <para>Compare for inequality.</para>
128           </listitem>
129         </varlistentry>
130
131         <varlistentry>
132           <term><option>=</option></term>
133           <listitem>
134             <para>Assign a value to a key. Keys that represent a list are reset
135             and only this single value is assigned.</para>
136           </listitem>
137         </varlistentry>
138
139         <varlistentry>
140           <term><option>+=</option></term>
141           <listitem>
142             <para>Add the value to a key that holds a list of entries.</para>
143           </listitem>
144         </varlistentry>
145
146         <varlistentry>
147           <term><option>:=</option></term>
148           <listitem>
149             <para>Assign  a  value  to  a key finally; disallow any later changes.</para>
150           </listitem>
151         </varlistentry>
152       </variablelist>
153
154       <para>The following key names can be used to match against device properties.
155       Some of the keys also match against properties of the parent devices in sysfs,
156       not only the device that has generated the event. If multiple keys that match
157       a parent device are specified in a single rule, all these keys must match at
158       one and the same parent device.</para>
159       <variablelist>
160         <varlistentry>
161           <term><option>ACTION</option></term>
162           <listitem>
163             <para>Match the name of the event action.</para>
164           </listitem>
165         </varlistentry>
166
167         <varlistentry>
168           <term><option>DEVPATH</option></term>
169           <listitem>
170             <para>Match the devpath of the event device.</para>
171           </listitem>
172         </varlistentry>
173
174         <varlistentry>
175           <term><option>KERNEL</option></term>
176           <listitem>
177             <para>Match the name of the event device.</para>
178           </listitem>
179         </varlistentry>
180
181         <varlistentry>
182           <term><option>NAME</option></term>
183           <listitem>
184             <para>Match the name of a network interface. It can be used once the
185             NAME key has been set in one of the preceding rules.</para>
186           </listitem>
187         </varlistentry>
188
189         <varlistentry>
190           <term><option>SYMLINK</option></term>
191           <listitem>
192             <para>Match the name of a symlink targeting the node. It can
193             be used once a SYMLINK key has been set in one of the preceding
194             rules. There may be multiple symlinks; only one needs to match.
195             </para>
196           </listitem>
197         </varlistentry>
198
199         <varlistentry>
200           <term><option>SUBSYSTEM</option></term>
201           <listitem>
202             <para>Match the subsystem of the event device.</para>
203           </listitem>
204         </varlistentry>
205         <varlistentry>
206           <term><option>DRIVER</option></term>
207           <listitem>
208             <para>Match the driver name of the event device. Only set this key for devices
209             which are bound to a driver at the time the event is generated.</para>
210           </listitem>
211         </varlistentry>
212         <varlistentry>
213           <term><option>ATTR{<replaceable>filename</replaceable>}</option></term>
214           <listitem>
215             <para>Match sysfs attribute values of the event device. Trailing
216             whitespace in the attribute values is ignored unless the specified match
217             value itself contains trailing whitespace.
218             </para>
219           </listitem>
220         </varlistentry>
221
222         <varlistentry>
223           <term><option>KERNELS</option></term>
224           <listitem>
225             <para>Search the devpath upwards for a matching device name.</para>
226           </listitem>
227         </varlistentry>
228
229         <varlistentry>
230           <term><option>SUBSYSTEMS</option></term>
231           <listitem>
232             <para>Search the devpath upwards for a matching device subsystem name.</para>
233           </listitem>
234         </varlistentry>
235
236         <varlistentry>
237           <term><option>DRIVERS</option></term>
238           <listitem>
239             <para>Search the devpath upwards for a matching device driver name.</para>
240           </listitem>
241         </varlistentry>
242
243         <varlistentry>
244           <term><option>ATTRS{<replaceable>filename</replaceable>}</option></term>
245           <listitem>
246             <para>Search the devpath upwards for a device with matching sysfs attribute values.
247             If multiple <option>ATTRS</option> matches are specified, all of them
248             must match on the same device. Trailing whitespace in the attribute values is ignored
249             unless the specified match value itself contains trailing whitespace.</para>
250           </listitem>
251         </varlistentry>
252
253         <varlistentry>
254           <term><option>TAGS</option></term>
255           <listitem>
256             <para>Search the devpath upwards for a device with matching tag.</para>
257           </listitem>
258         </varlistentry>
259
260         <varlistentry>
261           <term><option>ENV{<replaceable>key</replaceable>}</option></term>
262           <listitem>
263             <para>Match against a device property value.</para>
264           </listitem>
265         </varlistentry>
266
267         <varlistentry>
268           <term><option>TAG</option></term>
269           <listitem>
270             <para>Match against a device tag.</para>
271           </listitem>
272         </varlistentry>
273
274         <varlistentry>
275           <term><option>TEST{<replaceable>octal mode mask</replaceable>}</option></term>
276           <listitem>
277             <para>Test the existence of a file. An octal mode mask can be specified
278             if needed.</para>
279           </listitem>
280         </varlistentry>
281
282         <varlistentry>
283           <term><option>PROGRAM</option></term>
284           <listitem>
285             <para>Execute a program to determine whether there
286             is a match; the key is true if the program returns
287             successfully. The device properties are made available to the
288             executed program in the environment. The program's stdout
289             is available in the RESULT key.</para>
290           </listitem>
291         </varlistentry>
292
293         <varlistentry>
294           <term><option>RESULT</option></term>
295           <listitem>
296             <para>Match the returned string of the last PROGRAM call. This key can
297             be used in the same or in any later rule after a PROGRAM call.</para>
298           </listitem>
299         </varlistentry>
300       </variablelist>
301
302       <para>Most of the fields support shell-style pattern matching. The following
303       pattern characters are supported:</para>
304       <variablelist>
305         <varlistentry>
306           <term><option>*</option></term>
307           <listitem>
308             <para>Matches zero or more characters.</para>
309           </listitem>
310         </varlistentry>
311         <varlistentry>
312           <term><option>?</option></term>
313           <listitem>
314             <para>Matches any single character.</para>
315           </listitem>
316         </varlistentry>
317         <varlistentry>
318           <term><option>[]</option></term>
319           <listitem>
320             <para>Matches any single character specified within the brackets. For
321             example, the pattern string 'tty[SR]' would match either 'ttyS' or 'ttyR'.
322             Ranges are also supported via the '-' character.
323             For example, to match on the range of all digits, the pattern [0-9] could
324             be used. If the first character following the '[' is a '!', any characters
325             not enclosed are matched.</para>
326           </listitem>
327         </varlistentry>
328       </variablelist>
329
330       <para>The following keys can get values assigned:</para>
331       <variablelist>
332         <varlistentry>
333           <term><option>NAME</option></term>
334           <listitem>
335             <para>The name to use for a network interface. The name of a device node
336             can not be changed by udev, only additional symlinks can be created.</para>
337           </listitem>
338         </varlistentry>
339
340         <varlistentry>
341           <term><option>SYMLINK</option></term>
342           <listitem>
343             <para>The name of a symlink targeting the node. Every matching rule adds
344             this value to the list of symlinks to be created. Multiple symlinks may be
345             specified by separating the names by the space character. In case multiple
346             devices claim the same name, the link always points to the device with
347             the highest link_priority. If the current device goes away, the links are
348             re-evaluated and the device with the next highest link_priority becomes the owner of
349             the link. If no link_priority is specified, the order of the devices (and
350             which one of them owns the link) is undefined. Also, symlink names must
351             never conflict with the kernel's default device node names, as that would
352             result in unpredictable behavior.
353             </para>
354           </listitem>
355         </varlistentry>
356
357         <varlistentry>
358           <term><option>OWNER, GROUP, MODE</option></term>
359           <listitem>
360             <para>The permissions for the device node. Every specified value overrides
361             the compiled-in default value.</para>
362           </listitem>
363         </varlistentry>
364
365         <varlistentry>
366           <term><option>ATTR{<replaceable>key</replaceable>}</option></term>
367           <listitem>
368             <para>The value that should be written to a sysfs attribute of the
369             event device.</para>
370           </listitem>
371         </varlistentry>
372
373         <varlistentry>
374           <term><option>ENV{<replaceable>key</replaceable>}</option></term>
375           <listitem>
376             <para>Set a device property value. Property names with a leading '.'
377             are neither stored in the database nor exported to events or
378             external tools (run by, say, the PROGRAM match key).</para>
379           </listitem>
380         </varlistentry>
381
382         <varlistentry>
383           <term><option>TAG</option></term>
384           <listitem>
385             <para>Attach a tag to a device. This is used to filter events for users
386             of libudev's monitor functionality, or to enumerate a group of tagged
387             devices. The implementation can only work efficiently if only a few
388             tags are attached to a device. It is only meant to be used in
389             contexts with specific device filter requirements, and not as a
390             general-purpose flag. Excessive use might result in inefficient event
391             handling.</para>
392           </listitem>
393         </varlistentry>
394
395         <varlistentry>
396           <term><option>RUN</option></term>
397           <listitem>
398             <para>Add a program to the list of programs to be executed for a specific
399             device.</para>
400             <para>If no absolute path is given, the program is expected to live in
401             /usr/lib/udev, otherwise the absolute path must be specified. The program
402             name and following arguments are separated by spaces. Single quotes can
403             be used to specify arguments with spaces.</para>
404             <para>This can only be used for very short running tasks. Running an
405             event process for a long period of time may block all further events for
406             this or a dependent device. Starting daemons or other long running processes
407             is not appropriate for udev.</para>
408           </listitem>
409         </varlistentry>
410
411         <varlistentry>
412           <term><option>LABEL</option></term>
413           <listitem>
414             <para>A named label to which a GOTO may jump.</para>
415           </listitem>
416         </varlistentry>
417
418         <varlistentry>
419           <term><option>GOTO</option></term>
420           <listitem>
421             <para>Jumps to the next LABEL with a matching name.</para>
422           </listitem>
423         </varlistentry>
424
425         <varlistentry>
426           <term><option>IMPORT{<replaceable>type</replaceable>}</option></term>
427           <listitem>
428             <para>Import a set of variables as device properties,
429             depending on <replaceable>type</replaceable>:</para>
430             <variablelist>
431               <varlistentry>
432                 <term><option>program</option></term>
433                 <listitem>
434                   <para>Execute an external program specified as the assigned value and
435                   import its output, which must be in environment key
436                   format. Path specification, command/argument separation,
437                   and quoting work like in <option>RUN</option>.</para>
438                 </listitem>
439               </varlistentry>
440               <varlistentry>
441                 <term><option>file</option></term>
442                 <listitem>
443                   <para>Import a text file specified as the assigned value, the content
444                   of which must be in environment key format.</para>
445                 </listitem>
446               </varlistentry>
447               <varlistentry>
448                 <term><option>db</option></term>
449                 <listitem>
450                   <para>Import a single property specified as the assigned value from the
451                   current device database. This works only if the database is already populated
452                   by an earlier event.</para>
453                 </listitem>
454               </varlistentry>
455               <varlistentry>
456                 <term><option>cmdline</option></term>
457                 <listitem>
458                   <para>Import a single property from the kernel command line. For simple flags
459                   the value of the property is set to '1'.</para>
460                 </listitem>
461               </varlistentry>
462               <varlistentry>
463                 <term><option>parent</option></term>
464                 <listitem>
465                   <para>Import the stored keys from the parent device by reading
466                   the database entry of the parent device. The value assigned to
467                   <option>IMPORT{parent}</option> is used as a filter of key names
468                   to import (with the same shell-style pattern matching used for
469                   comparisons).</para>
470                 </listitem>
471               </varlistentry>
472             </variablelist>
473           </listitem>
474         </varlistentry>
475
476         <varlistentry>
477           <term><option>WAIT_FOR</option></term>
478           <listitem>
479             <para>Wait for a file to become available or until a timeout of
480             10 seconds expires. The path is relative to the sysfs device;
481             if no path is specified, this waits for an attribute to appear.</para>
482           </listitem>
483         </varlistentry>
484
485         <varlistentry>
486           <term><option>OPTIONS</option></term>
487           <listitem>
488             <para>Rule and device options:</para>
489             <variablelist>
490               <varlistentry>
491                 <term><option>link_priority=<replaceable>value</replaceable></option></term>
492                 <listitem>
493                   <para>Specify the priority of the created symlinks. Devices with higher
494                   priorities overwrite existing symlinks of other devices. The default is 0.</para>
495                 </listitem>
496               </varlistentry>
497               <varlistentry>
498                 <term><option>event_timeout=</option></term>
499                 <listitem>
500                   <para>Number of seconds an event waits for operations to finish before
501                   giving up and terminating itself.</para>
502                 </listitem>
503               </varlistentry>
504               <varlistentry>
505                 <term><option>string_escape=<replaceable>none|replace</replaceable></option></term>
506                 <listitem>
507                   <para>Usually control and other possibly unsafe characters are replaced
508                   in strings used for device naming. The mode of replacement can be specified
509                   with this option.</para>
510                 </listitem>
511               </varlistentry>
512               <varlistentry>
513                 <term><option>static_node=</option></term>
514                 <listitem>
515                   <para>Apply the permissions specified in this rule to the static device node with
516                   the specified name. Static device nodes might be provided by kernel modules
517                   or copied from <filename>/usr/lib/udev/devices</filename>. These nodes might not have
518                   a corresponding kernel device at the time udevd is started; they can trigger
519                   automatic kernel module loading.</para>
520                 </listitem>
521               </varlistentry>
522               <varlistentry>
523                 <term><option>watch</option></term>
524                 <listitem>
525                   <para>Watch the device node with inotify; when the node is closed after being opened for
526                   writing, a change uevent is synthesized.</para>
527                 </listitem>
528               </varlistentry>
529               <varlistentry>
530                 <term><option>nowatch</option></term>
531                 <listitem>
532                   <para>Disable the watching of a device node with inotify.</para>
533                 </listitem>
534               </varlistentry>
535             </variablelist>
536           </listitem>
537         </varlistentry>
538       </variablelist>
539
540       <para>The <option>NAME</option>, <option>SYMLINK</option>, <option>PROGRAM</option>,
541       <option>OWNER</option>, <option>GROUP</option>, <option>MODE</option>  and  <option>RUN</option>
542       fields support simple string substitutions. The <option>RUN</option>
543       substitutions are performed after all rules have been processed, right before the program
544       is executed, allowing for the use of device properties set by earlier matching
545       rules. For all other fields, substitutions are performed while the individual rule is
546       being processed. The available substitutions are:</para>
547       <variablelist>
548         <varlistentry>
549           <term><option>$kernel</option>, <option>%k</option></term>
550           <listitem>
551             <para>The kernel name for this device.</para>
552           </listitem>
553         </varlistentry>
554
555         <varlistentry>
556           <term><option>$number</option>, <option>%n</option></term>
557           <listitem>
558             <para>The kernel number for this device. For example, 'sda3' has
559             kernel number of '3'</para>
560           </listitem>
561         </varlistentry>
562
563         <varlistentry>
564           <term><option>$devpath</option>, <option>%p</option></term>
565           <listitem>
566             <para>The devpath of the device.</para>
567           </listitem>
568         </varlistentry>
569
570         <varlistentry>
571           <term><option>$id</option>, <option>%b</option></term>
572           <listitem>
573             <para>The name of the device matched while searching the devpath upwards for
574               <option>SUBSYSTEMS</option>, <option>KERNELS</option>, <option>DRIVERS</option> and <option>ATTRS</option>.
575             </para>
576           </listitem>
577         </varlistentry>
578
579         <varlistentry>
580           <term><option>$driver</option></term>
581           <listitem>
582             <para>The driver name of the device matched while searching the devpath upwards for
583               <option>SUBSYSTEMS</option>, <option>KERNELS</option>, <option>DRIVERS</option> and <option>ATTRS</option>.
584             </para>
585           </listitem>
586         </varlistentry>
587
588         <varlistentry>
589           <term><option>$attr{<replaceable>file</replaceable>}</option>, <option>%s{<replaceable>file</replaceable>}</option></term>
590           <listitem>
591             <para>The value of a sysfs attribute found at the device where
592             all keys of the rule have matched. If the matching device does not have
593             such an attribute, and a previous KERNELS, SUBSYSTEMS, DRIVERS, or
594             ATTRS test selected a parent device, then the attribute from that
595             parent device is used.</para>
596             <para>If the attribute is a symlink, the last element of the symlink target is
597             returned as the value.</para>
598           </listitem>
599         </varlistentry>
600
601         <varlistentry>
602           <term><option>$env{<replaceable>key</replaceable>}</option>, <option>%E{<replaceable>key</replaceable>}</option></term>
603           <listitem>
604             <para>A device property value.</para>
605           </listitem>
606         </varlistentry>
607
608         <varlistentry>
609           <term><option>$major</option>, <option>%M</option></term>
610           <listitem>
611             <para>The kernel major number for the device.</para>
612           </listitem>
613         </varlistentry>
614
615         <varlistentry>
616           <term><option>$minor</option>, <option>%m</option></term>
617           <listitem>
618             <para>The kernel minor number for the device.</para>
619           </listitem>
620         </varlistentry>
621
622         <varlistentry>
623           <term><option>$result</option>, <option>%c</option></term>
624           <listitem>
625             <para>The string returned by the external program requested with PROGRAM.
626             A single part of the string, separated by a space character, may be selected
627             by specifying the part number as an attribute: <option>%c{N}</option>.
628             If the number is followed by the '+' character, this part plus all remaining parts
629             of the result string are substituted: <option>%c{N+}</option></para>
630           </listitem>
631         </varlistentry>
632
633         <varlistentry>
634           <term><option>$parent</option>, <option>%P</option></term>
635           <listitem>
636             <para>The node name of the parent device.</para>
637           </listitem>
638         </varlistentry>
639
640         <varlistentry>
641           <term><option>$name</option></term>
642           <listitem>
643             <para>The current name of the device. If not changed by a rule, it is the
644             name of the kernel device.</para>
645           </listitem>
646         </varlistentry>
647
648         <varlistentry>
649           <term><option>$links</option></term>
650           <listitem>
651             <para>A space-separated list of the current symlinks. The value is
652             only set during a remove event or if an earlier rule assigned a value.</para>
653           </listitem>
654         </varlistentry>
655
656         <varlistentry>
657           <term><option>$root</option>, <option>%r</option></term>
658           <listitem>
659             <para>The udev_root value.</para>
660           </listitem>
661         </varlistentry>
662
663         <varlistentry>
664           <term><option>$sys</option>, <option>%S</option></term>
665           <listitem>
666             <para>The sysfs mount point.</para>
667           </listitem>
668         </varlistentry>
669
670         <varlistentry>
671           <term><option>$devnode</option>, <option>%N</option></term>
672           <listitem>
673             <para>The name of the device node.</para>
674           </listitem>
675         </varlistentry>
676
677         <varlistentry>
678           <term><option>%%</option></term>
679           <listitem>
680           <para>The '%' character itself.</para>
681           </listitem>
682         </varlistentry>
683
684         <varlistentry>
685           <term><option>$$</option></term>
686           <listitem>
687           <para>The '$' character itself.</para>
688           </listitem>
689         </varlistentry>
690       </variablelist>
691     </refsect2>
692   </refsect1>
693
694   <refsect1>
695     <title>See Also</title>
696     <para><citerefentry>
697         <refentrytitle>udevd</refentrytitle><manvolnum>8</manvolnum>
698       </citerefentry>,
699       <citerefentry>
700         <refentrytitle>udevadm</refentrytitle><manvolnum>8</manvolnum>
701     </citerefentry></para>
702   </refsect1>
703 </refentry>