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