chiark / gitweb /
version bump
[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 information
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 are 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     '#' will be 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>/dev/.udev/rules.d/</filename>.
77       All rule files are sorted and processed in lexical order, regardless
78       in which of these directories they live.</para>
79
80       <para>Rule files are required to have a unique name, duplicate file names
81       are ignored. Files in <filename>/etc/udev/rules.d/</filename> have precedence
82       over files with the same name in <filename>/lib/udev/rules.d/</filename>. This
83       can be used to ignore a default rules file if needed.</para>
84
85       <para>Every line in the rules file contains at least one key value pair.
86       There are two kind of keys, match and assignment keys.
87       If all match keys are matching against its value, the rule gets applied and the
88       assign keys get the specified value assigned.</para>
89
90       <para>A matching rule may rename a network interface, add symlinks
91       pointing to the device node, or run a specified program as part of
92       the event handling.</para>
93
94       <para>A rule consists of a list of one or more key value pairs separated by
95       a comma. Each key has a distinct operation, depending on the used operator. Valid
96       operators are:</para>
97       <variablelist>
98         <varlistentry>
99           <term><option>==</option></term>
100           <listitem>
101             <para>Compare for equality.</para>
102           </listitem>
103         </varlistentry>
104
105         <varlistentry>
106           <term><option>!=</option></term>
107           <listitem>
108             <para>Compare for inequality.</para>
109           </listitem>
110         </varlistentry>
111
112         <varlistentry>
113           <term><option>=</option></term>
114           <listitem>
115             <para>Assign a value to a key. Keys that represent a list, are reset
116             and only this single value is assigned.</para>
117           </listitem>
118         </varlistentry>
119
120         <varlistentry>
121           <term><option>+=</option></term>
122           <listitem>
123             <para>Add the value to a key that holds a list of entries.</para>
124           </listitem>
125         </varlistentry>
126
127         <varlistentry>
128           <term><option>:=</option></term>
129           <listitem>
130             <para>Assign  a  value  to  a key finally; disallow any later changes,
131             which may be used to prevent changes by any later rules.</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 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, if the specified match
200             value does not contain trailing whitespace itself.
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             if the specified match value does not contain trailing whitespace itself.</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. The key is true, if the program returns
262             successfully. The device properties are made available to the
263             executed program in the environment. The program's output printed to
264             stdout, is available in the RESULT key.</para>
265           </listitem>
266         </varlistentry>
267
268         <varlistentry>
269           <term><option>RESULT</option></term>
270           <listitem>
271             <para>Match the returned string of the last PROGRAM call. This key can
272             be used in the same or in any later rule after a PROGRAM call.</para>
273           </listitem>
274         </varlistentry>
275       </variablelist>
276
277       <para>Most of the fields support a shell style pattern matching. The following
278       pattern characters are supported:</para>
279       <variablelist>
280         <varlistentry>
281           <term><option>*</option></term>
282           <listitem>
283             <para>Matches zero, or any number of characters.</para>
284           </listitem>
285         </varlistentry>
286         <varlistentry>
287           <term><option>?</option></term>
288           <listitem>
289             <para>Matches any single character.</para>
290           </listitem>
291         </varlistentry>
292         <varlistentry>
293           <term><option>[]</option></term>
294           <listitem>
295             <para>Matches any single character specified within the brackets. For
296             example, the pattern string 'tty[SR]' would match either 'ttyS' or 'ttyR'.
297             Ranges are also supported within this match with the '-' character.
298             For example, to match on the range of all digits, the pattern [0-9] would
299             be used. If the first character following the '[' is a '!', any characters
300             not enclosed are matched.</para>
301           </listitem>
302         </varlistentry>
303       </variablelist>
304
305       <para>The following keys can get values assigned:</para>
306       <variablelist>
307         <varlistentry>
308           <term><option>NAME</option></term>
309           <listitem>
310             <para>The name, a network interface should be renamed to. Or as
311             a temporary workaraound, the name a device node should be named.
312             Usually the kernel provides the defined node name, or even creates
313             and removes the node before udev even receives any event. Changing
314             the node name from the kernel's default creates inconsistencies
315             and is not supported. If the kernel and NAME specify different names,
316             an error will be logged. Udev is only expected to handle device node
317             permissions and to create additional symlinks, not to change
318             kernel-provided device node names. Instead of renaming a device node,
319             SYMLINK should be used. Symlink names must never conflict with
320             device node names, it will result in unpredictable behavior.</para>
321           </listitem>
322         </varlistentry>
323
324         <varlistentry>
325           <term><option>SYMLINK</option></term>
326           <listitem>
327             <para>The name of a symlink targeting the node. Every matching rule will add
328             this value to the list of symlinks to be created. Multiple symlinks may be
329             specified by separating the names by the space character. In case multiple
330             devices claim the same name, the link will always point to the device with
331             the highest link_priority. If the current device goes away, the links will
332             be re-evaluated and the device with the next highest link_priority will own
333             the link. If no link_priority is specified, the order of the devices, and
334             which one of them will own the link, is undefined. Claiming the same name for
335             a symlink, which is or might be used for a device node, may result in
336             unexpected behavior and is not supported.
337             </para>
338           </listitem>
339         </varlistentry>
340
341         <varlistentry>
342           <term><option>OWNER, GROUP, MODE</option></term>
343           <listitem>
344             <para>The permissions for the device node. Every specified value overwrites
345             the compiled-in default value.</para>
346           </listitem>
347         </varlistentry>
348
349         <varlistentry>
350           <term><option>ATTR{<replaceable>key</replaceable>}</option></term>
351           <listitem>
352             <para>The value that should be written to a sysfs attribute of the
353             event device.</para>
354           </listitem>
355         </varlistentry>
356
357         <varlistentry>
358           <term><option>ENV{<replaceable>key</replaceable>}</option></term>
359           <listitem>
360             <para>Set a device property value. Property names with a leading '.'
361             are not stored in the database or exported to external tool or events.</para>
362           </listitem>
363         </varlistentry>
364
365         <varlistentry>
366           <term><option>TAG</option></term>
367           <listitem>
368             <para>Attach a tag to a device. This is used to filter events for users
369             of libudev's monitor functionality, or to enumerate a group of tagged
370             devices. The implementation can only work efficiently if only a few
371             tags are attached to a device. It is only meant to be used in
372             contexts with specific device filter requirements, and not as a
373             general-purpose flag. Excessive use might result in inefficient event
374             handling.</para>
375           </listitem>
376         </varlistentry>
377
378         <varlistentry>
379           <term><option>RUN</option></term>
380           <listitem>
381             <para>Add a program to the list of programs to be executed for a specific
382             device. This can only be used for very short running tasks. Running an
383             event process for a long period of time may block all further events for
384             this or a dependent device. Long running tasks need to be immediately
385             detached from the event process itself. If the option
386             <option>RUN{<replaceable>fail_event_on_error</replaceable>}</option> is
387             specified, and the executed program returns non-zero, the event will be
388             marked as failed for a possible later handling.</para>
389             <para>If no absolute path is given, the program is expected to live in
390             <filename>/lib/udev</filename>, otherwise the absolute path must be
391             specified. Program name and arguments are separated by spaces. Single quotes
392             can be used to specify arguments with spaces.</para>
393           </listitem>
394         </varlistentry>
395
396         <varlistentry>
397           <term><option>LABEL</option></term>
398           <listitem>
399             <para>Named label where a GOTO can jump to.</para>
400           </listitem>
401         </varlistentry>
402
403         <varlistentry>
404           <term><option>GOTO</option></term>
405           <listitem>
406             <para>Jumps to the next LABEL with a matching name</para>
407           </listitem>
408         </varlistentry>
409
410         <varlistentry>
411           <term><option>IMPORT{<replaceable>type</replaceable>}</option></term>
412           <listitem>
413             <para>Import a set of variables as device properties,
414             depending on <replaceable>type</replaceable>:</para>
415             <variablelist>
416               <varlistentry>
417                 <term><option>program</option></term>
418                 <listitem>
419                   <para>Execute an external program specified as the assigned value and
420                   import its output, which must be in environment key
421                   format. Path specification, command/argument separation,
422                   and quoting work like in <option>RUN</option>.</para>
423                 </listitem>
424               </varlistentry>
425               <varlistentry>
426                 <term><option>file</option></term>
427                 <listitem>
428                   <para>Import a text file specified as the assigned value, which must be in
429                   environment key format.</para>
430                 </listitem>
431               </varlistentry>
432               <varlistentry>
433                 <term><option>db</option></term>
434                 <listitem>
435                   <para>Import a single property specified as the assigned value from the
436                   current device database. This works only if the database is already populated
437                   by an earlier event.</para>
438                 </listitem>
439               </varlistentry>
440               <varlistentry>
441                 <term><option>cmdline</option></term>
442                 <listitem>
443                   <para>Import a single property from the kernel commandline. For simple flags
444                   the value of the property will be set to '1'.</para>
445                 </listitem>
446               </varlistentry>
447               <varlistentry>
448                 <term><option>parent</option></term>
449                 <listitem>
450                   <para>Import the stored keys from the parent device by reading
451                   the database entry of the parent device. The value assigned to
452                   <option>IMPORT{parent}</option> is used as a filter of key names
453                   to import (with the same shell-style pattern matching used for
454                   comparisons).</para>
455                 </listitem>
456               </varlistentry>
457             </variablelist>
458             <para>If no option is given, udev will choose between <option>program</option>
459             and <option>file</option> based on the executable bit of the file
460             permissions.</para>
461           </listitem>
462         </varlistentry>
463
464         <varlistentry>
465           <term><option>WAIT_FOR</option></term>
466           <listitem>
467             <para>Wait for a file to become available or until a 10
468             seconds timeout expires.</para>
469           </listitem>
470         </varlistentry>
471
472         <varlistentry>
473           <term><option>OPTIONS</option></term>
474           <listitem>
475             <para>Rule and device options:</para>
476             <variablelist>
477               <varlistentry>
478                 <term><option>link_priority=<replaceable>value</replaceable></option></term>
479                 <listitem>
480                   <para>Specify the priority of the created symlinks. Devices with higher
481                   priorities overwrite existing symlinks of other devices. The default is 0.</para>
482                 </listitem>
483               </varlistentry>
484               <varlistentry>
485                 <term><option>event_timeout=</option></term>
486                 <listitem>
487                   <para>Number of seconds an event will wait for operations to finish, before it
488                   will terminate itself.</para>
489                 </listitem>
490               </varlistentry>
491               <varlistentry>
492                 <term><option>string_escape=<replaceable>none|replace</replaceable></option></term>
493                 <listitem>
494                   <para>Usually control and other possibly unsafe characters are replaced
495                   in strings used for device naming. The mode of replacement can be specified
496                   with this option.</para>
497                 </listitem>
498               </varlistentry>
499               <varlistentry>
500                 <term><option>static_node=</option></term>
501                 <listitem>
502                   <para>Apply the permissions specified in this rule to a static device node with
503                   the specified name. Static device nodes might be provided by kernel modules,
504                   or copied from <filename>/lib/udev/devices</filename>. These nodes might not have
505                   a corresponding kernel device at the time udevd is started, and allow to trigger
506                   automatic kernel module on-demand loading.</para>
507                 </listitem>
508               </varlistentry>
509               <varlistentry>
510                 <term><option>watch</option></term>
511                 <listitem>
512                   <para>Watch the device node with inotify, when closed after being opened for
513                   writing, a change uevent will be synthesised.</para>
514                 </listitem>
515               </varlistentry>
516             </variablelist>
517           </listitem>
518         </varlistentry>
519       </variablelist>
520
521       <para>The <option>NAME</option>, <option>SYMLINK</option>, <option>PROGRAM</option>,
522       <option>OWNER</option>, <option>GROUP</option>, <option>MODE</option>  and  <option>RUN</option>
523       fields support simple printf-like string substitutions. The <option>RUN</option>
524       format chars gets applied after all rules have been processed, right before the program
525       is executed. It allows the use of device properties set by earlier matching
526       rules. For all other fields, substitutions are applied while the individual rule is
527       being processed. The available substitutions are:</para>
528       <variablelist>
529         <varlistentry>
530           <term><option>$kernel</option>, <option>%k</option></term>
531           <listitem>
532             <para>The kernel name for this device.</para>
533           </listitem>
534         </varlistentry>
535
536         <varlistentry>
537           <term><option>$number</option>, <option>%n</option></term>
538           <listitem>
539             <para>The kernel number for this device. For example, 'sda3' has
540             kernel number of '3'</para>
541           </listitem>
542         </varlistentry>
543
544         <varlistentry>
545           <term><option>$devpath</option>, <option>%p</option></term>
546           <listitem>
547             <para>The devpath of the device.</para>
548           </listitem>
549         </varlistentry>
550
551         <varlistentry>
552           <term><option>$id</option>, <option>%b</option></term>
553           <listitem>
554             <para>The name of the device matched while searching the devpath upwards for
555               <option>SUBSYSTEMS</option>, <option>KERNELS</option>, <option>DRIVERS</option> and <option>ATTRS</option>.
556             </para>
557           </listitem>
558         </varlistentry>
559
560         <varlistentry>
561           <term><option>$driver</option></term>
562           <listitem>
563             <para>The driver name of the device matched while searching the devpath upwards for
564               <option>SUBSYSTEMS</option>, <option>KERNELS</option>, <option>DRIVERS</option> and <option>ATTRS</option>.
565             </para>
566           </listitem>
567         </varlistentry>
568
569         <varlistentry>
570           <term><option>$attr{<replaceable>file</replaceable>}</option>, <option>%s{<replaceable>file</replaceable>}</option></term>
571           <listitem>
572             <para>The value of a sysfs attribute found at the device, where
573             all keys of the rule have matched. If the matching device does not have
574             such an attribute, follow the chain of parent devices and use the value
575             of the first attribute that matches.
576             If the attribute is a symlink, the last element of the symlink target is
577             returned as the value.</para>
578           </listitem>
579         </varlistentry>
580
581         <varlistentry>
582           <term><option>$env{<replaceable>key</replaceable>}</option>, <option>%E{<replaceable>key</replaceable>}</option></term>
583           <listitem>
584             <para>A device property value.</para>
585           </listitem>
586         </varlistentry>
587
588         <varlistentry>
589           <term><option>$major</option>, <option>%M</option></term>
590           <listitem>
591             <para>The kernel major number for the device.</para>
592           </listitem>
593         </varlistentry>
594
595         <varlistentry>
596           <term><option>$minor</option>, <option>%m</option></term>
597           <listitem>
598             <para>The kernel minor number for the device.</para>
599           </listitem>
600         </varlistentry>
601
602         <varlistentry>
603           <term><option>$result</option>, <option>%c</option></term>
604           <listitem>
605             <para>The string returned by the external program requested with PROGRAM.
606             A single part of the string, separated by a space character may be selected
607             by specifying the part number as an attribute: <option>%c{N}</option>.
608             If the number is followed by the '+' char this part plus all remaining parts
609             of the result string are substituted: <option>%c{N+}</option></para>
610           </listitem>
611         </varlistentry>
612
613         <varlistentry>
614           <term><option>$parent</option>, <option>%P</option></term>
615           <listitem>
616             <para>The node name of the parent device.</para>
617           </listitem>
618         </varlistentry>
619
620         <varlistentry>
621           <term><option>$name</option></term>
622           <listitem>
623             <para>The current name of the device node. If not changed by a rule, it is the
624             name of the kernel device.</para>
625           </listitem>
626         </varlistentry>
627
628         <varlistentry>
629           <term><option>$links</option></term>
630           <listitem>
631             <para>The current list of symlinks, separated by a space character. The value is
632             only set if an earlier rule assigned a value, or during a remove events.</para>
633           </listitem>
634         </varlistentry>
635
636         <varlistentry>
637           <term><option>$root</option>, <option>%r</option></term>
638           <listitem>
639             <para>The udev_root value.</para>
640           </listitem>
641         </varlistentry>
642
643         <varlistentry>
644           <term><option>$sys</option>, <option>%S</option></term>
645           <listitem>
646             <para>The sysfs mount point.</para>
647           </listitem>
648         </varlistentry>
649
650         <varlistentry>
651           <term><option>$tempnode</option>, <option>%N</option></term>
652           <listitem>
653             <para>The name of a created temporary device node to provide access to
654             the device from a external program before the real node is created.</para>
655           </listitem>
656         </varlistentry>
657
658         <varlistentry>
659           <term><option>%%</option></term>
660           <listitem>
661           <para>The '%' character itself.</para>
662           </listitem>
663         </varlistentry>
664
665         <varlistentry>
666           <term><option>$$</option></term>
667           <listitem>
668           <para>The '$' character itself.</para>
669           </listitem>
670         </varlistentry>
671       </variablelist>
672     </refsect2>
673   </refsect1>
674
675   <refsect1><title>Author</title>
676     <para>Written by Greg Kroah-Hartman <email>greg@kroah.com</email> and
677     Kay Sievers <email>kay.sievers@vrfy.org</email>. With much help from
678     Dan Stekloff and many others.</para>
679   </refsect1>
680
681   <refsect1>
682     <title>See Also</title>
683     <para><citerefentry>
684         <refentrytitle>udevd</refentrytitle><manvolnum>8</manvolnum>
685       </citerefentry>, 
686       <citerefentry>
687         <refentrytitle>udevadm</refentrytitle><manvolnum>8</manvolnum>
688     </citerefentry></para>
689   </refsect1>
690 </refentry>