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