chiark / gitweb /
man: add $attr{} section about symlinks
[elogind.git] / 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 form 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>All udev configuration files are placed in <filename>/etc/udev/*</filename>.
44         Every file consists of a set of lines of text. All empty lines or lines beginning
45         with '#' 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_rules</option></term>
62               <listitem>
63                 <para>The name of the udev rules file or directory to look for files
64                 with the suffix <filename>.rules</filename>. Multiple rule files are
65                 read in lexical order. The default value is
66                 <filename>/etc/udev/rules.d</filename>.</para>
67               </listitem>
68             </varlistentry>
69
70             <varlistentry>
71               <term><option>udev_log</option></term>
72               <listitem>
73                 <para>The logging priority. Valid values are the numerical syslog priorities
74                 or their textual representations: <option>err</option>, <option>info</option>
75                 and <option>debug</option>.</para>
76               </listitem>
77             </varlistentry>
78           </variablelist>
79         </refsect2>
80
81         <refsect2><title>Rules files</title>
82           <para>The udev rules are read from the files located in the
83           <filename>/etc/udev/rules.d</filename> directory or at the location specified
84           value in the configuration file. Every line in the rules file contains at least
85           one key value pair. There are two kind of keys, match and assignment keys.
86           If all match keys are matching against its value, the rule gets applied and the
87           assign keys get the specified value assigned. A matching rule may specify the
88           name of the device node, add a symlink pointing to the node, or run a specified
89           program as part of the event handling. If no matching rule is found, the default
90           device node name is used.</para>
91
92           <para>A rule may consists of a list of one or more key value pairs separated by
93           a comma. Each key has a distinct operation, depending on the used operator. Valid
94           operators are:</para>
95           <variablelist>
96             <varlistentry>
97               <term><option>==</option></term>
98               <listitem>
99                 <para>Compare for equality.</para>
100               </listitem>
101             </varlistentry>
102
103             <varlistentry>
104               <term><option>!=</option></term>
105               <listitem>
106                 <para>Compare for non-equality.</para>
107               </listitem>
108             </varlistentry>
109
110             <varlistentry>
111               <term><option>=</option></term>
112               <listitem>
113                 <para>Assign a value to a key. Keys that represent a list, are reset
114                 and only this single value is assigned.</para>
115               </listitem>
116             </varlistentry>
117
118             <varlistentry>
119               <term><option>+=</option></term>
120               <listitem>
121                 <para>Add the value to a key that holds a list of entries.</para>
122               </listitem>
123             </varlistentry>
124
125             <varlistentry>
126               <term><option>:=</option></term>
127               <listitem>
128                 <para>Assign  a  value  to  a key finally; disallow any later changes,
129                 which may be used to prevent changes by any later rules.</para>
130               </listitem>
131             </varlistentry>
132           </variablelist>
133
134           <para>The following key names can be used to match against device properties:</para>
135           <variablelist>
136             <varlistentry>
137               <term><option>ACTION</option></term>
138               <listitem>
139                 <para>Match the name of the event action.</para>
140               </listitem>
141             </varlistentry>
142
143             <varlistentry>
144               <term><option>DEVPATH</option></term>
145               <listitem>
146                 <para>Match the devpath of the event device.</para>
147               </listitem>
148             </varlistentry>
149
150             <varlistentry>
151               <term><option>KERNEL</option></term>
152               <listitem>
153                 <para>Match the name of the event device.</para>
154               </listitem>
155             </varlistentry>
156
157             <varlistentry>
158               <term><option>SUBSYSTEM</option></term>
159               <listitem>
160                 <para>Match the subsystem of the event device.</para>
161               </listitem>
162             </varlistentry>
163 <!--
164             <varlistentry>
165               <term><option>DRIVER</option></term>
166               <listitem>
167                 <para>Match the driver name of the event device. Only set for devices created by a bus driver.</para>
168               </listitem>
169             </varlistentry>
170 -->
171             <varlistentry>
172               <term><option>ATTR{<replaceable>filename</replaceable>}</option></term>
173               <listitem>
174                 <para>Match sysfs attribute values of the event device. Up to five
175                 <option>ATTR</option> keys can be specified per rule. Trailing
176                 whitespace in the attribute values is ignored, if the specified match
177                 value does not contain trailing whitespace itself. Depending on the type
178                 of operator, this key is also used to set the value of a sysfs attribute.
179                 </para>
180               </listitem>
181             </varlistentry>
182
183             <varlistentry>
184               <term><option>KERNELS</option></term>
185               <listitem>
186                 <para>Search the devpath upwards for a matching device name.</para>
187               </listitem>
188             </varlistentry>
189
190             <varlistentry>
191               <term><option>SUBSYSTEMS</option></term>
192               <listitem>
193                 <para>Search the devpath upwards for a matching device subsystem name.</para>
194               </listitem>
195             </varlistentry>
196
197             <varlistentry>
198               <term><option>DRIVERS</option></term>
199               <listitem>
200                 <para>Search the devpath upwards for a matching device driver name.</para>
201               </listitem>
202             </varlistentry>
203
204             <varlistentry>
205               <term><option>ATTRS{<replaceable>filename</replaceable>}</option></term>
206               <listitem>
207                 <para>Search the devpath upwards for a device with matching sysfs attribute values.
208                 Up to five <option>ATTRS</option> keys can be specified per rule. All attributes
209                 must match on the same device. Trailing whitespace in the attribute values is ignored,
210                 if the specified match value does not contain trailing whitespace itself.</para>
211               </listitem>
212             </varlistentry>
213
214             <varlistentry>
215               <term><option>ENV{<replaceable>key</replaceable>}</option></term>
216               <listitem>
217                 <para>Match against the value of an environment variable. Up to five <option>ENV</option>
218                 keys can be specified per rule. Depending on the type of operator, this key is also used
219                 to export a variable to the environment.</para>
220               </listitem>
221             </varlistentry>
222
223             <varlistentry>
224               <term><option>PROGRAM</option></term>
225               <listitem>
226                 <para>Execute external program. The key is true, if the program returns
227                 without exit code zero. The whole event environment is available to the
228                 executed program. The program's output printed to stdout is available for
229                 the RESULT key.</para>
230               </listitem>
231             </varlistentry>
232
233             <varlistentry>
234               <term><option>RESULT</option></term>
235               <listitem>
236                 <para>Match the returned string of the last PROGRAM call. This key can
237                 be used in the same or in any later rule after a PROGRAM call.</para>
238               </listitem>
239             </varlistentry>
240           </variablelist>
241
242           <para>Most of the fields support a shell style pattern matching. The following
243           pattern characters are supported:</para>
244           <variablelist>
245             <varlistentry>
246               <term><option>*</option></term>
247               <listitem>
248                 <para>Matches zero, or any number of characters.</para>
249               </listitem>
250             </varlistentry>
251             <varlistentry>
252               <term><option>?</option></term>
253               <listitem>
254                 <para>Matches any single character.</para>
255               </listitem>
256             </varlistentry>
257             <varlistentry>
258               <term><option>[]</option></term>
259               <listitem>
260                 <para>Matches any single character specified within the brackets. For
261                 example, the pattern string 'tty[SR]' would match either 'ttyS' or 'ttyR'.
262                 Ranges are also supported within this match with the '-' character.
263                 For example, to match on the range of all digits, the pattern [0-9] would
264                 be used. If the first character following the '[' is a '!', any characters
265                 not enclosed are matched.</para>
266               </listitem>
267             </varlistentry>
268           </variablelist>
269
270           <para>The following keys can get values assigned:</para>
271           <variablelist>
272             <varlistentry>
273               <term><option>NAME</option></term>
274               <listitem>
275                 <para>The name of the node to be created, or the name the network interface
276                 should be renamed to. Only one rule can set the node name, all later rules with
277                 a NAME key will be ignored.</para>
278               </listitem>
279             </varlistentry>
280
281             <varlistentry>
282               <term><option>SYMLINK</option></term>
283               <listitem>
284                 <para>The name of a symlink targeting the node. Every matching rule can add
285                 this value to the list of symlinks to be created along with the device  node.
286                 Multiple symlinks may be specified by separating the names by the space
287                 character.</para>
288               </listitem>
289             </varlistentry>
290
291             <varlistentry>
292               <term><option>OWNER, GROUP, MODE</option></term>
293               <listitem>
294                 <para>The permissions for the device node. Every specified value overwrites
295                 the compiled-in default value.</para>
296               </listitem>
297             </varlistentry>
298
299             <varlistentry>
300               <term><option>ATTR{<replaceable>key</replaceable>}</option></term>
301               <listitem>
302                 <para>The value that should be written to a sysfs attribute of the
303                 event device. Depending on the type of operator, this key is also
304                 used to match against the value of a sysfs attribute.</para>
305               </listitem>
306             </varlistentry>
307
308             <varlistentry>
309               <term><option>ENV{<replaceable>key</replaceable>}</option></term>
310               <listitem>
311                 <para>Export a variable to the environment. Depending on the type of operator,
312                 this key is also to match against an environment variable.</para>
313               </listitem>
314             </varlistentry>
315
316             <varlistentry>
317               <term><option>RUN</option></term>
318               <listitem>
319                 <para>Add a program to the list of programs to be executed for a specific
320                 device. This can only be used for very short running tasks. Running an
321                 event process for a long period of time may block all further events for
322                 this or a dependent device. Long running tasks need to be immediately
323                 detached from the event process itself.</para>
324               </listitem>
325             </varlistentry>
326
327             <varlistentry>
328               <term><option>LABEL</option></term>
329               <listitem>
330                 <para>Named label where a GOTO can jump to.</para>
331               </listitem>
332             </varlistentry>
333
334             <varlistentry>
335               <term><option>GOTO</option></term>
336               <listitem>
337                 <para>Jumps to the next LABEL with a matching name</para>
338               </listitem>
339             </varlistentry>
340
341             <varlistentry>
342               <term><option>IMPORT{<replaceable>type</replaceable>}</option></term>
343               <listitem>
344                 <para>Import the printed result or the value of a file in environment key
345                 format into the event environment. <option>program</option> will execute an
346                 external program and read its output. <option>file</option> will import a
347                 text file. If no option is given, udev will determine it from the  executable
348                 bit of of the file permissions.</para>
349               </listitem>
350             </varlistentry>
351
352             <varlistentry>
353               <term><option>WAIT_FOR_SYSFS</option></term>
354               <listitem>
355                 <para>Wait for the specified sysfs file of the device to be created. Can be used
356                 to fight against kernel sysfs timing issues.</para>
357               </listitem>
358             </varlistentry>
359
360             <varlistentry>
361               <term><option>OPTIONS</option></term>
362               <listitem>
363                 <para><option>last_rule</option> stops further rules application. No later rules
364                 will have any effect.
365                 <option>ignore_device</option> will ignore this event completely.
366                 <option>ignore_remove</option> will ignore  any  later  remove  event  for  this
367                 device. This may be useful as a workaround for broken device drivers.
368                 <option>all_partitions</option> will create the device nodes for all available
369                 partitions of a block device. This may be useful for removable media devices where
370                 media changes are not detected.</para>
371               </listitem>
372             </varlistentry>
373           </variablelist>
374
375           <para>The <option>NAME</option>, <option>SYMLINK</option>, <option>PROGRAM</option>,
376           <option>OWNER</option>, <option>GROUP</option>  and  <option>RUN</option>
377           fields support simple printf-like string substitutions. The <option>RUN</option>
378           format chars gets applied after all rules have been processed, right before the program
379           is executed. It allows the use of the complete environment set by earlier matching
380           rules. For all other fields, substitutions are applied while the individual rule is
381           being processed. The available substitutions are:</para>
382           <variablelist>
383             <varlistentry>
384               <term><option>$kernel</option>, <option>%k</option></term>
385               <listitem>
386                 <para>The kernel name for this device.</para>
387               </listitem>
388             </varlistentry>
389
390             <varlistentry>
391               <term><option>$number</option>, <option>%n</option></term>
392               <listitem>
393                 <para>The kernel number for this device. For example, 'sda3' has
394                 kernel number of '3'</para>
395               </listitem>
396             </varlistentry>
397
398             <varlistentry>
399               <term><option>$devpath</option>, <option>%p</option></term>
400               <listitem>
401                 <para>The devpath of the device.</para>
402               </listitem>
403             </varlistentry>
404
405             <varlistentry>
406               <term><option>$id</option>, <option>%b</option></term>
407               <listitem>
408                 <para>The name of the device matched while searching the devpath upwards for
409                   <option>SUBSYSTEMS</option>, <option>KERNELS</option>, <option>DRIVERS</option> and <option>ATTRS</option>.
410                 </para>
411               </listitem>
412             </varlistentry>
413
414             <varlistentry>
415               <term><option>$attr{<replaceable>file</replaceable>}</option>, <option>%s{<replaceable>file</replaceable>}</option></term>
416               <listitem>
417                 <para>The value of a sysfs attribute found at the device, where
418                 all keys of the rule have matched. If the matching device does not have
419                 such an attribute, all devices along the chain of parents are searched
420                 for a matching attribute.
421                 If the attribute is a symlink, the last element of the symlink target is
422                 returned as the value.</para>
423               </listitem>
424             </varlistentry>
425
426             <varlistentry>
427               <term><option>$env{<replaceable>key</replaceable>}</option>, <option>%E{<replaceable>key</replaceable>}</option></term>
428               <listitem>
429                 <para>The value of an environment variable.</para>
430               </listitem>
431             </varlistentry>
432
433             <varlistentry>
434               <term><option>$major</option>, <option>%M</option></term>
435               <listitem>
436                 <para>The kernel major number for the device.</para>
437               </listitem>
438             </varlistentry>
439
440             <varlistentry>
441               <term><option>$minor</option> <option>%m</option></term>
442               <listitem>
443                 <para>The kernel minor number for the device.</para>
444               </listitem>
445             </varlistentry>
446
447             <varlistentry>
448               <term><option>$result</option>, <option>%c</option></term>
449               <listitem>
450                 <para>The string returned by the external program requested with PROGRAM.
451                 A single part of the string, separated by a space character may be selected
452                 by specifying the part number as an attribute: <option>%c{N}</option>.
453                 If the number is followed by the '+' char this part plus all remaining parts
454                 of the result string are substituted: <option>%c{N+}</option></para>
455               </listitem>
456             </varlistentry>
457
458             <varlistentry>
459               <term><option>$parent</option>, <option>%P</option></term>
460               <listitem>
461                 <para>The node name of the parent device.</para>
462               </listitem>
463             </varlistentry>
464
465             <varlistentry>
466               <term><option>$root</option>, <option>%r</option></term>
467               <listitem>
468                 <para>The udev_root value.</para>
469               </listitem>
470             </varlistentry>
471
472             <varlistentry>
473               <term><option>$tempnode</option>, <option>%N</option></term>
474               <listitem>
475                 <para>The name of a created temporary device node to provide access to
476                 the device from a external program before the real node is created.</para>
477               </listitem>
478             </varlistentry>
479
480             <varlistentry>
481               <term><option>%%</option></term>
482               <listitem>
483               <para>The '%' character itself.</para>
484               </listitem>
485             </varlistentry>
486
487             <varlistentry>
488               <term><option>$$</option></term>
489               <listitem>
490               <para>The '$' character itself.</para>
491               </listitem>
492             </varlistentry>
493           </variablelist>
494           <para>The count of characters to be substituted may be limited by specifying
495           the format length value. For example, '%3s{file}' will only
496           insert the first three characters of the sysfs attribute</para>
497         </refsect2>
498       </refsect1>
499
500       <refsect1><title>AUTHOR</title>
501         <para>Written by Greg Kroah-Hartman <email>greg@kroah.com</email> and
502         Kay Sievers <email>kay.sievers@vrfy.org</email>. With much help from
503         Dan  Stekloff <email>dsteklof@us.ibm.com</email> and many others.</para>
504       </refsect1>
505
506       <refsect1>
507         <title>SEE ALSO</title>
508         <para><citerefentry>
509             <refentrytitle>udevd</refentrytitle><manvolnum>8</manvolnum>
510           </citerefentry>, 
511           <citerefentry>
512             <refentrytitle>udevinfo</refentrytitle><manvolnum>8</manvolnum>
513           </citerefentry>, 
514           <citerefentry>
515             <refentrytitle>udevmonitor</refentrytitle><manvolnum>8</manvolnum>
516         </citerefentry></para>
517       </refsect1>
518     </refentry>
519   </section>
520 </article>