chiark / gitweb /
nspawn: add --read-only switch
[elogind.git] / man / udev.xml
1 <?xml version='1.0'?>
2 <?xml-stylesheet type="text/xsl" href="http://docbook.sourceforge.net/release/xsl/current/xhtml/docbook.xsl"?>
3 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
4   "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
5
6 <refentry id="udev">
7   <refentryinfo>
8     <title>udev</title>
9     <productname>systemd</productname>
10     <authorgroup>
11       <author>
12         <contrib>Developer</contrib>
13         <firstname>Greg</firstname>
14         <surname>Kroah-Hartmann</surname>
15         <email>greg@kroah.com</email>
16       </author>
17       <author>
18         <contrib>Developer</contrib>
19         <firstname>Kay</firstname>
20         <surname>Sievers</surname>
21         <email>kay@vrfy.org</email>
22       </author>
23     </authorgroup>
24   </refentryinfo>
25
26   <refmeta>
27     <refentrytitle>udev</refentrytitle>
28     <manvolnum>7</manvolnum>
29   </refmeta>
30
31   <refnamediv>
32     <refname>udev</refname>
33     <refpurpose>Linux dynamic device management</refpurpose>
34   </refnamediv>
35
36   <refsect1><title>Description</title>
37     <para>udev supplies the system software with device events, manages permissions
38     of device nodes and may create additional symlinks in the <filename>/dev</filename>
39     directory, or renames network interfaces. The kernel usually just assigns unpredictable
40     device names based on the order of discovery. Meaningful symlinks or network device
41     names provide a way to reliably identify devices based on their properties or
42     current configuration.</para>
43
44     <para>The udev daemon, <citerefentry><refentrytitle>systemd-udevd</refentrytitle>
45     <manvolnum>8</manvolnum></citerefentry>, receives device uevents directly from
46     the kernel whenever a device is added or removed from the system, or it changes its
47     state. When udev receives a device event, it matches its configured set of rules
48     against various device attributes to identify the device. Rules that match may
49     provide additional device information to be stored in the udev database or
50     to be used to create meaningful symlink names.</para>
51
52     <para>All device information udev processes is stored in the udev database and
53     sent out to possible event subscribers. Access to all stored data and the event
54     sources is provided by the library libudev.</para>
55   </refsect1>
56
57   <refsect1><title>Configuration</title>
58     <para>udev configuration files are placed in <filename>/etc/udev</filename>
59     and <filename>/usr/lib/udev</filename>. All empty lines or lines beginning with
60     '#' are ignored.</para>
61
62     <refsect2><title>Configuration file</title>
63       <para>udev expects its main configuration file at <filename>/etc/udev/udev.conf</filename>.
64       It consists of a set of variables allowing the user to override default udev values.
65       The following variables can be set:</para>
66       <variablelist>
67         <varlistentry>
68           <term><option>udev_log</option></term>
69           <listitem>
70             <para>The logging priority. Valid values are the numerical syslog priorities
71             or their textual representations: <option>err</option>, <option>info</option>
72             and <option>debug</option>.</para>
73           </listitem>
74         </varlistentry>
75       </variablelist>
76     </refsect2>
77
78     <refsect2><title>Rules files</title>
79       <para>The udev rules are read from the files located in the
80       system rules directory <filename>/usr/lib/udev/rules.d</filename>,
81       the volatile runtime directory <filename>/run/udev/rules.d</filename>
82       and the local administration directory <filename>/etc/udev/rules.d</filename>.
83       All rules files are collectively sorted and processed in lexical order,
84       regardless of the directories in which they live. However, files with
85       identical file names replace each other. Files in <filename>/etc</filename>
86       have the highest priority, files in <filename>/run</filename> take precedence
87       over files with the same name in <filename>/lib</filename>. This can be
88       used to override a system-supplied rules file with a local file if needed;
89       a symlink in <filename>/etc</filename> with the same name as a rules file in
90       <filename>/lib</filename>, pointing to <filename>/dev/null</filename>,
91       disables the rules file entirely.</para>
92
93       <para>Rule files must have the extension <filename>.rules</filename>; other
94       extensions are ignored.</para>
95
96       <para>Every line in the rules file contains at least one key-value pair.
97       There are two kind of keys: match and assignment.
98       If all match keys are matching against its value, the rule gets applied and the
99       assignment keys get the specified value assigned.</para>
100
101       <para>A matching rule may rename a network interface, add symlinks
102       pointing to the device node, or run a specified program as part of
103       the event handling.</para>
104
105       <para>A rule consists of a comma-separated list of one or more key-value pairs.
106       Each key has a distinct operation, depending on the used operator. Valid
107       operators are:</para>
108       <variablelist>
109         <varlistentry>
110           <term><option>==</option></term>
111           <listitem>
112             <para>Compare for equality.</para>
113           </listitem>
114         </varlistentry>
115
116         <varlistentry>
117           <term><option>!=</option></term>
118           <listitem>
119             <para>Compare for inequality.</para>
120           </listitem>
121         </varlistentry>
122
123         <varlistentry>
124           <term><option>=</option></term>
125           <listitem>
126             <para>Assign a value to a key. Keys that represent a list are reset
127             and only this single value is assigned.</para>
128           </listitem>
129         </varlistentry>
130
131         <varlistentry>
132           <term><option>+=</option></term>
133           <listitem>
134             <para>Add the value to a key that holds a list of entries.</para>
135           </listitem>
136         </varlistentry>
137
138         <varlistentry>
139           <term><option>:=</option></term>
140           <listitem>
141             <para>Assign  a  value  to  a key finally; disallow any later changes.</para>
142           </listitem>
143         </varlistentry>
144       </variablelist>
145
146       <para>The following key names can be used to match against device properties.
147       Some of the keys also match against properties of the parent devices in sysfs,
148       not only the device that has generated the event. If multiple keys that match
149       a parent device are specified in a single rule, all these keys must match at
150       one and the same parent device.</para>
151       <variablelist>
152         <varlistentry>
153           <term><option>ACTION</option></term>
154           <listitem>
155             <para>Match the name of the event action.</para>
156           </listitem>
157         </varlistentry>
158
159         <varlistentry>
160           <term><option>DEVPATH</option></term>
161           <listitem>
162             <para>Match the devpath of the event device.</para>
163           </listitem>
164         </varlistentry>
165
166         <varlistentry>
167           <term><option>KERNEL</option></term>
168           <listitem>
169             <para>Match the name of the event device.</para>
170           </listitem>
171         </varlistentry>
172
173         <varlistentry>
174           <term><option>NAME</option></term>
175           <listitem>
176             <para>Match the name of a network interface. It can be used once the
177             NAME key has been set in one of the preceding rules.</para>
178           </listitem>
179         </varlistentry>
180
181         <varlistentry>
182           <term><option>SYMLINK</option></term>
183           <listitem>
184             <para>Match the name of a symlink targeting the node. It can
185             be used once a SYMLINK key has been set in one of the preceding
186             rules. There may be multiple symlinks; only one needs to match.
187             </para>
188           </listitem>
189         </varlistentry>
190
191         <varlistentry>
192           <term><option>SUBSYSTEM</option></term>
193           <listitem>
194             <para>Match the subsystem of the event device.</para>
195           </listitem>
196         </varlistentry>
197         <varlistentry>
198           <term><option>DRIVER</option></term>
199           <listitem>
200             <para>Match the driver name of the event device. Only set this key for devices
201             which are bound to a driver at the time the event is generated.</para>
202           </listitem>
203         </varlistentry>
204         <varlistentry>
205           <term><option>ATTR{<replaceable>filename</replaceable>}</option></term>
206           <listitem>
207             <para>Match sysfs attribute values of the event device. Trailing
208             whitespace in the attribute values is ignored unless the specified match
209             value itself contains trailing whitespace.
210             </para>
211           </listitem>
212         </varlistentry>
213
214         <varlistentry>
215           <term><option>KERNELS</option></term>
216           <listitem>
217             <para>Search the devpath upwards for a matching device name.</para>
218           </listitem>
219         </varlistentry>
220
221         <varlistentry>
222           <term><option>SUBSYSTEMS</option></term>
223           <listitem>
224             <para>Search the devpath upwards for a matching device subsystem name.</para>
225           </listitem>
226         </varlistentry>
227
228         <varlistentry>
229           <term><option>DRIVERS</option></term>
230           <listitem>
231             <para>Search the devpath upwards for a matching device driver name.</para>
232           </listitem>
233         </varlistentry>
234
235         <varlistentry>
236           <term><option>ATTRS{<replaceable>filename</replaceable>}</option></term>
237           <listitem>
238             <para>Search the devpath upwards for a device with matching sysfs attribute values.
239             If multiple <option>ATTRS</option> matches are specified, all of them
240             must match on the same device. Trailing whitespace in the attribute values is ignored
241             unless the specified match value itself contains trailing whitespace.</para>
242           </listitem>
243         </varlistentry>
244
245         <varlistentry>
246           <term><option>TAGS</option></term>
247           <listitem>
248             <para>Search the devpath upwards for a device with matching tag.</para>
249           </listitem>
250         </varlistentry>
251
252         <varlistentry>
253           <term><option>ENV{<replaceable>key</replaceable>}</option></term>
254           <listitem>
255             <para>Match against a device property value.</para>
256           </listitem>
257         </varlistentry>
258
259         <varlistentry>
260           <term><option>TAG</option></term>
261           <listitem>
262             <para>Match against a device tag.</para>
263           </listitem>
264         </varlistentry>
265
266         <varlistentry>
267           <term><option>TEST{<replaceable>octal mode mask</replaceable>}</option></term>
268           <listitem>
269             <para>Test the existence of a file. An octal mode mask can be specified
270             if needed.</para>
271           </listitem>
272         </varlistentry>
273
274         <varlistentry>
275           <term><option>PROGRAM</option></term>
276           <listitem>
277             <para>Execute a program to determine whether there
278             is a match; the key is true if the program returns
279             successfully. The device properties are made available to the
280             executed program in the environment. The program's stdout
281             is available in the RESULT key.</para>
282             <para>This can only be used for very short-running foreground tasks. For details
283             see <option>RUN</option>.</para>
284           </listitem>
285         </varlistentry>
286
287         <varlistentry>
288           <term><option>RESULT</option></term>
289           <listitem>
290             <para>Match the returned string of the last PROGRAM call. This key can
291             be used in the same or in any later rule after a PROGRAM call.</para>
292           </listitem>
293         </varlistentry>
294       </variablelist>
295
296       <para>Most of the fields support shell-style pattern matching. The following
297       pattern characters are supported:</para>
298       <variablelist>
299         <varlistentry>
300           <term><option>*</option></term>
301           <listitem>
302             <para>Matches zero or more characters.</para>
303           </listitem>
304         </varlistentry>
305         <varlistentry>
306           <term><option>?</option></term>
307           <listitem>
308             <para>Matches any single character.</para>
309           </listitem>
310         </varlistentry>
311         <varlistentry>
312           <term><option>[]</option></term>
313           <listitem>
314             <para>Matches any single character specified within the brackets. For
315             example, the pattern string 'tty[SR]' would match either 'ttyS' or 'ttyR'.
316             Ranges are also supported via the '-' character.
317             For example, to match on the range of all digits, the pattern [0-9] could
318             be used. If the first character following the '[' is a '!', any characters
319             not enclosed are matched.</para>
320           </listitem>
321         </varlistentry>
322       </variablelist>
323
324       <para>The following keys can get values assigned:</para>
325       <variablelist>
326         <varlistentry>
327           <term><option>NAME</option></term>
328           <listitem>
329             <para>The name to use for a network interface. The name of a device node
330             can not be changed by udev, only additional symlinks can be created.</para>
331           </listitem>
332         </varlistentry>
333
334         <varlistentry>
335           <term><option>SYMLINK</option></term>
336           <listitem>
337             <para>The name of a symlink targeting the node. Every matching rule adds
338             this value to the list of symlinks to be created. Multiple symlinks may be
339             specified by separating the names by the space character. In case multiple
340             devices claim the same name, the link always points to the device with
341             the highest link_priority. If the current device goes away, the links are
342             re-evaluated and the device with the next highest link_priority becomes the owner of
343             the link. If no link_priority is specified, the order of the devices (and
344             which one of them owns the link) is undefined. Also, symlink names must
345             never conflict with the kernel's default device node names, as that would
346             result in unpredictable behavior.
347             </para>
348           </listitem>
349         </varlistentry>
350
351         <varlistentry>
352           <term><option>OWNER, GROUP, MODE</option></term>
353           <listitem>
354             <para>The permissions for the device node. Every specified value overrides
355             the compiled-in default value.</para>
356           </listitem>
357         </varlistentry>
358
359         <varlistentry>
360           <term><option>ATTR{<replaceable>key</replaceable>}</option></term>
361           <listitem>
362             <para>The value that should be written to a sysfs attribute of the
363             event device.</para>
364           </listitem>
365         </varlistentry>
366
367         <varlistentry>
368           <term><option>ENV{<replaceable>key</replaceable>}</option></term>
369           <listitem>
370             <para>Set a device property value. Property names with a leading '.'
371             are neither stored in the database nor exported to events or
372             external tools (run by, say, the PROGRAM match key).</para>
373           </listitem>
374         </varlistentry>
375
376         <varlistentry>
377           <term><option>TAG</option></term>
378           <listitem>
379             <para>Attach a tag to a device. This is used to filter events for users
380             of libudev's monitor functionality, or to enumerate a group of tagged
381             devices. The implementation can only work efficiently if only a few
382             tags are attached to a device. It is only meant to be used in
383             contexts with specific device filter requirements, and not as a
384             general-purpose flag. Excessive use might result in inefficient event
385             handling.</para>
386           </listitem>
387         </varlistentry>
388
389         <varlistentry>
390           <term><option>RUN</option></term>
391           <listitem>
392             <para>Add a program to the list of programs to be executed for a specific
393             device.</para>
394             <para>If no absolute path is given, the program is expected to live in
395             /usr/lib/udev, otherwise the absolute path must be specified. The program
396             name and following arguments are separated by spaces. Single quotes can
397             be used to specify arguments with spaces.</para>
398             <para>This can only be used for very short-running foreground tasks. Running an
399             event process for a long period of time may block all further events for
400             this or a dependent device.</para>
401             <para>Starting daemons or other long running processes is not appropriate
402             for udev; the forked processes, detached or not, will be unconditionally
403             killed after the event handling has finished.</para>
404           </listitem>
405         </varlistentry>
406
407         <varlistentry>
408           <term><option>LABEL</option></term>
409           <listitem>
410             <para>A named label to which a GOTO may jump.</para>
411           </listitem>
412         </varlistentry>
413
414         <varlistentry>
415           <term><option>GOTO</option></term>
416           <listitem>
417             <para>Jumps to the next LABEL with a matching name.</para>
418           </listitem>
419         </varlistentry>
420
421         <varlistentry>
422           <term><option>IMPORT{<replaceable>type</replaceable>}</option></term>
423           <listitem>
424             <para>Import a set of variables as device properties,
425             depending on <replaceable>type</replaceable>:</para>
426             <variablelist>
427               <varlistentry>
428                 <term><option>program</option></term>
429                 <listitem>
430                   <para>Execute an external program specified as the assigned value and
431                   import its output, which must be in environment key
432                   format. Path specification, command/argument separation,
433                   and quoting work like in <option>RUN</option>.</para>
434                 </listitem>
435               </varlistentry>
436               <varlistentry>
437                 <term><option>file</option></term>
438                 <listitem>
439                   <para>Import a text file specified as the assigned value, the content
440                   of which must be in environment key format.</para>
441                 </listitem>
442               </varlistentry>
443               <varlistentry>
444                 <term><option>db</option></term>
445                 <listitem>
446                   <para>Import a single property specified as the assigned value from the
447                   current device database. This works only if the database is already populated
448                   by an earlier event.</para>
449                 </listitem>
450               </varlistentry>
451               <varlistentry>
452                 <term><option>cmdline</option></term>
453                 <listitem>
454                   <para>Import a single property from the kernel command line. For simple flags
455                   the value of the property is set to '1'.</para>
456                 </listitem>
457               </varlistentry>
458               <varlistentry>
459                 <term><option>parent</option></term>
460                 <listitem>
461                   <para>Import the stored keys from the parent device by reading
462                   the database entry of the parent device. The value assigned to
463                   <option>IMPORT{parent}</option> is used as a filter of key names
464                   to import (with the same shell-style pattern matching used for
465                   comparisons).</para>
466                 </listitem>
467               </varlistentry>
468             </variablelist>
469             <para>This can only be used for very short-running foreground tasks. For details
470             see <option>RUN</option>.</para>
471           </listitem>
472         </varlistentry>
473
474         <varlistentry>
475           <term><option>WAIT_FOR</option></term>
476           <listitem>
477             <para>Wait for a file to become available or until a timeout of
478             10 seconds expires. The path is relative to the sysfs device;
479             if no path is specified, this waits for an attribute to appear.</para>
480           </listitem>
481         </varlistentry>
482
483         <varlistentry>
484           <term><option>OPTIONS</option></term>
485           <listitem>
486             <para>Rule and device options:</para>
487             <variablelist>
488               <varlistentry>
489                 <term><option>link_priority=<replaceable>value</replaceable></option></term>
490                 <listitem>
491                   <para>Specify the priority of the created symlinks. Devices with higher
492                   priorities overwrite existing symlinks of other devices. The default is 0.</para>
493                 </listitem>
494               </varlistentry>
495               <varlistentry>
496                 <term><option>event_timeout=</option></term>
497                 <listitem>
498                   <para>Number of seconds an event waits for operations to finish before
499                   giving up and terminating itself.</para>
500                 </listitem>
501               </varlistentry>
502               <varlistentry>
503                 <term><option>string_escape=<replaceable>none|replace</replaceable></option></term>
504                 <listitem>
505                   <para>Usually control and other possibly unsafe characters are replaced
506                   in strings used for device naming. The mode of replacement can be specified
507                   with this option.</para>
508                 </listitem>
509               </varlistentry>
510               <varlistentry>
511                 <term><option>static_node=</option></term>
512                 <listitem>
513                   <para>Apply the permissions specified in this rule to the static device node with
514                   the specified name. Static device node creation can be requested by kernel modules.
515                   These nodes might not have a corresponding kernel device at the time systemd-udevd is
516                   started; they can trigger automatic kernel module loading.</para>
517                 </listitem>
518               </varlistentry>
519               <varlistentry>
520                 <term><option>watch</option></term>
521                 <listitem>
522                   <para>Watch the device node with inotify; when the node is closed after being opened for
523                   writing, a change uevent is synthesized.</para>
524                 </listitem>
525               </varlistentry>
526               <varlistentry>
527                 <term><option>nowatch</option></term>
528                 <listitem>
529                   <para>Disable the watching of a device node with inotify.</para>
530                 </listitem>
531               </varlistentry>
532             </variablelist>
533           </listitem>
534         </varlistentry>
535       </variablelist>
536
537       <para>The <option>NAME</option>, <option>SYMLINK</option>, <option>PROGRAM</option>,
538       <option>OWNER</option>, <option>GROUP</option>, <option>MODE</option>  and  <option>RUN</option>
539       fields support simple string substitutions. The <option>RUN</option>
540       substitutions are performed after all rules have been processed, right before the program
541       is executed, allowing for the use of device properties set by earlier matching
542       rules. For all other fields, substitutions are performed while the individual rule is
543       being processed. The available substitutions are:</para>
544       <variablelist>
545         <varlistentry>
546           <term><option>$kernel</option>, <option>%k</option></term>
547           <listitem>
548             <para>The kernel name for this device.</para>
549           </listitem>
550         </varlistentry>
551
552         <varlistentry>
553           <term><option>$number</option>, <option>%n</option></term>
554           <listitem>
555             <para>The kernel number for this device. For example, 'sda3' has
556             kernel number of '3'</para>
557           </listitem>
558         </varlistentry>
559
560         <varlistentry>
561           <term><option>$devpath</option>, <option>%p</option></term>
562           <listitem>
563             <para>The devpath of the device.</para>
564           </listitem>
565         </varlistentry>
566
567         <varlistentry>
568           <term><option>$id</option>, <option>%b</option></term>
569           <listitem>
570             <para>The name of the device matched while searching the devpath upwards for
571               <option>SUBSYSTEMS</option>, <option>KERNELS</option>, <option>DRIVERS</option> and <option>ATTRS</option>.
572             </para>
573           </listitem>
574         </varlistentry>
575
576         <varlistentry>
577           <term><option>$driver</option></term>
578           <listitem>
579             <para>The driver name of the device matched while searching the devpath upwards for
580               <option>SUBSYSTEMS</option>, <option>KERNELS</option>, <option>DRIVERS</option> and <option>ATTRS</option>.
581             </para>
582           </listitem>
583         </varlistentry>
584
585         <varlistentry>
586           <term><option>$attr{<replaceable>file</replaceable>}</option>, <option>%s{<replaceable>file</replaceable>}</option></term>
587           <listitem>
588             <para>The value of a sysfs attribute found at the device where
589             all keys of the rule have matched. If the matching device does not have
590             such an attribute, and a previous KERNELS, SUBSYSTEMS, DRIVERS, or
591             ATTRS test selected a parent device, then the attribute from that
592             parent device is used.</para>
593             <para>If the attribute is a symlink, the last element of the symlink target is
594             returned as the value.</para>
595           </listitem>
596         </varlistentry>
597
598         <varlistentry>
599           <term><option>$env{<replaceable>key</replaceable>}</option>, <option>%E{<replaceable>key</replaceable>}</option></term>
600           <listitem>
601             <para>A device property value.</para>
602           </listitem>
603         </varlistentry>
604
605         <varlistentry>
606           <term><option>$major</option>, <option>%M</option></term>
607           <listitem>
608             <para>The kernel major number for the device.</para>
609           </listitem>
610         </varlistentry>
611
612         <varlistentry>
613           <term><option>$minor</option>, <option>%m</option></term>
614           <listitem>
615             <para>The kernel minor number for the device.</para>
616           </listitem>
617         </varlistentry>
618
619         <varlistentry>
620           <term><option>$result</option>, <option>%c</option></term>
621           <listitem>
622             <para>The string returned by the external program requested with PROGRAM.
623             A single part of the string, separated by a space character, may be selected
624             by specifying the part number as an attribute: <option>%c{N}</option>.
625             If the number is followed by the '+' character, this part plus all remaining parts
626             of the result string are substituted: <option>%c{N+}</option></para>
627           </listitem>
628         </varlistentry>
629
630         <varlistentry>
631           <term><option>$parent</option>, <option>%P</option></term>
632           <listitem>
633             <para>The node name of the parent device.</para>
634           </listitem>
635         </varlistentry>
636
637         <varlistentry>
638           <term><option>$name</option></term>
639           <listitem>
640             <para>The current name of the device. If not changed by a rule, it is the
641             name of the kernel device.</para>
642           </listitem>
643         </varlistentry>
644
645         <varlistentry>
646           <term><option>$links</option></term>
647           <listitem>
648             <para>A space-separated list of the current symlinks. The value is
649             only set during a remove event or if an earlier rule assigned a value.</para>
650           </listitem>
651         </varlistentry>
652
653         <varlistentry>
654           <term><option>$root</option>, <option>%r</option></term>
655           <listitem>
656             <para>The udev_root value.</para>
657           </listitem>
658         </varlistentry>
659
660         <varlistentry>
661           <term><option>$sys</option>, <option>%S</option></term>
662           <listitem>
663             <para>The sysfs mount point.</para>
664           </listitem>
665         </varlistentry>
666
667         <varlistentry>
668           <term><option>$devnode</option>, <option>%N</option></term>
669           <listitem>
670             <para>The name of the device node.</para>
671           </listitem>
672         </varlistentry>
673
674         <varlistentry>
675           <term><option>%%</option></term>
676           <listitem>
677           <para>The '%' character itself.</para>
678           </listitem>
679         </varlistentry>
680
681         <varlistentry>
682           <term><option>$$</option></term>
683           <listitem>
684           <para>The '$' character itself.</para>
685           </listitem>
686         </varlistentry>
687       </variablelist>
688     </refsect2>
689   </refsect1>
690
691   <refsect1>
692     <title>See Also</title>
693     <para><citerefentry>
694         <refentrytitle>systemd-udevd</refentrytitle><manvolnum>8</manvolnum>
695       </citerefentry>,
696       <citerefentry>
697         <refentrytitle>udevadm</refentrytitle><manvolnum>8</manvolnum>
698     </citerefentry></para>
699   </refsect1>
700 </refentry>