chiark / gitweb /
Docs: udev.xml: Add missing `.'
[elogind.git] / udev / 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>/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       default rules directory <filename>/lib/udev/rules.d/</filename>,
75       the custom rules directory <filename>/etc/udev/rules.d/</filename>
76       and the temporary rules directory <filename>/run/udev/rules.d/</filename>.
77       All rule files are collectively sorted and processed in lexical order,
78       regardless of the directories in which they live. However, files in
79       <filename>/etc/udev/rules.d/</filename> take precedence over files with
80       the same name in <filename>/lib/udev/rules.d/</filename>; this can be
81       used to ignore a default rules file if needed.</para>
82
83       <para>Rule files must have the extension <filename>.rules</filename>; other
84       extensions are ignored.</para>
85
86       <para>Every line in the rules file contains at least one key-value pair.
87       There are two kind of keys: match and assignment.
88       If all match keys are matching against its value, the rule gets applied and the
89       assignment keys get the specified value assigned.</para>
90
91       <para>A matching rule may rename a network interface, add symlinks
92       pointing to the device node, or run a specified program as part of
93       the event handling.</para>
94
95       <para>A rule consists of a comma-separated list of one or more key-value pairs.
96       Each key has a distinct operation, depending on the used operator. Valid
97       operators are:</para>
98       <variablelist>
99         <varlistentry>
100           <term><option>==</option></term>
101           <listitem>
102             <para>Compare for equality.</para>
103           </listitem>
104         </varlistentry>
105
106         <varlistentry>
107           <term><option>!=</option></term>
108           <listitem>
109             <para>Compare for inequality.</para>
110           </listitem>
111         </varlistentry>
112
113         <varlistentry>
114           <term><option>=</option></term>
115           <listitem>
116             <para>Assign a value to a key. Keys that represent a list are reset
117             and only this single value is assigned.</para>
118           </listitem>
119         </varlistentry>
120
121         <varlistentry>
122           <term><option>+=</option></term>
123           <listitem>
124             <para>Add the value to a key that holds a list of entries.</para>
125           </listitem>
126         </varlistentry>
127
128         <varlistentry>
129           <term><option>:=</option></term>
130           <listitem>
131             <para>Assign  a  value  to  a key finally; disallow any later changes.</para>
132           </listitem>
133         </varlistentry>
134       </variablelist>
135
136       <para>The following key names can be used to match against device properties.
137       Some of the keys also match against properties of the parent devices in sysfs,
138       not only the device that has generated the event. If multiple keys that match
139       a parent device are specified in a single rule, all these keys must match at
140       one and the same parent device.</para>
141       <variablelist>
142         <varlistentry>
143           <term><option>ACTION</option></term>
144           <listitem>
145             <para>Match the name of the event action.</para>
146           </listitem>
147         </varlistentry>
148
149         <varlistentry>
150           <term><option>DEVPATH</option></term>
151           <listitem>
152             <para>Match the devpath of the event device.</para>
153           </listitem>
154         </varlistentry>
155
156         <varlistentry>
157           <term><option>KERNEL</option></term>
158           <listitem>
159             <para>Match the name of the event device.</para>
160           </listitem>
161         </varlistentry>
162
163         <varlistentry>
164           <term><option>NAME</option></term>
165           <listitem>
166             <para>Match the name of the node or network interface. It can
167             be used once the NAME key has been set in one of the preceding
168             rules.</para>
169           </listitem>
170         </varlistentry>
171
172         <varlistentry>
173           <term><option>SYMLINK</option></term>
174           <listitem>
175             <para>Match the name of a symlink targeting the node. It can
176             be used once a SYMLINK key has been set in one of the preceding
177             rules. There may be multiple symlinks; only one needs to match.
178             </para>
179           </listitem>
180         </varlistentry>
181
182         <varlistentry>
183           <term><option>SUBSYSTEM</option></term>
184           <listitem>
185             <para>Match the subsystem of the event device.</para>
186           </listitem>
187         </varlistentry>
188         <varlistentry>
189           <term><option>DRIVER</option></term>
190           <listitem>
191             <para>Match the driver name of the event device. Only set this key for devices
192             which are bound to a driver at the time the event is generated.</para>
193           </listitem>
194         </varlistentry>
195         <varlistentry>
196           <term><option>ATTR{<replaceable>filename</replaceable>}</option></term>
197           <listitem>
198             <para>Match sysfs attribute values of the event device. Trailing
199             whitespace in the attribute values is ignored unless the specified match
200             value itself contains trailing whitespace.
201             </para>
202           </listitem>
203         </varlistentry>
204
205         <varlistentry>
206           <term><option>KERNELS</option></term>
207           <listitem>
208             <para>Search the devpath upwards for a matching device name.</para>
209           </listitem>
210         </varlistentry>
211
212         <varlistentry>
213           <term><option>SUBSYSTEMS</option></term>
214           <listitem>
215             <para>Search the devpath upwards for a matching device subsystem name.</para>
216           </listitem>
217         </varlistentry>
218
219         <varlistentry>
220           <term><option>DRIVERS</option></term>
221           <listitem>
222             <para>Search the devpath upwards for a matching device driver name.</para>
223           </listitem>
224         </varlistentry>
225
226         <varlistentry>
227           <term><option>ATTRS{<replaceable>filename</replaceable>}</option></term>
228           <listitem>
229             <para>Search the devpath upwards for a device with matching sysfs attribute values.
230             If multiple <option>ATTRS</option> matches are specified, all of them
231             must match on the same device. Trailing whitespace in the attribute values is ignored
232             unless the specified match value itself contains trailing whitespace.</para>
233           </listitem>
234         </varlistentry>
235
236         <varlistentry>
237           <term><option>ENV{<replaceable>key</replaceable>}</option></term>
238           <listitem>
239             <para>Match against a device property value.</para>
240           </listitem>
241         </varlistentry>
242
243         <varlistentry>
244           <term><option>TAG</option></term>
245           <listitem>
246             <para>Match against a device tag.</para>
247           </listitem>
248         </varlistentry>
249
250         <varlistentry>
251           <term><option>TEST{<replaceable>octal mode mask</replaceable>}</option></term>
252           <listitem>
253             <para>Test the existence of a file. An octal mode mask can be specified
254             if needed.</para>
255           </listitem>
256         </varlistentry>
257
258         <varlistentry>
259           <term><option>PROGRAM</option></term>
260           <listitem>
261             <para>Execute a program to determine whether there
262             is a match; the key is true if the program returns
263             successfully. The device properties are made available to the
264             executed program in the environment. The program's stdout
265             is available in the RESULT key.</para>
266           </listitem>
267         </varlistentry>
268
269         <varlistentry>
270           <term><option>RESULT</option></term>
271           <listitem>
272             <para>Match the returned string of the last PROGRAM call. This key can
273             be used in the same or in any later rule after a PROGRAM call.</para>
274           </listitem>
275         </varlistentry>
276       </variablelist>
277
278       <para>Most of the fields support shell-style pattern matching. The following
279       pattern characters are supported:</para>
280       <variablelist>
281         <varlistentry>
282           <term><option>*</option></term>
283           <listitem>
284             <para>Matches zero or more characters.</para>
285           </listitem>
286         </varlistentry>
287         <varlistentry>
288           <term><option>?</option></term>
289           <listitem>
290             <para>Matches any single character.</para>
291           </listitem>
292         </varlistentry>
293         <varlistentry>
294           <term><option>[]</option></term>
295           <listitem>
296             <para>Matches any single character specified within the brackets. For
297             example, the pattern string 'tty[SR]' would match either 'ttyS' or 'ttyR'.
298             Ranges are also supported via the '-' character.
299             For example, to match on the range of all digits, the pattern [0-9] could
300             be used. If the first character following the '[' is a '!', any characters
301             not enclosed are matched.</para>
302           </listitem>
303         </varlistentry>
304       </variablelist>
305
306       <para>The following keys can get values assigned:</para>
307       <variablelist>
308         <varlistentry>
309           <term><option>NAME</option></term>
310           <listitem>
311             <para>What a network interface should be named.</para>
312             <para>Also, as a temporary workaround, this is what a device node
313             should be named; usually the kernel provides the defined node name or creates
314             and removes the node before udev even receives any event. Changing
315             the node name from the kernel's default creates inconsistencies
316             and is not supported. If the kernel and NAME specify different names,
317             an error is logged. udev is only expected to handle device node
318             permissions and to create additional symlinks, not to change
319             kernel-provided device node names. Instead of renaming a device node,
320             SYMLINK should be used. However, symlink names must never conflict with
321             device node names, as that would result in unpredictable behavior.</para>
322           </listitem>
323         </varlistentry>
324
325         <varlistentry>
326           <term><option>SYMLINK</option></term>
327           <listitem>
328             <para>The name of a symlink targeting the node. Every matching rule adds
329             this value to the list of symlinks to be created. Multiple symlinks may be
330             specified by separating the names by the space character. In case multiple
331             devices claim the same name, the link always points to the device with
332             the highest link_priority. If the current device goes away, the links are
333             re-evaluated and the device with the next highest link_priority becomes the owner of
334             the link. If no link_priority is specified, the order of the devices (and
335             which one of them owns the link) is undefined. Also, symlink names must
336             never conflict with the kernel's default device node names, as that would
337             result in unpredictable behavior.
338             </para>
339           </listitem>
340         </varlistentry>
341
342         <varlistentry>
343           <term><option>OWNER, GROUP, MODE</option></term>
344           <listitem>
345             <para>The permissions for the device node. Every specified value overwrites
346             the compiled-in default value.</para>
347           </listitem>
348         </varlistentry>
349
350         <varlistentry>
351           <term><option>ATTR{<replaceable>key</replaceable>}</option></term>
352           <listitem>
353             <para>The value that should be written to a sysfs attribute of the
354             event device.</para>
355           </listitem>
356         </varlistentry>
357
358         <varlistentry>
359           <term><option>ENV{<replaceable>key</replaceable>}</option></term>
360           <listitem>
361             <para>Set a device property value. Property names with a leading '.'
362             are neither stored in the database nor exported to events or
363             external tools (run by, say, the PROGRAM match key).</para>
364           </listitem>
365         </varlistentry>
366
367         <varlistentry>
368           <term><option>TAG</option></term>
369           <listitem>
370             <para>Attach a tag to a device. This is used to filter events for users
371             of libudev's monitor functionality, or to enumerate a group of tagged
372             devices. The implementation can only work efficiently if only a few
373             tags are attached to a device. It is only meant to be used in
374             contexts with specific device filter requirements, and not as a
375             general-purpose flag. Excessive use might result in inefficient event
376             handling.</para>
377           </listitem>
378         </varlistentry>
379
380         <varlistentry>
381           <term><option>RUN</option></term>
382           <listitem>
383             <para>Add a program to the list of programs to be executed for a specific
384             device. This can only be used for very short running tasks. Running an
385             event process for a long period of time may block all further events for
386             this or a dependent device. Long running tasks need to be immediately
387             detached from the event process itself.</para>
388             <para>If no absolute path is given, the program is expected to live in
389             the directory provided at compile-time to configure via --libexecdir
390             (this is usually <filename>/lib/udev</filename>), otherwise the absolute
391             path must be specified. The program name and following arguments are
392             separated by spaces. Single quotes can be used to specify arguments with
393             spaces.</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, which must be in
430                   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 commandline. 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             <para>If no option is given, udev chooses between <option>program</option>
460             and <option>file</option> based on the executable bit of the file
461             permissions.</para>
462           </listitem>
463         </varlistentry>
464
465         <varlistentry>
466           <term><option>WAIT_FOR</option></term>
467           <listitem>
468             <para>Wait for a file to become available or until a 10
469             seconds timeout expires. The path is relative to the sysfs device,
470             i. e. if no path is specified this waits for an attribute to appear.</para>
471           </listitem>
472         </varlistentry>
473
474         <varlistentry>
475           <term><option>OPTIONS</option></term>
476           <listitem>
477             <para>Rule and device options:</para>
478             <variablelist>
479               <varlistentry>
480                 <term><option>link_priority=<replaceable>value</replaceable></option></term>
481                 <listitem>
482                   <para>Specify the priority of the created symlinks. Devices with higher
483                   priorities overwrite existing symlinks of other devices. The default is 0.</para>
484                 </listitem>
485               </varlistentry>
486               <varlistentry>
487                 <term><option>event_timeout=</option></term>
488                 <listitem>
489                   <para>Number of seconds an event waits for operations to finish before
490                   giving up and terminating itself.</para>
491                 </listitem>
492               </varlistentry>
493               <varlistentry>
494                 <term><option>string_escape=<replaceable>none|replace</replaceable></option></term>
495                 <listitem>
496                   <para>Usually control and other possibly unsafe characters are replaced
497                   in strings used for device naming. The mode of replacement can be specified
498                   with this option.</para>
499                 </listitem>
500               </varlistentry>
501               <varlistentry>
502                 <term><option>static_node=</option></term>
503                 <listitem>
504                   <para>Apply the permissions specified in this rule to a static device node with
505                   the specified name. Static device nodes might be provided by kernel modules
506                   or copied from <filename>/lib/udev/devices</filename>. These nodes might not have
507                   a corresponding kernel device at the time udevd is started; they can trigger
508                   automatic kernel module loading.</para>
509                 </listitem>
510               </varlistentry>
511               <varlistentry>
512                 <term><option>watch</option></term>
513                 <listitem>
514                   <para>Watch the device node with inotify; when closed after being opened for
515                   writing, a change uevent is synthesised.</para>
516                 </listitem>
517               </varlistentry>
518               <varlistentry>
519                 <term><option>nowatch</option></term>
520                 <listitem>
521                   <para>Disable the watching of a device node with inotify.</para>
522                 </listitem>
523               </varlistentry>
524             </variablelist>
525           </listitem>
526         </varlistentry>
527       </variablelist>
528
529       <para>The <option>NAME</option>, <option>SYMLINK</option>, <option>PROGRAM</option>,
530       <option>OWNER</option>, <option>GROUP</option>, <option>MODE</option>  and  <option>RUN</option>
531       fields support simple printf-like string substitutions. The <option>RUN</option>
532       format chars gets applied after all rules have been processed, right before the program
533       is executed. It allows the use of device properties set by earlier matching
534       rules. For all other fields, substitutions are applied while the individual rule is
535       being processed. The available substitutions are:</para>
536       <variablelist>
537         <varlistentry>
538           <term><option>$kernel</option>, <option>%k</option></term>
539           <listitem>
540             <para>The kernel name for this device.</para>
541           </listitem>
542         </varlistentry>
543
544         <varlistentry>
545           <term><option>$number</option>, <option>%n</option></term>
546           <listitem>
547             <para>The kernel number for this device. For example, 'sda3' has
548             kernel number of '3'</para>
549           </listitem>
550         </varlistentry>
551
552         <varlistentry>
553           <term><option>$devpath</option>, <option>%p</option></term>
554           <listitem>
555             <para>The devpath of the device.</para>
556           </listitem>
557         </varlistentry>
558
559         <varlistentry>
560           <term><option>$id</option>, <option>%b</option></term>
561           <listitem>
562             <para>The name of the device matched while searching the devpath upwards for
563               <option>SUBSYSTEMS</option>, <option>KERNELS</option>, <option>DRIVERS</option> and <option>ATTRS</option>.
564             </para>
565           </listitem>
566         </varlistentry>
567
568         <varlistentry>
569           <term><option>$driver</option></term>
570           <listitem>
571             <para>The driver name of the device matched while searching the devpath upwards for
572               <option>SUBSYSTEMS</option>, <option>KERNELS</option>, <option>DRIVERS</option> and <option>ATTRS</option>.
573             </para>
574           </listitem>
575         </varlistentry>
576
577         <varlistentry>
578           <term><option>$attr{<replaceable>file</replaceable>}</option>, <option>%s{<replaceable>file</replaceable>}</option></term>
579           <listitem>
580             <para>The value of a sysfs attribute found at the device where
581             all keys of the rule have matched. If the matching device does not have
582             such an attribute, and a previous KERNELS, SUBSYSTEMS, DRIVERS, or
583             ATTRS test selected a parent device, use the attribute from that
584             parent device.
585             If the attribute is a symlink, the last element of the symlink target is
586             returned as the value.</para>
587           </listitem>
588         </varlistentry>
589
590         <varlistentry>
591           <term><option>$env{<replaceable>key</replaceable>}</option>, <option>%E{<replaceable>key</replaceable>}</option></term>
592           <listitem>
593             <para>A device property value.</para>
594           </listitem>
595         </varlistentry>
596
597         <varlistentry>
598           <term><option>$major</option>, <option>%M</option></term>
599           <listitem>
600             <para>The kernel major number for the device.</para>
601           </listitem>
602         </varlistentry>
603
604         <varlistentry>
605           <term><option>$minor</option>, <option>%m</option></term>
606           <listitem>
607             <para>The kernel minor number for the device.</para>
608           </listitem>
609         </varlistentry>
610
611         <varlistentry>
612           <term><option>$result</option>, <option>%c</option></term>
613           <listitem>
614             <para>The string returned by the external program requested with PROGRAM.
615             A single part of the string, separated by a space character may be selected
616             by specifying the part number as an attribute: <option>%c{N}</option>.
617             If the number is followed by the '+' char this part plus all remaining parts
618             of the result string are substituted: <option>%c{N+}</option></para>
619           </listitem>
620         </varlistentry>
621
622         <varlistentry>
623           <term><option>$parent</option>, <option>%P</option></term>
624           <listitem>
625             <para>The node name of the parent device.</para>
626           </listitem>
627         </varlistentry>
628
629         <varlistentry>
630           <term><option>$name</option></term>
631           <listitem>
632             <para>The current name of the device node. If not changed by a rule, it is the
633             name of the kernel device.</para>
634           </listitem>
635         </varlistentry>
636
637         <varlistentry>
638           <term><option>$links</option></term>
639           <listitem>
640             <para>The current list of symlinks, separated by a space character. The value is
641             only set if an earlier rule assigned a value, or during a remove events.</para>
642           </listitem>
643         </varlistentry>
644
645         <varlistentry>
646           <term><option>$root</option>, <option>%r</option></term>
647           <listitem>
648             <para>The udev_root value.</para>
649           </listitem>
650         </varlistentry>
651
652         <varlistentry>
653           <term><option>$sys</option>, <option>%S</option></term>
654           <listitem>
655             <para>The sysfs mount point.</para>
656           </listitem>
657         </varlistentry>
658
659         <varlistentry>
660           <term><option>$tempnode</option>, <option>%N</option></term>
661           <listitem>
662             <para>The name of a created temporary device node to provide access to
663             the device from a external program before the real node is created.</para>
664           </listitem>
665         </varlistentry>
666
667         <varlistentry>
668           <term><option>%%</option></term>
669           <listitem>
670           <para>The '%' character itself.</para>
671           </listitem>
672         </varlistentry>
673
674         <varlistentry>
675           <term><option>$$</option></term>
676           <listitem>
677           <para>The '$' character itself.</para>
678           </listitem>
679         </varlistentry>
680       </variablelist>
681     </refsect2>
682   </refsect1>
683
684   <refsect1><title>Author</title>
685     <para>Written by Greg Kroah-Hartman <email>greg@kroah.com</email> and
686     Kay Sievers <email>kay.sievers@vrfy.org</email>. With much help from
687     Dan Stekloff and many others.</para>
688   </refsect1>
689
690   <refsect1>
691     <title>See Also</title>
692     <para><citerefentry>
693         <refentrytitle>udevd</refentrytitle><manvolnum>8</manvolnum>
694       </citerefentry>, 
695       <citerefentry>
696         <refentrytitle>udevadm</refentrytitle><manvolnum>8</manvolnum>
697     </citerefentry></para>
698   </refsect1>
699 </refentry>