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>udev</productname>
13 <refentrytitle>udev</refentrytitle>
14 <manvolnum>7</manvolnum>
18 <refname>udev</refname>
19 <refpurpose>Linux dynamic device management</refpurpose>
22 <refsect1><title>Description</title>
23 <para>udev supplies the system software with device events, manages permissions
24 of device nodes and may create additional symlinks in the <filename>/dev</filename>
25 directory, or renames network interfaces. The kernel usually just assigns unpredictable
26 device names based on the order of discovery. Meaningful symlinks or network device
27 names provide a way to reliably identify devices based on their properties or
28 current configuration.</para>
30 <para>The udev daemon, <citerefentry><refentrytitle>udevd</refentrytitle>
31 <manvolnum>8</manvolnum></citerefentry>, receives device uevents directly from
32 the kernel whenever a device is added or removed from the system, or it changes its
33 state. When udev receives a device event, it matches its configured set of rules
34 against various device attributes to identify the device. Rules that match may
35 provide additional device information to be stored in the udev database or
36 to be used to create meaningful symlink names.</para>
38 <para>All device information udev processes is stored in the udev database and
39 sent out to possible event subscribers. Access to all stored data and the event
40 sources is provided by the library libudev.</para>
43 <refsect1><title>Configuration</title>
44 <para>udev configuration files are placed in <filename>/etc/udev</filename>
45 and <filename>/usr/lib/udev</filename>. All empty lines or lines beginning with
46 '#' are ignored.</para>
48 <refsect2><title>Configuration file</title>
49 <para>udev expects its main configuration file at <filename>/etc/udev/udev.conf</filename>.
50 It consists of a set of variables allowing the user to override default udev values.
51 The following variables can be set:</para>
54 <term><option>udev_root</option></term>
56 <para>Specifies where to place the device nodes in the filesystem.
57 The default value is <filename>/dev</filename>.</para>
62 <term><option>udev_log</option></term>
64 <para>The logging priority. Valid values are the numerical syslog priorities
65 or their textual representations: <option>err</option>, <option>info</option>
66 and <option>debug</option>.</para>
72 <refsect2><title>Rules files</title>
73 <para>The udev rules are read from the files located in the
74 system rules directory <filename>/usr/lib/udev/rules.d</filename>,
75 the local administration directory <filename>/etc/udev/rules.d</filename>
76 and the volatile runtime directory <filename>/run/udev/rules.d</filename>.
77 All rules files are collectively sorted and processed in lexical order,
78 regardless of the directories in which they live. However, files with
79 identical file names replace each other. Files in <filename>/run</filename>
80 have the highest priority, files in <filename>/etc</filename> take precedence
81 over files with the same name in <filename>/lib</filename>. This can be
82 used to overwrite a system rules file if needed; a symlink in
83 <filename>/etc</filename> with the same name as a rules file in
84 <filename>/lib</filename>, pointing to <filename>/dev/null</filename>,
85 disables the rules file entirely.</para>
87 <para>Rule files must have the extension <filename>.rules</filename>; other
88 extensions are ignored.</para>
90 <para>Every line in the rules file contains at least one key-value pair.
91 There are two kind of keys: match and assignment.
92 If all match keys are matching against its value, the rule gets applied and the
93 assignment keys get the specified value assigned.</para>
95 <para>A matching rule may rename a network interface, add symlinks
96 pointing to the device node, or run a specified program as part of
97 the event handling.</para>
99 <para>A rule consists of a comma-separated list of one or more key-value pairs.
100 Each key has a distinct operation, depending on the used operator. Valid
101 operators are:</para>
104 <term><option>==</option></term>
106 <para>Compare for equality.</para>
111 <term><option>!=</option></term>
113 <para>Compare for inequality.</para>
118 <term><option>=</option></term>
120 <para>Assign a value to a key. Keys that represent a list are reset
121 and only this single value is assigned.</para>
126 <term><option>+=</option></term>
128 <para>Add the value to a key that holds a list of entries.</para>
133 <term><option>:=</option></term>
135 <para>Assign a value to a key finally; disallow any later changes.</para>
140 <para>The following key names can be used to match against device properties.
141 Some of the keys also match against properties of the parent devices in sysfs,
142 not only the device that has generated the event. If multiple keys that match
143 a parent device are specified in a single rule, all these keys must match at
144 one and the same parent device.</para>
147 <term><option>ACTION</option></term>
149 <para>Match the name of the event action.</para>
154 <term><option>DEVPATH</option></term>
156 <para>Match the devpath of the event device.</para>
161 <term><option>KERNEL</option></term>
163 <para>Match the name of the event device.</para>
168 <term><option>NAME</option></term>
170 <para>Match the name of a network interface. It can be used once the
171 NAME key has been set in one of the preceding rules.</para>
176 <term><option>SYMLINK</option></term>
178 <para>Match the name of a symlink targeting the node. It can
179 be used once a SYMLINK key has been set in one of the preceding
180 rules. There may be multiple symlinks; only one needs to match.
186 <term><option>SUBSYSTEM</option></term>
188 <para>Match the subsystem of the event device.</para>
192 <term><option>DRIVER</option></term>
194 <para>Match the driver name of the event device. Only set this key for devices
195 which are bound to a driver at the time the event is generated.</para>
199 <term><option>ATTR{<replaceable>filename</replaceable>}</option></term>
201 <para>Match sysfs attribute values of the event device. Trailing
202 whitespace in the attribute values is ignored unless the specified match
203 value itself contains trailing whitespace.
209 <term><option>KERNELS</option></term>
211 <para>Search the devpath upwards for a matching device name.</para>
216 <term><option>SUBSYSTEMS</option></term>
218 <para>Search the devpath upwards for a matching device subsystem name.</para>
223 <term><option>DRIVERS</option></term>
225 <para>Search the devpath upwards for a matching device driver name.</para>
230 <term><option>ATTRS{<replaceable>filename</replaceable>}</option></term>
232 <para>Search the devpath upwards for a device with matching sysfs attribute values.
233 If multiple <option>ATTRS</option> matches are specified, all of them
234 must match on the same device. Trailing whitespace in the attribute values is ignored
235 unless the specified match value itself contains trailing whitespace.</para>
240 <term><option>TAGS</option></term>
242 <para>Search the devpath upwards for a device with matching tag.</para>
247 <term><option>ENV{<replaceable>key</replaceable>}</option></term>
249 <para>Match against a device property value.</para>
254 <term><option>TAG</option></term>
256 <para>Match against a device tag.</para>
261 <term><option>TEST{<replaceable>octal mode mask</replaceable>}</option></term>
263 <para>Test the existence of a file. An octal mode mask can be specified
269 <term><option>PROGRAM</option></term>
271 <para>Execute a program to determine whether there
272 is a match; the key is true if the program returns
273 successfully. The device properties are made available to the
274 executed program in the environment. The program's stdout
275 is available in the RESULT key.</para>
280 <term><option>RESULT</option></term>
282 <para>Match the returned string of the last PROGRAM call. This key can
283 be used in the same or in any later rule after a PROGRAM call.</para>
288 <para>Most of the fields support shell-style pattern matching. The following
289 pattern characters are supported:</para>
292 <term><option>*</option></term>
294 <para>Matches zero or more characters.</para>
298 <term><option>?</option></term>
300 <para>Matches any single character.</para>
304 <term><option>[]</option></term>
306 <para>Matches any single character specified within the brackets. For
307 example, the pattern string 'tty[SR]' would match either 'ttyS' or 'ttyR'.
308 Ranges are also supported via the '-' character.
309 For example, to match on the range of all digits, the pattern [0-9] could
310 be used. If the first character following the '[' is a '!', any characters
311 not enclosed are matched.</para>
316 <para>The following keys can get values assigned:</para>
319 <term><option>NAME</option></term>
321 <para>The name to use for a network interface. The name of a device node
322 can not be changed by udev, only additional symlinks can be created.</para>
327 <term><option>SYMLINK</option></term>
329 <para>The name of a symlink targeting the node. Every matching rule adds
330 this value to the list of symlinks to be created. Multiple symlinks may be
331 specified by separating the names by the space character. In case multiple
332 devices claim the same name, the link always points to the device with
333 the highest link_priority. If the current device goes away, the links are
334 re-evaluated and the device with the next highest link_priority becomes the owner of
335 the link. If no link_priority is specified, the order of the devices (and
336 which one of them owns the link) is undefined. Also, symlink names must
337 never conflict with the kernel's default device node names, as that would
338 result in unpredictable behavior.
344 <term><option>OWNER, GROUP, MODE</option></term>
346 <para>The permissions for the device node. Every specified value overwrites
347 the compiled-in default value.</para>
352 <term><option>ATTR{<replaceable>key</replaceable>}</option></term>
354 <para>The value that should be written to a sysfs attribute of the
360 <term><option>ENV{<replaceable>key</replaceable>}</option></term>
362 <para>Set a device property value. Property names with a leading '.'
363 are neither stored in the database nor exported to events or
364 external tools (run by, say, the PROGRAM match key).</para>
369 <term><option>TAG</option></term>
371 <para>Attach a tag to a device. This is used to filter events for users
372 of libudev's monitor functionality, or to enumerate a group of tagged
373 devices. The implementation can only work efficiently if only a few
374 tags are attached to a device. It is only meant to be used in
375 contexts with specific device filter requirements, and not as a
376 general-purpose flag. Excessive use might result in inefficient event
382 <term><option>RUN</option></term>
384 <para>Add a program to the list of programs to be executed for a specific
385 device. This can only be used for very short running tasks. Running an
386 event process for a long period of time may block all further events for
387 this or a dependent device. Long running tasks need to be immediately
388 detached from the event process itself.</para>
389 <para>If no absolute path is given, the program is expected to live in
390 /usr/lib/udev, otherwise the absolute path must be specified. The program
391 name and following arguments are separated by spaces. Single quotes can
392 be used to specify arguments with spaces.</para>
397 <term><option>LABEL</option></term>
399 <para>A named label to which a GOTO may jump.</para>
404 <term><option>GOTO</option></term>
406 <para>Jumps to the next LABEL with a matching name.</para>
411 <term><option>IMPORT{<replaceable>type</replaceable>}</option></term>
413 <para>Import a set of variables as device properties,
414 depending on <replaceable>type</replaceable>:</para>
417 <term><option>program</option></term>
419 <para>Execute an external program specified as the assigned value and
420 import its output, which must be in environment key
421 format. Path specification, command/argument separation,
422 and quoting work like in <option>RUN</option>.</para>
426 <term><option>file</option></term>
428 <para>Import a text file specified as the assigned value, the content
429 of which must be in environment key format.</para>
433 <term><option>db</option></term>
435 <para>Import a single property specified as the assigned value from the
436 current device database. This works only if the database is already populated
437 by an earlier event.</para>
441 <term><option>cmdline</option></term>
443 <para>Import a single property from the kernel command line. For simple flags
444 the value of the property is set to '1'.</para>
448 <term><option>parent</option></term>
450 <para>Import the stored keys from the parent device by reading
451 the database entry of the parent device. The value assigned to
452 <option>IMPORT{parent}</option> is used as a filter of key names
453 to import (with the same shell-style pattern matching used for
462 <term><option>WAIT_FOR</option></term>
464 <para>Wait for a file to become available or until a timeout of
465 10 seconds expires. The path is relative to the sysfs device;
466 if no path is specified, this waits for an attribute to appear.</para>
471 <term><option>OPTIONS</option></term>
473 <para>Rule and device options:</para>
476 <term><option>link_priority=<replaceable>value</replaceable></option></term>
478 <para>Specify the priority of the created symlinks. Devices with higher
479 priorities overwrite existing symlinks of other devices. The default is 0.</para>
483 <term><option>event_timeout=</option></term>
485 <para>Number of seconds an event waits for operations to finish before
486 giving up and terminating itself.</para>
490 <term><option>string_escape=<replaceable>none|replace</replaceable></option></term>
492 <para>Usually control and other possibly unsafe characters are replaced
493 in strings used for device naming. The mode of replacement can be specified
494 with this option.</para>
498 <term><option>static_node=</option></term>
500 <para>Apply the permissions specified in this rule to the static device node with
501 the specified name. Static device nodes might be provided by kernel modules
502 or copied from <filename>/usr/lib/udev/devices</filename>. These nodes might not have
503 a corresponding kernel device at the time udevd is started; they can trigger
504 automatic kernel module loading.</para>
508 <term><option>watch</option></term>
510 <para>Watch the device node with inotify; when the node is closed after being opened for
511 writing, a change uevent is synthesized.</para>
515 <term><option>nowatch</option></term>
517 <para>Disable the watching of a device node with inotify.</para>
525 <para>The <option>NAME</option>, <option>SYMLINK</option>, <option>PROGRAM</option>,
526 <option>OWNER</option>, <option>GROUP</option>, <option>MODE</option> and <option>RUN</option>
527 fields support simple string substitutions. The <option>RUN</option>
528 substitutions are performed after all rules have been processed, right before the program
529 is executed, allowing for the use of device properties set by earlier matching
530 rules. For all other fields, substitutions are performed while the individual rule is
531 being processed. The available substitutions are:</para>
534 <term><option>$kernel</option>, <option>%k</option></term>
536 <para>The kernel name for this device.</para>
541 <term><option>$number</option>, <option>%n</option></term>
543 <para>The kernel number for this device. For example, 'sda3' has
544 kernel number of '3'</para>
549 <term><option>$devpath</option>, <option>%p</option></term>
551 <para>The devpath of the device.</para>
556 <term><option>$id</option>, <option>%b</option></term>
558 <para>The name of the device matched while searching the devpath upwards for
559 <option>SUBSYSTEMS</option>, <option>KERNELS</option>, <option>DRIVERS</option> and <option>ATTRS</option>.
565 <term><option>$driver</option></term>
567 <para>The driver name of the device matched while searching the devpath upwards for
568 <option>SUBSYSTEMS</option>, <option>KERNELS</option>, <option>DRIVERS</option> and <option>ATTRS</option>.
574 <term><option>$attr{<replaceable>file</replaceable>}</option>, <option>%s{<replaceable>file</replaceable>}</option></term>
576 <para>The value of a sysfs attribute found at the device where
577 all keys of the rule have matched. If the matching device does not have
578 such an attribute, and a previous KERNELS, SUBSYSTEMS, DRIVERS, or
579 ATTRS test selected a parent device, then the attribute from that
580 parent device is used.</para>
581 <para>If the attribute is a symlink, the last element of the symlink target is
582 returned as the value.</para>
587 <term><option>$env{<replaceable>key</replaceable>}</option>, <option>%E{<replaceable>key</replaceable>}</option></term>
589 <para>A device property value.</para>
594 <term><option>$major</option>, <option>%M</option></term>
596 <para>The kernel major number for the device.</para>
601 <term><option>$minor</option>, <option>%m</option></term>
603 <para>The kernel minor number for the device.</para>
608 <term><option>$result</option>, <option>%c</option></term>
610 <para>The string returned by the external program requested with PROGRAM.
611 A single part of the string, separated by a space character, may be selected
612 by specifying the part number as an attribute: <option>%c{N}</option>.
613 If the number is followed by the '+' character, this part plus all remaining parts
614 of the result string are substituted: <option>%c{N+}</option></para>
619 <term><option>$parent</option>, <option>%P</option></term>
621 <para>The node name of the parent device.</para>
626 <term><option>$name</option></term>
628 <para>The current name of the device. If not changed by a rule, it is the
629 name of the kernel device.</para>
634 <term><option>$links</option></term>
636 <para>A space-separated list of the current symlinks. The value is
637 only set during a remove event or if an earlier rule assigned a value.</para>
642 <term><option>$root</option>, <option>%r</option></term>
644 <para>The udev_root value.</para>
649 <term><option>$sys</option>, <option>%S</option></term>
651 <para>The sysfs mount point.</para>
656 <term><option>$devnode</option>, <option>%N</option></term>
658 <para>The name of the device node.</para>
663 <term><option>%%</option></term>
665 <para>The '%' character itself.</para>
670 <term><option>$$</option></term>
672 <para>The '$' character itself.</para>
679 <refsect1><title>Author</title>
680 <para>Written by Greg Kroah-Hartman <email>greg@kroah.com</email> and
681 Kay Sievers <email>kay.sievers@vrfy.org</email>. With much help from
682 Dan Stekloff and many others.</para>
686 <title>See Also</title>
688 <refentrytitle>udevd</refentrytitle><manvolnum>8</manvolnum>
691 <refentrytitle>udevadm</refentrytitle><manvolnum>8</manvolnum>
692 </citerefentry></para>