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