chiark / gitweb /
use autotools
[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         <date>August 2005</date>
12         <productname>udev</productname>
13       </refentryinfo>
14
15       <refmeta>
16         <refentrytitle>udev</refentrytitle>
17         <manvolnum>7</manvolnum>
18         <refmiscinfo class="version"></refmiscinfo>
19       </refmeta>
20
21       <refnamediv>
22         <refname>udev</refname>
23         <refpurpose>dynamic device management</refpurpose>
24       </refnamediv>
25
26       <refsect1><title>DESCRIPTION</title>
27         <para>udev provides a dynamic device directory containing only the files for
28         actually present devices. It creates or removes device node files in the
29         <filename>/dev</filename> directory, or it renames network interfaces.</para>
30
31         <para>Usually udev runs as <citerefentry><refentrytitle>udevd</refentrytitle>
32         <manvolnum>8</manvolnum></citerefentry> and receives uevents directly from the
33         kernel if a device is added or removed from the system.</para>
34
35         <para>If udev receives a device event, it matches its configured rules
36         against the available device attributes provided in sysfs to identify the device.
37         Rules that match may provide additional device information or specify a device
38         node name and multiple symlink names and instruct udev to run additional programs
39         as part of the device event handling.</para>
40       </refsect1>
41
42       <refsect1><title>CONFIGURATION</title>
43         <para>udev configuration files are placed in <filename>/etc/udev/</filename>
44         and <filename>/lib/udev/</filename>. All empty lines, or lines beginning with
45         '#' will be ignored.</para>
46
47         <refsect2><title>Configuration file</title>
48           <para>udev expects its main configuration file at <filename>/etc/udev/udev.conf</filename>.
49           It consists of a set of variables allowing the user to override default udev values.
50           The following variables can be set:</para>
51           <variablelist>
52             <varlistentry>
53               <term><option>udev_root</option></term>
54               <listitem>
55                 <para>Specifies where to place the device nodes in the filesystem.
56                 The default value is <filename>/dev</filename>.</para>
57               </listitem>
58             </varlistentry>
59
60             <varlistentry>
61               <term><option>udev_log</option></term>
62               <listitem>
63                 <para>The logging priority. Valid values are the numerical syslog priorities
64                 or their textual representations: <option>err</option>, <option>info</option>
65                 and <option>debug</option>.</para>
66               </listitem>
67             </varlistentry>
68           </variablelist>
69         </refsect2>
70
71         <refsect2><title>Rules files</title>
72           <para>The udev rules are read from the files located in the
73           default rules directory <filename>/lib/udev/rules.d/</filename>,
74           the custom rules directory <filename>/etc/udev/rules.d/</filename>
75           and the temporary rules directory <filename>/dev/.udev/rules.d/</filename>.
76           All rule files are sorted and processed in lexical order, regardless
77           in which of these directories they live. Every line in the rules file contains at least
78           one key value pair. There are two kind of keys, match and assignment keys.
79           If all match keys are matching against its value, the rule gets applied and the
80           assign keys get the specified value assigned.</para>
81
82           <para>A matching rule may specify the name of the device node, add a symlink
83           pointing to the node, or run a specified program as part of the event handling.
84           If no matching rule is found, the default device node name is used.</para>
85
86           <para>A rule may consist of a list of one or more key value pairs separated by
87           a comma. Each key has a distinct operation, depending on the used operator. Valid
88           operators are:</para>
89           <variablelist>
90             <varlistentry>
91               <term><option>==</option></term>
92               <listitem>
93                 <para>Compare for equality.</para>
94               </listitem>
95             </varlistentry>
96
97             <varlistentry>
98               <term><option>!=</option></term>
99               <listitem>
100                 <para>Compare for non-equality.</para>
101               </listitem>
102             </varlistentry>
103
104             <varlistentry>
105               <term><option>=</option></term>
106               <listitem>
107                 <para>Assign a value to a key. Keys that represent a list, are reset
108                 and only this single value is assigned.</para>
109               </listitem>
110             </varlistentry>
111
112             <varlistentry>
113               <term><option>+=</option></term>
114               <listitem>
115                 <para>Add the value to a key that holds a list of entries.</para>
116               </listitem>
117             </varlistentry>
118
119             <varlistentry>
120               <term><option>:=</option></term>
121               <listitem>
122                 <para>Assign  a  value  to  a key finally; disallow any later changes,
123                 which may be used to prevent changes by any later rules.</para>
124               </listitem>
125             </varlistentry>
126           </variablelist>
127
128           <para>The following key names can be used to match against device properties.
129           Some of the keys also match against properties of the parent devices in sysfs,
130           not only the device that has generated the event. If multiple keys that match
131           a parent device are specified in a single rule, all these keys must match at
132           one and the same parent device.</para>
133           <variablelist>
134             <varlistentry>
135               <term><option>ACTION</option></term>
136               <listitem>
137                 <para>Match the name of the event action.</para>
138               </listitem>
139             </varlistentry>
140
141             <varlistentry>
142               <term><option>DEVPATH</option></term>
143               <listitem>
144                 <para>Match the devpath of the event device.</para>
145               </listitem>
146             </varlistentry>
147
148             <varlistentry>
149               <term><option>KERNEL</option></term>
150               <listitem>
151                 <para>Match the name of the event device.</para>
152               </listitem>
153             </varlistentry>
154
155             <varlistentry>
156               <term><option>NAME</option></term>
157               <listitem>
158                 <para>Match the name of the node or network interface. It can
159                 be used once the NAME key has been set in one of the preceding
160                 rules.</para>
161               </listitem>
162             </varlistentry>
163
164             <varlistentry>
165               <term><option>SUBSYSTEM</option></term>
166               <listitem>
167                 <para>Match the subsystem of the event device.</para>
168               </listitem>
169             </varlistentry>
170             <varlistentry>
171               <term><option>DRIVER</option></term>
172               <listitem>
173                 <para>Match the driver name of the event device. Only set for devices
174                 which are bound to a driver at the time the event is generated.</para>
175               </listitem>
176             </varlistentry>
177             <varlistentry>
178               <term><option>ATTR{<replaceable>filename</replaceable>}</option></term>
179               <listitem>
180                 <para>Match sysfs attribute values of the event device. Up to five
181                 <option>ATTR</option> keys can be specified per rule. Trailing
182                 whitespace in the attribute values is ignored, if the specified match
183                 value does not contain trailing whitespace itself. Depending on the type
184                 of operator, this key is also used to set the value of a sysfs attribute.
185                 </para>
186               </listitem>
187             </varlistentry>
188
189             <varlistentry>
190               <term><option>KERNELS</option></term>
191               <listitem>
192                 <para>Search the devpath upwards for a matching device name.</para>
193               </listitem>
194             </varlistentry>
195
196             <varlistentry>
197               <term><option>SUBSYSTEMS</option></term>
198               <listitem>
199                 <para>Search the devpath upwards for a matching device subsystem name.</para>
200               </listitem>
201             </varlistentry>
202
203             <varlistentry>
204               <term><option>DRIVERS</option></term>
205               <listitem>
206                 <para>Search the devpath upwards for a matching device driver name.</para>
207               </listitem>
208             </varlistentry>
209
210             <varlistentry>
211               <term><option>ATTRS{<replaceable>filename</replaceable>}</option></term>
212               <listitem>
213                 <para>Search the devpath upwards for a device with matching sysfs attribute values.
214                 Up to five <option>ATTRS</option> keys can be specified per rule, but all of them
215                 must match on the same device. Trailing whitespace in the attribute values is ignored,
216                 if the specified match value does not contain trailing whitespace itself.</para>
217               </listitem>
218             </varlistentry>
219
220             <varlistentry>
221               <term><option>ENV{<replaceable>key</replaceable>}</option></term>
222               <listitem>
223                 <para>Match against the value of an environment variable. Up to five <option>ENV</option>
224                 keys can be specified per rule. Depending on the type of operator, this key is also used
225                 to export a variable to the environment.</para>
226               </listitem>
227             </varlistentry>
228
229             <varlistentry>
230               <term><option>TEST{<replaceable>octal mode mask</replaceable>}</option></term>
231               <listitem>
232                 <para>Test the existence of a file. An octal mode mask can be specified
233                 if needed.</para>
234               </listitem>
235             </varlistentry>
236
237             <varlistentry>
238               <term><option>PROGRAM</option></term>
239               <listitem>
240                 <para>Execute external program. The key is true, if the program returns
241                 with exit code zero. The whole event environment is available to the
242                 executed program. The program's output printed to stdout, is available in
243                 the RESULT key.</para>
244               </listitem>
245             </varlistentry>
246
247             <varlistentry>
248               <term><option>RESULT</option></term>
249               <listitem>
250                 <para>Match the returned string of the last PROGRAM call. This key can
251                 be used in the same or in any later rule after a PROGRAM call.</para>
252               </listitem>
253             </varlistentry>
254           </variablelist>
255
256           <para>Most of the fields support a shell style pattern matching. The following
257           pattern characters are supported:</para>
258           <variablelist>
259             <varlistentry>
260               <term><option>*</option></term>
261               <listitem>
262                 <para>Matches zero, or any number of characters.</para>
263               </listitem>
264             </varlistentry>
265             <varlistentry>
266               <term><option>?</option></term>
267               <listitem>
268                 <para>Matches any single character.</para>
269               </listitem>
270             </varlistentry>
271             <varlistentry>
272               <term><option>[]</option></term>
273               <listitem>
274                 <para>Matches any single character specified within the brackets. For
275                 example, the pattern string 'tty[SR]' would match either 'ttyS' or 'ttyR'.
276                 Ranges are also supported within this match with the '-' character.
277                 For example, to match on the range of all digits, the pattern [0-9] would
278                 be used. If the first character following the '[' is a '!', any characters
279                 not enclosed are matched.</para>
280               </listitem>
281             </varlistentry>
282           </variablelist>
283
284           <para>The following keys can get values assigned:</para>
285           <variablelist>
286             <varlistentry>
287               <term><option>NAME</option></term>
288               <listitem>
289                 <para>The name of the node to be created, or the name the network interface
290                 should be renamed to. Only one rule can set the node name, all later rules with
291                 a NAME key will be ignored.</para>
292               </listitem>
293             </varlistentry>
294
295             <varlistentry>
296               <term><option>SYMLINK</option></term>
297               <listitem>
298                 <para>The name of a symlink targeting the node. Every matching rule can add
299                 this value to the list of symlinks to be created along with the device  node.
300                 Multiple symlinks may be specified by separating the names by the space
301                 character.</para>
302               </listitem>
303             </varlistentry>
304
305             <varlistentry>
306               <term><option>OWNER, GROUP, MODE</option></term>
307               <listitem>
308                 <para>The permissions for the device node. Every specified value overwrites
309                 the compiled-in default value.</para>
310               </listitem>
311             </varlistentry>
312
313             <varlistentry>
314               <term><option>ATTR{<replaceable>key</replaceable>}</option></term>
315               <listitem>
316                 <para>The value that should be written to a sysfs attribute of the
317                 event device. Depending on the type of operator, this key is also
318                 used to match against the value of a sysfs attribute.</para>
319               </listitem>
320             </varlistentry>
321
322             <varlistentry>
323               <term><option>ENV{<replaceable>key</replaceable>}</option></term>
324               <listitem>
325                 <para>Export a variable to the environment. Depending on the type of operator,
326                 this key is also to match against an environment variable.</para>
327               </listitem>
328             </varlistentry>
329
330             <varlistentry>
331               <term><option>RUN</option></term>
332               <listitem>
333                 <para>Add a program to the list of programs to be executed for a specific
334                 device. This can only be used for very short running tasks. Running an
335                 event process for a long period of time may block all further events for
336                 this or a dependent device. Long running tasks need to be immediately
337                 detached from the event process itself.</para>
338                 <para>If the specifiefd string starts with
339                 <option>socket:<replaceable>path</replaceable></option>, all current event
340                 values will be passed to the specified socket, as a message in the same
341                 format the kernel sends an uevent. If the first character of the specified path
342                 is an @ character, an abstract namespace socket is used, instead of an existing
343                 socket file.</para>
344               </listitem>
345             </varlistentry>
346
347             <varlistentry>
348               <term><option>LABEL</option></term>
349               <listitem>
350                 <para>Named label where a GOTO can jump to.</para>
351               </listitem>
352             </varlistentry>
353
354             <varlistentry>
355               <term><option>GOTO</option></term>
356               <listitem>
357                 <para>Jumps to the next LABEL with a matching name</para>
358               </listitem>
359             </varlistentry>
360
361             <varlistentry>
362               <term><option>IMPORT{<replaceable>type</replaceable>}</option></term>
363               <listitem>
364                 <para>Import a set of variables into the event environment,
365                 depending on <replaceable>type</replaceable>:</para>
366                 <variablelist>
367                   <varlistentry>
368                     <term><option>program</option></term>
369                     <listitem>
370                       <para>Execute an external program specified as the assigned value and
371                       import its output, which must be in environment key format.</para>
372                     </listitem>
373                   </varlistentry>
374                   <varlistentry>
375                     <term><option>file</option></term>
376                     <listitem>
377                       <para>Import a text file specified as the assigned value, which must be in
378                       environment key format.</para>
379                     </listitem>
380                   </varlistentry>
381                   <varlistentry>
382                     <term><option>parent</option></term>
383                     <listitem>
384                       <para>Import the stored keys from the parent device by reading
385                       the database entry of the parent device. The value assigned to
386                       <option>IMPORT{parent}</option> is used as a filter of key names
387                       to import (with the same shell-style pattern matching used for
388                       comparisons).</para>
389                     </listitem>
390                   </varlistentry>
391                 </variablelist>
392                 <para>If no option is given, udev will choose between <option>program</option>
393                 and <option>file</option> based on the executable bit of the file
394                 permissions.</para>
395               </listitem>
396             </varlistentry>
397
398             <varlistentry>
399               <term><option>WAIT_FOR</option></term>
400               <listitem>
401                 <para>Wait for a file to become available.</para>
402               </listitem>
403             </varlistentry>
404
405             <varlistentry>
406               <term><option>OPTIONS</option></term>
407               <listitem>
408                 <para>Rule and device options:</para>
409                 <variablelist>
410                   <varlistentry>
411                     <term><option>last_rule</option></term>
412                     <listitem>
413                       <para>Stops further rules application. No later rules will have
414                       any effect.</para>
415                     </listitem>
416                   </varlistentry>
417                   <varlistentry>
418                     <term><option>ignore_device</option></term>
419                     <listitem>
420                       <para>Ignore this event completely.</para>
421                     </listitem>
422                   </varlistentry>
423                   <varlistentry>
424                     <term><option>ignore_remove</option></term>
425                     <listitem>
426                       <para>Do not remove the device node when the device goes away. This may be
427                       useful as a workaround for broken device drivers.</para>
428                     </listitem>
429                   </varlistentry>
430                   <varlistentry>
431                     <term><option>link_priority=<replaceable>value</replaceable></option></term>
432                     <listitem>
433                       <para>Specify the priority of the created symlinks. Devices with higher
434                       priorities overwrite existing symlinks of other devices. The default is 0.</para>
435                     </listitem>
436                   </varlistentry>
437                   <varlistentry>
438                     <term><option>all_partitions</option></term>
439                     <listitem>
440                       <para>Create the device nodes for all available partitions of a block device.
441                       This may be useful for removable media devices where media changes are not
442                       detected.</para>
443                     </listitem>
444                   </varlistentry>
445                   <varlistentry>
446                     <term><option>event_timeout=</option></term>
447                     <listitem>
448                       <para>Number of seconds an event will wait for operations to finish, before it
449                       will terminate itself.</para>
450                     </listitem>
451                   </varlistentry>
452                   <varlistentry>
453                     <term><option>string_escape=<replaceable>none|replace</replaceable></option></term>
454                     <listitem>
455                       <para>Usually control and other possibly unsafe characters are replaced
456                       in strings used for device naming. The mode of replacement can be specified
457                       with this option.</para>
458                     </listitem>
459                   </varlistentry>
460                 </variablelist>
461               </listitem>
462             </varlistentry>
463           </variablelist>
464
465           <para>The <option>NAME</option>, <option>SYMLINK</option>, <option>PROGRAM</option>,
466           <option>OWNER</option>, <option>GROUP</option>, <option>MODE</option>  and  <option>RUN</option>
467           fields support simple printf-like string substitutions. The <option>RUN</option>
468           format chars gets applied after all rules have been processed, right before the program
469           is executed. It allows the use of the complete environment set by earlier matching
470           rules. For all other fields, substitutions are applied while the individual rule is
471           being processed. The available substitutions are:</para>
472           <variablelist>
473             <varlistentry>
474               <term><option>$kernel</option>, <option>%k</option></term>
475               <listitem>
476                 <para>The kernel name for this device.</para>
477               </listitem>
478             </varlistentry>
479
480             <varlistentry>
481               <term><option>$number</option>, <option>%n</option></term>
482               <listitem>
483                 <para>The kernel number for this device. For example, 'sda3' has
484                 kernel number of '3'</para>
485               </listitem>
486             </varlistentry>
487
488             <varlistentry>
489               <term><option>$devpath</option>, <option>%p</option></term>
490               <listitem>
491                 <para>The devpath of the device.</para>
492               </listitem>
493             </varlistentry>
494
495             <varlistentry>
496               <term><option>$id</option>, <option>%b</option></term>
497               <listitem>
498                 <para>The name of the device matched while searching the devpath upwards for
499                   <option>SUBSYSTEMS</option>, <option>KERNELS</option>, <option>DRIVERS</option> and <option>ATTRS</option>.
500                 </para>
501               </listitem>
502             </varlistentry>
503
504             <varlistentry>
505               <term><option>$driver</option></term>
506               <listitem>
507                 <para>The driver name of the device matched while searching the devpath upwards for
508                   <option>SUBSYSTEMS</option>, <option>KERNELS</option>, <option>DRIVERS</option> and <option>ATTRS</option>.
509                 </para>
510               </listitem>
511             </varlistentry>
512
513             <varlistentry>
514               <term><option>$attr{<replaceable>file</replaceable>}</option>, <option>%s{<replaceable>file</replaceable>}</option></term>
515               <listitem>
516                 <para>The value of a sysfs attribute found at the device, where
517                 all keys of the rule have matched. If the matching device does not have
518                 such an attribute, follow the chain of parent devices and use the value
519                 of the first attribute that matches.
520                 If the attribute is a symlink, the last element of the symlink target is
521                 returned as the value.</para>
522               </listitem>
523             </varlistentry>
524
525             <varlistentry>
526               <term><option>$env{<replaceable>key</replaceable>}</option>, <option>%E{<replaceable>key</replaceable>}</option></term>
527               <listitem>
528                 <para>The value of an environment variable.</para>
529               </listitem>
530             </varlistentry>
531
532             <varlistentry>
533               <term><option>$major</option>, <option>%M</option></term>
534               <listitem>
535                 <para>The kernel major number for the device.</para>
536               </listitem>
537             </varlistentry>
538
539             <varlistentry>
540               <term><option>$minor</option>, <option>%m</option></term>
541               <listitem>
542                 <para>The kernel minor number for the device.</para>
543               </listitem>
544             </varlistentry>
545
546             <varlistentry>
547               <term><option>$result</option>, <option>%c</option></term>
548               <listitem>
549                 <para>The string returned by the external program requested with PROGRAM.
550                 A single part of the string, separated by a space character may be selected
551                 by specifying the part number as an attribute: <option>%c{N}</option>.
552                 If the number is followed by the '+' char this part plus all remaining parts
553                 of the result string are substituted: <option>%c{N+}</option></para>
554               </listitem>
555             </varlistentry>
556
557             <varlistentry>
558               <term><option>$parent</option>, <option>%P</option></term>
559               <listitem>
560                 <para>The node name of the parent device.</para>
561               </listitem>
562             </varlistentry>
563
564             <varlistentry>
565               <term><option>$name</option></term>
566               <listitem>
567                 <para>The current name of the device node. If not changed by a rule, it is the
568                 name of the kernel device.</para>
569               </listitem>
570             </varlistentry>
571
572             <varlistentry>
573               <term><option>$links</option></term>
574               <listitem>
575                 <para>The current list of symlinks, separated by a space character. The value is
576                 only set if an earlier rule assigned a value, or during a remove events.</para>
577               </listitem>
578             </varlistentry>
579
580             <varlistentry>
581               <term><option>$root</option>, <option>%r</option></term>
582               <listitem>
583                 <para>The udev_root value.</para>
584               </listitem>
585             </varlistentry>
586
587             <varlistentry>
588               <term><option>$sys</option>, <option>%S</option></term>
589               <listitem>
590                 <para>The sysfs mount point.</para>
591               </listitem>
592             </varlistentry>
593
594             <varlistentry>
595               <term><option>$tempnode</option>, <option>%N</option></term>
596               <listitem>
597                 <para>The name of a created temporary device node to provide access to
598                 the device from a external program before the real node is created.</para>
599               </listitem>
600             </varlistentry>
601
602             <varlistentry>
603               <term><option>%%</option></term>
604               <listitem>
605               <para>The '%' character itself.</para>
606               </listitem>
607             </varlistentry>
608
609             <varlistentry>
610               <term><option>$$</option></term>
611               <listitem>
612               <para>The '$' character itself.</para>
613               </listitem>
614             </varlistentry>
615           </variablelist>
616           <para>The count of characters to be substituted may be limited by specifying
617           the format length value. For example, '%3s{file}' will only
618           insert the first three characters of the sysfs attribute</para>
619         </refsect2>
620       </refsect1>
621
622       <refsect1><title>AUTHOR</title>
623         <para>Written by Greg Kroah-Hartman <email>greg@kroah.com</email> and
624         Kay Sievers <email>kay.sievers@vrfy.org</email>. With much help from
625         Dan Stekloff and many others.</para>
626       </refsect1>
627
628       <refsect1>
629         <title>SEE ALSO</title>
630         <para><citerefentry>
631             <refentrytitle>udevd</refentrytitle><manvolnum>8</manvolnum>
632           </citerefentry>, 
633           <citerefentry>
634             <refentrytitle>udevadm</refentrytitle><manvolnum>8</manvolnum>
635         </citerefentry></para>
636       </refsect1>
637     </refentry>
638   </section>
639 </article>