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>/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 default rules directory <filename>/lib/udev/rules.d/</filename>,
75 the custom rules directory <filename>/etc/udev/rules.d/</filename>
76 and the temporary rules directory <filename>/run/udev/rules.d/</filename>.
77 All rule files are collectively sorted and processed in lexical order,
78 regardless of the directories in which they live. However, files in
79 <filename>/etc/udev/rules.d/</filename> take precedence over files with
80 the same name in <filename>/lib/udev/rules.d/</filename>; this can be
81 used to ignore a default rules file if needed.</para>
83 <para>Rule files must have the extension <filename>.rules</filename>; other
84 extensions are ignored.</para>
86 <para>Every line in the rules file contains at least one key-value pair.
87 There are two kind of keys: match and assignment.
88 If all match keys are matching against its value, the rule gets applied and the
89 assignment keys get the specified value assigned.</para>
91 <para>A matching rule may rename a network interface, add symlinks
92 pointing to the device node, or run a specified program as part of
93 the event handling.</para>
95 <para>A rule consists of a comma-separated list of one or more key-value pairs.
96 Each key has a distinct operation, depending on the used operator. Valid
100 <term><option>==</option></term>
102 <para>Compare for equality.</para>
107 <term><option>!=</option></term>
109 <para>Compare for inequality.</para>
114 <term><option>=</option></term>
116 <para>Assign a value to a key. Keys that represent a list are reset
117 and only this single value is assigned.</para>
122 <term><option>+=</option></term>
124 <para>Add the value to a key that holds a list of entries.</para>
129 <term><option>:=</option></term>
131 <para>Assign a value to a key finally; disallow any later changes.</para>
136 <para>The following key names can be used to match against device properties.
137 Some of the keys also match against properties of the parent devices in sysfs,
138 not only the device that has generated the event. If multiple keys that match
139 a parent device are specified in a single rule, all these keys must match at
140 one and the same parent device.</para>
143 <term><option>ACTION</option></term>
145 <para>Match the name of the event action.</para>
150 <term><option>DEVPATH</option></term>
152 <para>Match the devpath of the event device.</para>
157 <term><option>KERNEL</option></term>
159 <para>Match the name of the event device.</para>
164 <term><option>NAME</option></term>
166 <para>Match the name of the node or network interface. It can
167 be used once the NAME key has been set in one of the preceding
173 <term><option>SYMLINK</option></term>
175 <para>Match the name of a symlink targeting the node. It can
176 be used once a SYMLINK key has been set in one of the preceding
177 rules. There may be multiple symlinks; only one needs to match.
183 <term><option>SUBSYSTEM</option></term>
185 <para>Match the subsystem of the event device.</para>
189 <term><option>DRIVER</option></term>
191 <para>Match the driver name of the event device. Only set this key for devices
192 which are bound to a driver at the time the event is generated.</para>
196 <term><option>ATTR{<replaceable>filename</replaceable>}</option></term>
198 <para>Match sysfs attribute values of the event device. Trailing
199 whitespace in the attribute values is ignored unless the specified match
200 value itself contains trailing whitespace.
206 <term><option>KERNELS</option></term>
208 <para>Search the devpath upwards for a matching device name.</para>
213 <term><option>SUBSYSTEMS</option></term>
215 <para>Search the devpath upwards for a matching device subsystem name.</para>
220 <term><option>DRIVERS</option></term>
222 <para>Search the devpath upwards for a matching device driver name.</para>
227 <term><option>ATTRS{<replaceable>filename</replaceable>}</option></term>
229 <para>Search the devpath upwards for a device with matching sysfs attribute values.
230 If multiple <option>ATTRS</option> matches are specified, all of them
231 must match on the same device. Trailing whitespace in the attribute values is ignored
232 unless the specified match value itself contains trailing whitespace.</para>
237 <term><option>TAGS</option></term>
239 <para>Search the devpath upwards for a device with matching tag.</para>
244 <term><option>ENV{<replaceable>key</replaceable>}</option></term>
246 <para>Match against a device property value.</para>
251 <term><option>TAG</option></term>
253 <para>Match against a device tag.</para>
258 <term><option>TEST{<replaceable>octal mode mask</replaceable>}</option></term>
260 <para>Test the existence of a file. An octal mode mask can be specified
266 <term><option>PROGRAM</option></term>
268 <para>Execute a program to determine whether there
269 is a match; the key is true if the program returns
270 successfully. The device properties are made available to the
271 executed program in the environment. The program's stdout
272 is available in the RESULT key.</para>
277 <term><option>RESULT</option></term>
279 <para>Match the returned string of the last PROGRAM call. This key can
280 be used in the same or in any later rule after a PROGRAM call.</para>
285 <para>Most of the fields support shell-style pattern matching. The following
286 pattern characters are supported:</para>
289 <term><option>*</option></term>
291 <para>Matches zero or more characters.</para>
295 <term><option>?</option></term>
297 <para>Matches any single character.</para>
301 <term><option>[]</option></term>
303 <para>Matches any single character specified within the brackets. For
304 example, the pattern string 'tty[SR]' would match either 'ttyS' or 'ttyR'.
305 Ranges are also supported via the '-' character.
306 For example, to match on the range of all digits, the pattern [0-9] could
307 be used. If the first character following the '[' is a '!', any characters
308 not enclosed are matched.</para>
313 <para>The following keys can get values assigned:</para>
316 <term><option>NAME</option></term>
318 <para>What a network interface should be named.</para>
319 <para>Also, as a temporary workaround, this is what a device node
320 should be named; usually the kernel provides the defined node name or creates
321 and removes the node before udev even receives any event. Changing
322 the node name from the kernel's default creates inconsistencies
323 and is not supported. If the kernel and NAME specify different names,
324 an error is logged. udev is only expected to handle device node
325 permissions and to create additional symlinks, not to change
326 kernel-provided device node names. Instead of renaming a device node,
327 SYMLINK should be used. However, symlink names must never conflict with
328 device node names, as that would result in unpredictable behavior.</para>
333 <term><option>SYMLINK</option></term>
335 <para>The name of a symlink targeting the node. Every matching rule adds
336 this value to the list of symlinks to be created. Multiple symlinks may be
337 specified by separating the names by the space character. In case multiple
338 devices claim the same name, the link always points to the device with
339 the highest link_priority. If the current device goes away, the links are
340 re-evaluated and the device with the next highest link_priority becomes the owner of
341 the link. If no link_priority is specified, the order of the devices (and
342 which one of them owns the link) is undefined. Also, symlink names must
343 never conflict with the kernel's default device node names, as that would
344 result in unpredictable behavior.
350 <term><option>OWNER, GROUP, MODE</option></term>
352 <para>The permissions for the device node. Every specified value overwrites
353 the compiled-in default value.</para>
358 <term><option>ATTR{<replaceable>key</replaceable>}</option></term>
360 <para>The value that should be written to a sysfs attribute of the
366 <term><option>ENV{<replaceable>key</replaceable>}</option></term>
368 <para>Set a device property value. Property names with a leading '.'
369 are neither stored in the database nor exported to events or
370 external tools (run by, say, the PROGRAM match key).</para>
375 <term><option>TAG</option></term>
377 <para>Attach a tag to a device. This is used to filter events for users
378 of libudev's monitor functionality, or to enumerate a group of tagged
379 devices. The implementation can only work efficiently if only a few
380 tags are attached to a device. It is only meant to be used in
381 contexts with specific device filter requirements, and not as a
382 general-purpose flag. Excessive use might result in inefficient event
388 <term><option>RUN</option></term>
390 <para>Add a program to the list of programs to be executed for a specific
391 device. This can only be used for very short running tasks. Running an
392 event process for a long period of time may block all further events for
393 this or a dependent device. Long running tasks need to be immediately
394 detached from the event process itself.</para>
395 <para>If no absolute path is given, the program is expected to live in
396 the directory provided at compile-time to configure via --libexecdir
397 (this is usually <filename>/lib/udev</filename>), otherwise the absolute
398 path must be specified. The program name and following arguments are
399 separated by spaces. Single quotes can be used to specify arguments with
405 <term><option>LABEL</option></term>
407 <para>A named label to which a GOTO may jump.</para>
412 <term><option>GOTO</option></term>
414 <para>Jumps to the next LABEL with a matching name.</para>
419 <term><option>IMPORT{<replaceable>type</replaceable>}</option></term>
421 <para>Import a set of variables as device properties,
422 depending on <replaceable>type</replaceable>:</para>
425 <term><option>program</option></term>
427 <para>Execute an external program specified as the assigned value and
428 import its output, which must be in environment key
429 format. Path specification, command/argument separation,
430 and quoting work like in <option>RUN</option>.</para>
434 <term><option>file</option></term>
436 <para>Import a text file specified as the assigned value, the content
437 of which must be in environment key format.</para>
441 <term><option>db</option></term>
443 <para>Import a single property specified as the assigned value from the
444 current device database. This works only if the database is already populated
445 by an earlier event.</para>
449 <term><option>cmdline</option></term>
451 <para>Import a single property from the kernel command line. For simple flags
452 the value of the property is set to '1'.</para>
456 <term><option>parent</option></term>
458 <para>Import the stored keys from the parent device by reading
459 the database entry of the parent device. The value assigned to
460 <option>IMPORT{parent}</option> is used as a filter of key names
461 to import (with the same shell-style pattern matching used for
470 <term><option>WAIT_FOR</option></term>
472 <para>Wait for a file to become available or until a timeout of
473 10 seconds expires. The path is relative to the sysfs device;
474 if no path is specified, this waits for an attribute to appear.</para>
479 <term><option>OPTIONS</option></term>
481 <para>Rule and device options:</para>
484 <term><option>link_priority=<replaceable>value</replaceable></option></term>
486 <para>Specify the priority of the created symlinks. Devices with higher
487 priorities overwrite existing symlinks of other devices. The default is 0.</para>
491 <term><option>event_timeout=</option></term>
493 <para>Number of seconds an event waits for operations to finish before
494 giving up and terminating itself.</para>
498 <term><option>string_escape=<replaceable>none|replace</replaceable></option></term>
500 <para>Usually control and other possibly unsafe characters are replaced
501 in strings used for device naming. The mode of replacement can be specified
502 with this option.</para>
506 <term><option>static_node=</option></term>
508 <para>Apply the permissions specified in this rule to the static device node with
509 the specified name. Static device nodes might be provided by kernel modules
510 or copied from <filename>/lib/udev/devices</filename>. These nodes might not have
511 a corresponding kernel device at the time udevd is started; they can trigger
512 automatic kernel module loading.</para>
516 <term><option>watch</option></term>
518 <para>Watch the device node with inotify; when the node is closed after being opened for
519 writing, a change uevent is synthesized.</para>
523 <term><option>nowatch</option></term>
525 <para>Disable the watching of a device node with inotify.</para>
533 <para>The <option>NAME</option>, <option>SYMLINK</option>, <option>PROGRAM</option>,
534 <option>OWNER</option>, <option>GROUP</option>, <option>MODE</option> and <option>RUN</option>
535 fields support simple string substitutions. The <option>RUN</option>
536 substitutions are performed after all rules have been processed, right before the program
537 is executed, allowing for the use of device properties set by earlier matching
538 rules. For all other fields, substitutions are performed while the individual rule is
539 being processed. The available substitutions are:</para>
542 <term><option>$kernel</option>, <option>%k</option></term>
544 <para>The kernel name for this device.</para>
549 <term><option>$number</option>, <option>%n</option></term>
551 <para>The kernel number for this device. For example, 'sda3' has
552 kernel number of '3'</para>
557 <term><option>$devpath</option>, <option>%p</option></term>
559 <para>The devpath of the device.</para>
564 <term><option>$id</option>, <option>%b</option></term>
566 <para>The name of the device matched while searching the devpath upwards for
567 <option>SUBSYSTEMS</option>, <option>KERNELS</option>, <option>DRIVERS</option> and <option>ATTRS</option>.
573 <term><option>$driver</option></term>
575 <para>The driver name of the device matched while searching the devpath upwards for
576 <option>SUBSYSTEMS</option>, <option>KERNELS</option>, <option>DRIVERS</option> and <option>ATTRS</option>.
582 <term><option>$attr{<replaceable>file</replaceable>}</option>, <option>%s{<replaceable>file</replaceable>}</option></term>
584 <para>The value of a sysfs attribute found at the device where
585 all keys of the rule have matched. If the matching device does not have
586 such an attribute, and a previous KERNELS, SUBSYSTEMS, DRIVERS, or
587 ATTRS test selected a parent device, then the attribute from that
588 parent device is used.</para>
589 <para>If the attribute is a symlink, the last element of the symlink target is
590 returned as the value.</para>
595 <term><option>$env{<replaceable>key</replaceable>}</option>, <option>%E{<replaceable>key</replaceable>}</option></term>
597 <para>A device property value.</para>
602 <term><option>$major</option>, <option>%M</option></term>
604 <para>The kernel major number for the device.</para>
609 <term><option>$minor</option>, <option>%m</option></term>
611 <para>The kernel minor number for the device.</para>
616 <term><option>$result</option>, <option>%c</option></term>
618 <para>The string returned by the external program requested with PROGRAM.
619 A single part of the string, separated by a space character, may be selected
620 by specifying the part number as an attribute: <option>%c{N}</option>.
621 If the number is followed by the '+' character, this part plus all remaining parts
622 of the result string are substituted: <option>%c{N+}</option></para>
627 <term><option>$parent</option>, <option>%P</option></term>
629 <para>The node name of the parent device.</para>
634 <term><option>$name</option></term>
636 <para>The current name of the device node. If not changed by a rule, it is the
637 name of the kernel device.</para>
642 <term><option>$links</option></term>
644 <para>A space-separated list of the current symlinks. The value is
645 only set during a remove event or if an earlier rule assigned a value.</para>
650 <term><option>$root</option>, <option>%r</option></term>
652 <para>The udev_root value.</para>
657 <term><option>$sys</option>, <option>%S</option></term>
659 <para>The sysfs mount point.</para>
664 <term><option>$tempnode</option>, <option>%N</option></term>
666 <para>The name of a temporary device node created to provide access to
667 the device from a external program before the real node is created.</para>
672 <term><option>%%</option></term>
674 <para>The '%' character itself.</para>
679 <term><option>$$</option></term>
681 <para>The '$' character itself.</para>
688 <refsect1><title>Author</title>
689 <para>Written by Greg Kroah-Hartman <email>greg@kroah.com</email> and
690 Kay Sievers <email>kay.sievers@vrfy.org</email>. With much help from
691 Dan Stekloff and many others.</para>
695 <title>See Also</title>
697 <refentrytitle>udevd</refentrytitle><manvolnum>8</manvolnum>
700 <refentrytitle>udevadm</refentrytitle><manvolnum>8</manvolnum>
701 </citerefentry></para>