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">
9 <productname>systemd</productname>
12 <contrib>Developer</contrib>
13 <firstname>Greg</firstname>
14 <surname>Kroah-Hartmann</surname>
15 <email>greg@kroah.com</email>
18 <contrib>Developer</contrib>
19 <firstname>Kay</firstname>
20 <surname>Sievers</surname>
21 <email>kay@vrfy.org</email>
27 <refentrytitle>udev</refentrytitle>
28 <manvolnum>7</manvolnum>
32 <refname>udev</refname>
33 <refpurpose>Linux dynamic device management</refpurpose>
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>
44 <para>The udev daemon, <citerefentry><refentrytitle>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>
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>
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>
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>
68 <term><option>udev_root</option></term>
70 <para>Specifies where to place the device nodes in the filesystem.
71 The default value is <filename>/dev</filename>.</para>
76 <term><option>udev_log</option></term>
78 <para>The logging priority. Valid values are the numerical syslog priorities
79 or their textual representations: <option>err</option>, <option>info</option>
80 and <option>debug</option>.</para>
86 <refsect2><title>Rules files</title>
87 <para>The udev rules are read from the files located in the
88 system rules directory <filename>/usr/lib/udev/rules.d</filename>,
89 the volatile runtime directory <filename>/run/udev/rules.d</filename>
90 and the local administration directory <filename>/etc/udev/rules.d</filename>.
91 All rules files are collectively sorted and processed in lexical order,
92 regardless of the directories in which they live. However, files with
93 identical file names replace each other. Files in <filename>/etc</filename>
94 have the highest priority, files in <filename>/run</filename> take precedence
95 over files with the same name in <filename>/lib</filename>. This can be
96 used to override a system-supplied rules file with a local file if needed;
97 a symlink in <filename>/etc</filename> with the same name as a rules file in
98 <filename>/lib</filename>, pointing to <filename>/dev/null</filename>,
99 disables the rules file entirely.</para>
101 <para>Rule files must have the extension <filename>.rules</filename>; other
102 extensions are ignored.</para>
104 <para>Every line in the rules file contains at least one key-value pair.
105 There are two kind of keys: match and assignment.
106 If all match keys are matching against its value, the rule gets applied and the
107 assignment keys get the specified value assigned.</para>
109 <para>A matching rule may rename a network interface, add symlinks
110 pointing to the device node, or run a specified program as part of
111 the event handling.</para>
113 <para>A rule consists of a comma-separated list of one or more key-value pairs.
114 Each key has a distinct operation, depending on the used operator. Valid
115 operators are:</para>
118 <term><option>==</option></term>
120 <para>Compare for equality.</para>
125 <term><option>!=</option></term>
127 <para>Compare for inequality.</para>
132 <term><option>=</option></term>
134 <para>Assign a value to a key. Keys that represent a list are reset
135 and only this single value is assigned.</para>
140 <term><option>+=</option></term>
142 <para>Add the value to a key that holds a list of entries.</para>
147 <term><option>:=</option></term>
149 <para>Assign a value to a key finally; disallow any later changes.</para>
154 <para>The following key names can be used to match against device properties.
155 Some of the keys also match against properties of the parent devices in sysfs,
156 not only the device that has generated the event. If multiple keys that match
157 a parent device are specified in a single rule, all these keys must match at
158 one and the same parent device.</para>
161 <term><option>ACTION</option></term>
163 <para>Match the name of the event action.</para>
168 <term><option>DEVPATH</option></term>
170 <para>Match the devpath of the event device.</para>
175 <term><option>KERNEL</option></term>
177 <para>Match the name of the event device.</para>
182 <term><option>NAME</option></term>
184 <para>Match the name of a network interface. It can be used once the
185 NAME key has been set in one of the preceding rules.</para>
190 <term><option>SYMLINK</option></term>
192 <para>Match the name of a symlink targeting the node. It can
193 be used once a SYMLINK key has been set in one of the preceding
194 rules. There may be multiple symlinks; only one needs to match.
200 <term><option>SUBSYSTEM</option></term>
202 <para>Match the subsystem of the event device.</para>
206 <term><option>DRIVER</option></term>
208 <para>Match the driver name of the event device. Only set this key for devices
209 which are bound to a driver at the time the event is generated.</para>
213 <term><option>ATTR{<replaceable>filename</replaceable>}</option></term>
215 <para>Match sysfs attribute values of the event device. Trailing
216 whitespace in the attribute values is ignored unless the specified match
217 value itself contains trailing whitespace.
223 <term><option>KERNELS</option></term>
225 <para>Search the devpath upwards for a matching device name.</para>
230 <term><option>SUBSYSTEMS</option></term>
232 <para>Search the devpath upwards for a matching device subsystem name.</para>
237 <term><option>DRIVERS</option></term>
239 <para>Search the devpath upwards for a matching device driver name.</para>
244 <term><option>ATTRS{<replaceable>filename</replaceable>}</option></term>
246 <para>Search the devpath upwards for a device with matching sysfs attribute values.
247 If multiple <option>ATTRS</option> matches are specified, all of them
248 must match on the same device. Trailing whitespace in the attribute values is ignored
249 unless the specified match value itself contains trailing whitespace.</para>
254 <term><option>TAGS</option></term>
256 <para>Search the devpath upwards for a device with matching tag.</para>
261 <term><option>ENV{<replaceable>key</replaceable>}</option></term>
263 <para>Match against a device property value.</para>
268 <term><option>TAG</option></term>
270 <para>Match against a device tag.</para>
275 <term><option>TEST{<replaceable>octal mode mask</replaceable>}</option></term>
277 <para>Test the existence of a file. An octal mode mask can be specified
283 <term><option>PROGRAM</option></term>
285 <para>Execute a program to determine whether there
286 is a match; the key is true if the program returns
287 successfully. The device properties are made available to the
288 executed program in the environment. The program's stdout
289 is available in the RESULT key.</para>
290 <para>This can only be used for very short-running foreground tasks. For details
291 see <option>RUN</option>.</para>
296 <term><option>RESULT</option></term>
298 <para>Match the returned string of the last PROGRAM call. This key can
299 be used in the same or in any later rule after a PROGRAM call.</para>
304 <para>Most of the fields support shell-style pattern matching. The following
305 pattern characters are supported:</para>
308 <term><option>*</option></term>
310 <para>Matches zero or more characters.</para>
314 <term><option>?</option></term>
316 <para>Matches any single character.</para>
320 <term><option>[]</option></term>
322 <para>Matches any single character specified within the brackets. For
323 example, the pattern string 'tty[SR]' would match either 'ttyS' or 'ttyR'.
324 Ranges are also supported via the '-' character.
325 For example, to match on the range of all digits, the pattern [0-9] could
326 be used. If the first character following the '[' is a '!', any characters
327 not enclosed are matched.</para>
332 <para>The following keys can get values assigned:</para>
335 <term><option>NAME</option></term>
337 <para>The name to use for a network interface. The name of a device node
338 can not be changed by udev, only additional symlinks can be created.</para>
343 <term><option>SYMLINK</option></term>
345 <para>The name of a symlink targeting the node. Every matching rule adds
346 this value to the list of symlinks to be created. Multiple symlinks may be
347 specified by separating the names by the space character. In case multiple
348 devices claim the same name, the link always points to the device with
349 the highest link_priority. If the current device goes away, the links are
350 re-evaluated and the device with the next highest link_priority becomes the owner of
351 the link. If no link_priority is specified, the order of the devices (and
352 which one of them owns the link) is undefined. Also, symlink names must
353 never conflict with the kernel's default device node names, as that would
354 result in unpredictable behavior.
360 <term><option>OWNER, GROUP, MODE</option></term>
362 <para>The permissions for the device node. Every specified value overrides
363 the compiled-in default value.</para>
368 <term><option>ATTR{<replaceable>key</replaceable>}</option></term>
370 <para>The value that should be written to a sysfs attribute of the
376 <term><option>ENV{<replaceable>key</replaceable>}</option></term>
378 <para>Set a device property value. Property names with a leading '.'
379 are neither stored in the database nor exported to events or
380 external tools (run by, say, the PROGRAM match key).</para>
385 <term><option>TAG</option></term>
387 <para>Attach a tag to a device. This is used to filter events for users
388 of libudev's monitor functionality, or to enumerate a group of tagged
389 devices. The implementation can only work efficiently if only a few
390 tags are attached to a device. It is only meant to be used in
391 contexts with specific device filter requirements, and not as a
392 general-purpose flag. Excessive use might result in inefficient event
398 <term><option>RUN</option></term>
400 <para>Add a program to the list of programs to be executed for a specific
402 <para>If no absolute path is given, the program is expected to live in
403 /usr/lib/udev, otherwise the absolute path must be specified. The program
404 name and following arguments are separated by spaces. Single quotes can
405 be used to specify arguments with spaces.</para>
406 <para>This can only be used for very short-running foreground tasks. Running an
407 event process for a long period of time may block all further events for
408 this or a dependent device.</para>
409 <para>Starting daemons or other long running processes is not appropriate
410 for udev; the forked processes, detached or not, will be unconditionally
411 killed after the event handling has finished.</para>
416 <term><option>LABEL</option></term>
418 <para>A named label to which a GOTO may jump.</para>
423 <term><option>GOTO</option></term>
425 <para>Jumps to the next LABEL with a matching name.</para>
430 <term><option>IMPORT{<replaceable>type</replaceable>}</option></term>
432 <para>Import a set of variables as device properties,
433 depending on <replaceable>type</replaceable>:</para>
436 <term><option>program</option></term>
438 <para>Execute an external program specified as the assigned value and
439 import its output, which must be in environment key
440 format. Path specification, command/argument separation,
441 and quoting work like in <option>RUN</option>.</para>
445 <term><option>file</option></term>
447 <para>Import a text file specified as the assigned value, the content
448 of which must be in environment key format.</para>
452 <term><option>db</option></term>
454 <para>Import a single property specified as the assigned value from the
455 current device database. This works only if the database is already populated
456 by an earlier event.</para>
460 <term><option>cmdline</option></term>
462 <para>Import a single property from the kernel command line. For simple flags
463 the value of the property is set to '1'.</para>
467 <term><option>parent</option></term>
469 <para>Import the stored keys from the parent device by reading
470 the database entry of the parent device. The value assigned to
471 <option>IMPORT{parent}</option> is used as a filter of key names
472 to import (with the same shell-style pattern matching used for
477 <para>This can only be used for very short-running foreground tasks. For details
478 see <option>RUN</option>.</para>
483 <term><option>WAIT_FOR</option></term>
485 <para>Wait for a file to become available or until a timeout of
486 10 seconds expires. The path is relative to the sysfs device;
487 if no path is specified, this waits for an attribute to appear.</para>
492 <term><option>OPTIONS</option></term>
494 <para>Rule and device options:</para>
497 <term><option>link_priority=<replaceable>value</replaceable></option></term>
499 <para>Specify the priority of the created symlinks. Devices with higher
500 priorities overwrite existing symlinks of other devices. The default is 0.</para>
504 <term><option>event_timeout=</option></term>
506 <para>Number of seconds an event waits for operations to finish before
507 giving up and terminating itself.</para>
511 <term><option>string_escape=<replaceable>none|replace</replaceable></option></term>
513 <para>Usually control and other possibly unsafe characters are replaced
514 in strings used for device naming. The mode of replacement can be specified
515 with this option.</para>
519 <term><option>static_node=</option></term>
521 <para>Apply the permissions specified in this rule to the static device node with
522 the specified name. Static device node creation can be requested by kernel modules.
523 These nodes might not have a corresponding kernel device at the time udevd is
524 started; they can trigger automatic kernel module loading.</para>
528 <term><option>watch</option></term>
530 <para>Watch the device node with inotify; when the node is closed after being opened for
531 writing, a change uevent is synthesized.</para>
535 <term><option>nowatch</option></term>
537 <para>Disable the watching of a device node with inotify.</para>
545 <para>The <option>NAME</option>, <option>SYMLINK</option>, <option>PROGRAM</option>,
546 <option>OWNER</option>, <option>GROUP</option>, <option>MODE</option> and <option>RUN</option>
547 fields support simple string substitutions. The <option>RUN</option>
548 substitutions are performed after all rules have been processed, right before the program
549 is executed, allowing for the use of device properties set by earlier matching
550 rules. For all other fields, substitutions are performed while the individual rule is
551 being processed. The available substitutions are:</para>
554 <term><option>$kernel</option>, <option>%k</option></term>
556 <para>The kernel name for this device.</para>
561 <term><option>$number</option>, <option>%n</option></term>
563 <para>The kernel number for this device. For example, 'sda3' has
564 kernel number of '3'</para>
569 <term><option>$devpath</option>, <option>%p</option></term>
571 <para>The devpath of the device.</para>
576 <term><option>$id</option>, <option>%b</option></term>
578 <para>The name of the device matched while searching the devpath upwards for
579 <option>SUBSYSTEMS</option>, <option>KERNELS</option>, <option>DRIVERS</option> and <option>ATTRS</option>.
585 <term><option>$driver</option></term>
587 <para>The driver name of the device matched while searching the devpath upwards for
588 <option>SUBSYSTEMS</option>, <option>KERNELS</option>, <option>DRIVERS</option> and <option>ATTRS</option>.
594 <term><option>$attr{<replaceable>file</replaceable>}</option>, <option>%s{<replaceable>file</replaceable>}</option></term>
596 <para>The value of a sysfs attribute found at the device where
597 all keys of the rule have matched. If the matching device does not have
598 such an attribute, and a previous KERNELS, SUBSYSTEMS, DRIVERS, or
599 ATTRS test selected a parent device, then the attribute from that
600 parent device is used.</para>
601 <para>If the attribute is a symlink, the last element of the symlink target is
602 returned as the value.</para>
607 <term><option>$env{<replaceable>key</replaceable>}</option>, <option>%E{<replaceable>key</replaceable>}</option></term>
609 <para>A device property value.</para>
614 <term><option>$major</option>, <option>%M</option></term>
616 <para>The kernel major number for the device.</para>
621 <term><option>$minor</option>, <option>%m</option></term>
623 <para>The kernel minor number for the device.</para>
628 <term><option>$result</option>, <option>%c</option></term>
630 <para>The string returned by the external program requested with PROGRAM.
631 A single part of the string, separated by a space character, may be selected
632 by specifying the part number as an attribute: <option>%c{N}</option>.
633 If the number is followed by the '+' character, this part plus all remaining parts
634 of the result string are substituted: <option>%c{N+}</option></para>
639 <term><option>$parent</option>, <option>%P</option></term>
641 <para>The node name of the parent device.</para>
646 <term><option>$name</option></term>
648 <para>The current name of the device. If not changed by a rule, it is the
649 name of the kernel device.</para>
654 <term><option>$links</option></term>
656 <para>A space-separated list of the current symlinks. The value is
657 only set during a remove event or if an earlier rule assigned a value.</para>
662 <term><option>$root</option>, <option>%r</option></term>
664 <para>The udev_root value.</para>
669 <term><option>$sys</option>, <option>%S</option></term>
671 <para>The sysfs mount point.</para>
676 <term><option>$devnode</option>, <option>%N</option></term>
678 <para>The name of the device node.</para>
683 <term><option>%%</option></term>
685 <para>The '%' character itself.</para>
690 <term><option>$$</option></term>
692 <para>The '$' character itself.</para>
700 <title>See Also</title>
702 <refentrytitle>udevd</refentrytitle><manvolnum>8</manvolnum>
705 <refentrytitle>udevadm</refentrytitle><manvolnum>8</manvolnum>
706 </citerefentry></para>