chiark / gitweb /
move and update libsysfs.txt
[elogind.git] / docs / 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   <articleinfo>
7     <title>xmlto</title>
8     <author>
9       <firstname>Kay</firstname>
10       <surname>Sievers</surname>
11       <email>kay.sievers@vrfy.org</email>
12     </author>
13     <copyright>
14       <year>2005</year>
15       <holder>Kay Sievers</holder>
16     </copyright>
17   </articleinfo>
18
19   <section>
20     <title>udev</title>
21     <refentry>
22       <refentryinfo>
23         <title>udev</title>
24         <date>August 2005</date>
25         <productname>udev</productname>
26       </refentryinfo>
27
28       <refmeta>
29         <refentrytitle>udev</refentrytitle>
30         <manvolnum>8</manvolnum>
31       </refmeta>
32
33       <refnamediv>
34         <refname>udev</refname>
35         <refpurpose>dynamic device management</refpurpose>
36       </refnamediv>
37
38       <refsect1><title>DESCRIPTION</title>
39         <para>udev provides a dynamic device directory containing only the files for
40         actually present devices. It creates or removes device node files in the
41         <filename>/dev</filename> directory, or it renames network interfaces.</para>
42
43         <para>Usually udev runs as <citerefentry><refentrytitle>udevd</refentrytitle>
44         <manvolnum>8</manvolnum></citerefentry> and receives uevents directly from the
45         kernel if a device is added or removed form the system. The program
46         <command>udev</command> itself may be used as an event handler in situations,
47         where running the daemon is not appropriate, like in initramfs.</para>
48
49         <para>If udev receives a device event, it matches its configured rules
50         against the available device attributes provided in sysfs to identify the device.
51         Rules that match, may provide additional device information or specify a device
52         node name and multiple symlink names and instruct udev to run additional programs
53         as part of the device event handling.</para>
54       </refsect1>
55
56       <refsect1><title>CONFIGURATION</title>
57         <para>All udev configuration files are placed in <filename>/etc/udev/*</filename>.
58         Every file consist of a set of lines of text. All empty lines or lines beginning
59         with '#' will be ignored.</para>
60
61         <refsect2><title>Configuration file</title>
62           <para>udev expects its main configuration file at <filename>/etc/udev/udev.conf</filename>.
63           It consists of a set of variables allowing the user to override default udev values.
64           The following variables can be set:</para>
65           <variablelist>
66             <varlistentry>
67               <term><option>udev_root</option></term>
68               <listitem>
69                 <para>Specifies where to place the device nodes in the filesystem.
70                 The default value is <filename>/dev</filename>.</para>
71               </listitem>
72             </varlistentry>
73
74             <varlistentry>
75               <term><option>udev_db</option></term>
76               <listitem>
77                 <para>The name and location of the udev database. The default value is
78                 <filename>/dev/.udevdb</filename>.</para>
79               </listitem>
80             </varlistentry>
81
82             <varlistentry>
83               <term><option>udev_rules</option></term>
84               <listitem>
85                 <para>The name of the udev rules file or directory to look for files
86                 with the suffix <filename>.rules</filename>. Multiple rule files are
87                 read in lexical order. The default value is
88                 <filename>/etc/udev/rules.d</filename>.</para>
89               </listitem>
90             </varlistentry>
91
92             <varlistentry>
93               <term><option>udev_log</option></term>
94               <listitem>
95                 <para>The logging priority. Valid values are the numerical syslog priorities
96                 or their textual representations: <option>err</option>, <option>info</option>
97                 and <option>debug</option>.</para>
98               </listitem>
99             </varlistentry>
100           </variablelist>
101         </refsect2>
102
103         <refsect2><title>Rules files</title>
104           <para>The udev rules are read from the files located in the
105           <filename>/etc/udev/rules.d</filename> directory or at the location specified
106           value in the configuraton file. Every line in the rules file contains at least
107           one key value pair. There are two kind of keys, match and assignement keys.
108           If all match keys are matching against its value, the rule gets applied and the
109           assign keys get the specified value assigned. A matching rule may specify the
110           name of the device node, add a symlink pointing to the node, or run a specified
111           program as part of the event handling. If no matching rule is found, the default
112           device node name is used.</para>
113
114           <para>A rule may consists of a list of one or more key value pairs separated by
115           a comma. Each key has a distinct operation, depending on the used operator. Valid
116           operators are:</para>
117           <variablelist>
118             <varlistentry>
119               <term><option>==</option></term>
120               <listitem>
121                 <para>Compare for equality.</para>
122               </listitem>
123             </varlistentry>
124
125             <varlistentry>
126               <term><option>!=</option></term>
127               <listitem>
128                 <para>Compare for non-equality.</para>
129               </listitem>
130             </varlistentry>
131
132             <varlistentry>
133               <term><option>=</option></term>
134               <listitem>
135                 <para>Asign a value to a key. Keys that represent a list, are reset
136                 and only this single value is assigned.</para>
137               </listitem>
138             </varlistentry>
139
140             <varlistentry>
141               <term><option>+=</option></term>
142               <listitem>
143                 <para>Add the value to a key that holds a list of entries.</para>
144               </listitem>
145             </varlistentry>
146
147             <varlistentry>
148               <term><option>:=</option></term>
149               <listitem>
150                 <para>Assign  a  value  to  a key finally; disallow any later changes,
151                 which may be used to prevent changes by any later rules.</para>
152               </listitem>
153             </varlistentry>
154           </variablelist>
155
156           <para>The following key names can be used to match against device properties:</para>
157           <variablelist>
158             <varlistentry>
159               <term><option>ACTION</option></term>
160               <listitem>
161                 <para>Match the kernel action name.</para>
162               </listitem>
163             </varlistentry>
164
165             <varlistentry>
166               <term><option>KERNEL</option></term>
167               <listitem>
168                 <para>Match the kernel device name</para>
169               </listitem>
170             </varlistentry>
171
172             <varlistentry>
173               <term><option>DEVPATH</option></term>
174               <listitem>
175                 <para>Match the kernel devpath.</para>
176               </listitem>
177             </varlistentry>
178
179             <varlistentry>
180               <term><option>SUBSYSTEM</option></term>
181               <listitem>
182                 <para>Match the kernel subsystem name</para>
183               </listitem>
184             </varlistentry>
185
186             <varlistentry>
187               <term><option>BUS</option></term>
188               <listitem>
189                 <para>Match the typ of bus the device is connected to.</para>
190               </listitem>
191             </varlistentry>
192
193             <varlistentry>
194               <term><option>DRIVER</option></term>
195               <listitem>
196                 <para>Match the kernel driver name.</para>
197               </listitem>
198             </varlistentry>
199
200             <varlistentry>
201               <term><option>ID</option></term>
202               <listitem>
203                 <para>Match the device number on the bus.</para>
204               </listitem>
205             </varlistentry>
206
207             <varlistentry>
208               <term><option>ENV{<replaceable>key</replaceable>}</option></term>
209               <listitem>
210                 <para>Match against the value of an environment key. Depending on
211                 the specified operation, this key is also used as a assignment.</para>
212               </listitem>
213             </varlistentry>
214
215             <varlistentry>
216               <term><option>SYSFS{<replaceable>filename</replaceable>}</option></term>
217               <listitem>
218                 <para>Match the sysfs attribute value. Up to five values can be specified.
219                 Trailing whitespace is ignored, if the specified match value does not contain
220                 trailing whitespace itself.</para>
221               </listitem>
222             </varlistentry>
223
224             <varlistentry>
225               <term><option>PROGRAM</option></term>
226               <listitem>
227                 <para>Execute external program. The key is true, if the program returns
228                 without exit code zero. The whole event environment is available to the
229                 executed program. The program's output printed to stdout is available for
230                 the RESULT key.</para>
231               </listitem>
232             </varlistentry>
233
234             <varlistentry>
235               <term><option>RESULT</option></term>
236               <listitem>
237                 <para>Match the returned string of the last PROGRAM call. This key can
238                 be used in the same or in any later rule after a PROGRAM call.</para>
239               </listitem>
240             </varlistentry>
241           </variablelist>
242
243           <para>Most of the fields support a shell style pattern matching. The following
244           pattern characters are supported:</para>
245           <variablelist>
246             <varlistentry>
247               <term><option>*</option></term>
248               <listitem>
249                 <para>Matches zero, or any number of characters.</para>
250               </listitem>
251             </varlistentry>
252             <varlistentry>
253               <term><option>?</option></term>
254               <listitem>
255                 <para>Matches any single character.</para>
256               </listitem>
257             </varlistentry>
258             <varlistentry>
259               <term><option>[]</option></term>
260               <listitem>
261                 <para>Matches any single character specified within the brackets.
262                 example, the pattern string 'tty[SR]' would match either 'ttyS' or 'ttyR'.
263                 Ranges are also supported within this match with the '-' character.
264                 For example, to match on the range of all digits, the pattern [0-9] would
265                 be used. If the first character following the '[' is a '!', any characters
266                 not enclosed are matched.</para>
267               </listitem>
268             </varlistentry>
269           </variablelist>
270
271           <para>The following keys can get values assigned:</para>
272           <variablelist>
273             <varlistentry>
274               <term><option>NAME</option></term>
275               <listitem>
276                 <para>The name of the node to be created, or the name, the network interface
277                 should be renamed to. Only one rule can set the a name, all later rules with
278                 a NAME key will be ignored.</para>
279               </listitem>
280             </varlistentry>
281
282             <varlistentry>
283               <term><option>SYMLINK</option></term>
284               <listitem>
285                 <para>The name of a symlink targeting the node. Every matching rule can add
286                 this value to the list of symlinks to be created along with the device  node.
287                 Multiple symlinks may be specified by separating the names by the space
288                 character.</para>
289               </listitem>
290             </varlistentry>
291
292             <varlistentry>
293               <term><option>OWNER, GROUP, MODE</option></term>
294               <listitem>
295                 <para>The permissions for the device node. Every specified value over writes
296                 the compiled-in default value.</para>
297               </listitem>
298             </varlistentry>
299
300             <varlistentry>
301               <term><option>ENV{<replaceable>key</replaceable>}</option></term>
302               <listitem>
303                 <para>Export the key to the environment. Depending on the specified
304                 operation, this key is also used as a match.</para>
305               </listitem>
306             </varlistentry>
307
308             <varlistentry>
309               <term><option>RUN</option></term>
310               <listitem>
311                 <para>Add a program to the list of programs to be executed for a specific
312                 device.</para>
313               </listitem>
314             </varlistentry>
315
316             <varlistentry>
317               <term><option>LABEL</option></term>
318               <listitem>
319                 <para>Named label where a GOTO can jump to.</para>
320               </listitem>
321             </varlistentry>
322
323             <varlistentry>
324               <term><option>GOTO</option></term>
325               <listitem>
326                 <para>Jumps to the next LABEL with a matching gname</para>
327               </listitem>
328             </varlistentry>
329
330             <varlistentry>
331               <term><option>IMPORT{<replaceable>type</replaceable>}</option></term>
332               <listitem>
333                 <para>Import the printed result or the content of a file in environment key
334                 format into the event environment. <option>program</option> will execute an
335                 external program and read its output. <option>file</option> will inport a
336                 text file. If no option is given, udev will determine it from the  executable
337                 bit of of the file permissions.</para>
338               </listitem>
339             </varlistentry>
340
341             <varlistentry>
342               <term><option>WAIT_FOR_SYSFS</option></term>
343               <listitem>
344                 <para>Wait for the specified sysfs file of the device to be created. May be used
345                 to fight agains timing issues wth the kernel.</para>
346               </listitem>
347             </varlistentry>
348
349             <varlistentry>
350               <term><option>OPTIONS</option></term>
351               <listitem>
352                 <para><option>last_rule</option> stops further rules application. No later rules
353                 will have any effect.
354                 <option>ignore_device</option> will ignore this event completely.
355                 <option>ignore_remove</option> will ignore  any  later  remove  event  for  this
356                 device. This may be useful as a workaround for broken device drivers.
357                 <option>all_partitions</option> will create device nodes for all available partitions of
358                 a block device. This may be useful for removable media.</para>
359               </listitem>
360             </varlistentry>
361           </variablelist>
362
363           <para>The <option>NAME</option>, <option>SYMLINK</option>, <option>PROGRAM</option>,
364           <option>OWNER</option>  and  <option>GROUP</option>  fields  support  simple
365           printf-like string substitutions:</para>
366           <variablelist>
367             <varlistentry>
368               <term><option>%k</option>, <option>$kernel</option></term>
369               <listitem>
370                 <para>The kernel name for this device.</para>
371               </listitem>
372             </varlistentry>
373
374             <varlistentry>
375               <term><option>%b</option>, <option>$id</option></term>
376               <listitem>
377                 <para>The kernel bus id for this device.</para>
378               </listitem>
379             </varlistentry>
380
381             <varlistentry>
382               <term><option>%n</option>, <option>$number</option></term>
383               <listitem>
384                 <para>The kernel number for this device. For example, 'sda3' has
385                 kernel number of '3'</para>
386               </listitem>
387             </varlistentry>
388
389             <varlistentry>
390               <term><option>%p</option>, <option>$devpath</option></term>
391               <listitem>
392                 <para>The devpath of the device.</para>
393               </listitem>
394             </varlistentry>
395
396             <varlistentry>
397               <term><option>%s{<replaceable>file</replaceable>}</option>, <option>$sysfs{<replaceable>file</replaceable>}</option></term>
398               <listitem>
399                 <para>The content of a sysfs attribute.</para>
400               </listitem>
401             </varlistentry>
402
403             <varlistentry>
404               <term><option>%e{<replaceable>key</replaceable>}</option>, <option>$env{<replaceable>key</replaceable>}</option></term>
405               <listitem>
406                 <para>The value of an environment variable.</para>
407               </listitem>
408             </varlistentry>
409
410             <varlistentry>
411               <term><option>%m</option>, <option>$major</option></term>
412               <listitem>
413                 <para>The kernel major number for the device.</para>
414               </listitem>
415             </varlistentry>
416
417             <varlistentry>
418               <term><option>%M</option> <option>$minor</option></term>
419               <listitem>
420                 <para>The kernel minor number for the device.</para>
421               </listitem>
422             </varlistentry>
423
424             <varlistentry>
425               <term><option>%c</option>, <option>$result</option></term>
426               <listitem>
427                 <para>The string returned by the external program requested with PROGRAM.
428                 A single part of the string, separated by a space character may be selected
429                 by specifying the part number as an attribute: <option>%c{N}</option>.
430                 If the number is followed by the '+' char this part plus all remaining parts
431                 of the result string are substituted: <option>%c{N+}</option></para>
432               </listitem>
433             </varlistentry>
434
435             <varlistentry>
436               <term><option>%e</option>, <option>$enum</option></term>
437               <listitem>
438                 <para>If a device node already exists with the name, the smallest next free
439                 number is used. This  can be used to create compatibility symlinks and enumerate
440                 devices of the same type originating from different kernel subsystems.</para>
441                 <para>Note: The use of the enumeration facility is unreliable for events that
442                 request a number at the same time. The  use  of enumerations in todays setups
443                 where devices can come and go at any time is not recomended.</para>
444               </listitem>
445             </varlistentry>
446
447             <varlistentry>
448               <term><option>%P</option>, <option>$parent</option></term>
449               <listitem>
450                 <para>The node name of the parent device.</para>
451               </listitem>
452             </varlistentry>
453
454             <varlistentry>
455               <term><option>%r</option>, <option>$root</option></term>
456               <listitem>
457                 <para>The udev_root value.</para>
458               </listitem>
459             </varlistentry>
460
461             <varlistentry>
462               <term><option>%N</option>, <option>$tempnode</option></term>
463               <listitem>
464                 <para>The name of a created temporary device node to provide access to
465                 the device from a external program before the real node is created.</para>
466               </listitem>
467             </varlistentry>
468
469             <varlistentry>
470               <term><option>%%</option></term>
471               <listitem>
472               <para>The '%' character itself.</para>
473               </listitem>
474             </varlistentry>
475
476             <varlistentry>
477               <term><option>$$</option></term>
478               <listitem>
479               <para>The '$' character itself.</para>
480               </listitem>
481             </varlistentry>
482           </variablelist>
483           <para>The count of characters to be substituted may be limited by specifying
484           the format length value. For example, '%3s{file}' will only
485           insert the first three characters of the sysfs attribute</para>
486         </refsect2>
487       </refsect1>
488
489       <refsect1><title>ENVIRONMENT</title>
490         <variablelist>
491           <varlistentry>
492             <term><option>ACTION</option></term>
493             <listitem>
494               <para><replaceable>add</replaceable> or <replaceable>remove</replaceable> signifies
495               the addition or the removal of a device.</para>
496             </listitem>
497           </varlistentry>
498
499           <varlistentry>
500             <term><option>DEVPATH</option></term>
501             <listitem>
502               <para>The sysfs devpath without the mountpoint but a leading slash.</para>
503             </listitem>
504           </varlistentry>
505
506           <varlistentry>
507             <term><option>SUBSYSTEM</option></term>
508             <listitem>
509               <para>The kernel subsystem the device belongs to.</para>
510             </listitem>
511           </varlistentry>
512
513           <varlistentry>
514             <term><option>UDEV_LOG</option></term>
515             <listitem>
516               <para>Overrides the syslog priority specified in the config file.</para>
517             </listitem>
518           </varlistentry>
519         </variablelist>
520      </refsect1>
521
522       <refsect1><title>AUTHOR</title>
523         <para>Written by Greg Kroah-Hartman <email>greg@kroah.com</email> and
524         Kay Sievers <email>kay.sievers@vrfy.org</email>. With much help from
525         Dan  Stekloff <email>dsteklof@us.ibm.com</email> and many others.</para>
526       </refsect1>
527
528       <refsect1>
529         <title>SEE ALSO</title>
530         <para><citerefentry>
531             <refentrytitle>udev</refentrytitle><manvolnum>8</manvolnum>
532           </citerefentry>, 
533           <citerefentry>
534             <refentrytitle>udevinfo</refentrytitle><manvolnum>8</manvolnum>
535           </citerefentry>, 
536           <citerefentry>
537             <refentrytitle>udevd</refentrytitle><manvolnum>8</manvolnum>
538           </citerefentry>, 
539           <citerefentry>
540             <refentrytitle>udevmonitor</refentrytitle><manvolnum>8</manvolnum>
541         </citerefentry></para>
542       </refsect1>
543     </refentry>
544   </section>
545 </article>