1 <?xml version='
1.0'
?> <!--*- Mode: nxml; nxml-child-indent: 2; indent-tabs-mode: nil -*-->
2 <!DOCTYPE refentry PUBLIC
"-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
6 SPDX-License-Identifier: LGPL-2.1+
8 This file is part of systemd.
10 Copyright 2012 Kay Sievers
11 Copyright 2014 Jason St. John
13 systemd is free software; you can redistribute it and/or modify it
14 under the terms of the GNU Lesser General Public License as published by
15 the Free Software Foundation; either version 2.1 of the License, or
16 (at your option) any later version.
18 systemd is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 Lesser General Public License for more details.
23 You should have received a copy of the GNU Lesser General Public License
24 along with systemd; If not, see <http://www.gnu.org/licenses/>.
30 <productname>systemd
</productname>
33 <contrib>Developer
</contrib>
34 <firstname>Greg
</firstname>
35 <surname>Kroah-Hartmann
</surname>
36 <email>greg@kroah.com
</email>
39 <contrib>Developer
</contrib>
40 <firstname>Kay
</firstname>
41 <surname>Sievers
</surname>
42 <email>kay@vrfy.org
</email>
48 <refentrytitle>udev
</refentrytitle>
49 <manvolnum>7</manvolnum>
53 <refname>udev
</refname>
54 <refpurpose>Dynamic device management
</refpurpose>
57 <refsect1><title>Description
</title>
58 <para>udev supplies the system software with device events, manages permissions
59 of device nodes and may create additional symlinks in the
<filename>/dev
</filename>
60 directory, or renames network interfaces. The kernel usually just assigns unpredictable
61 device names based on the order of discovery. Meaningful symlinks or network device
62 names provide a way to reliably identify devices based on their properties or
63 current configuration.
</para>
65 <para>The udev daemon,
<citerefentry><refentrytitle>systemd-udevd.service
</refentrytitle>
66 <manvolnum>8</manvolnum></citerefentry>, receives device uevents directly from
67 the kernel whenever a device is added or removed from the system, or it changes its
68 state. When udev receives a device event, it matches its configured set of rules
69 against various device attributes to identify the device. Rules that match may
70 provide additional device information to be stored in the udev database or
71 to be used to create meaningful symlink names.
</para>
73 <para>All device information udev processes is stored in the udev database and
74 sent out to possible event subscribers. Access to all stored data and the event
75 sources is provided by the library libudev.
</para>
78 <refsect1><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 filenames 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>/usr/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>/usr/lib
</filename>, pointing to
<filename>/dev/null
</filename>,
91 disables the rules file entirely. Rule files must have the extension
92 <filename>.rules
</filename>; other extensions are ignored.
</para>
94 <para>Every line in the rules file contains at least one key-value pair.
95 Except for empty lines or lines beginning with
<literal>#
</literal>, which are ignored.
96 There are two kinds of keys: match and assignment.
97 If all match keys match against their values, the rule gets applied and the
98 assignment keys get the specified values assigned.
</para>
100 <para>A matching rule may rename a network interface, add symlinks
101 pointing to the device node, or run a specified program as part of
102 the event handling.
</para>
104 <para>A rule consists of a comma-separated list of one or more key-value pairs.
105 Each key has a distinct operation, depending on the used operator. Valid
106 operators are:
</para>
109 <term><literal>==
</literal></term>
111 <para>Compare for equality.
</para>
116 <term><literal>!=
</literal></term>
118 <para>Compare for inequality.
</para>
123 <term><literal>=
</literal></term>
125 <para>Assign a value to a key. Keys that represent a list are reset
126 and only this single value is assigned.
</para>
131 <term><literal>+=
</literal></term>
133 <para>Add the value to a key that holds a list of entries.
</para>
138 <term><literal>-=
</literal></term>
140 <para>Remove the value from a key that holds a list of entries.
</para>
145 <term><literal>:=
</literal></term>
147 <para>Assign a value to a key finally; disallow any later changes.
</para>
152 <para>The following key names can be used to match against device properties.
153 Some of the keys also match against properties of the parent devices in sysfs,
154 not only the device that has generated the event. If multiple keys that match
155 a parent device are specified in a single rule, all these keys must match at
156 one and the same parent device.
</para>
157 <variablelist class='udev-directives'
>
159 <term><varname>ACTION
</varname></term>
161 <para>Match the name of the event action.
</para>
166 <term><varname>DEVPATH
</varname></term>
168 <para>Match the devpath of the event device.
</para>
173 <term><varname>KERNEL
</varname></term>
175 <para>Match the name of the event device.
</para>
180 <term><varname>NAME
</varname></term>
182 <para>Match the name of a network interface. It can be used once the
183 NAME key has been set in one of the preceding rules.
</para>
188 <term><varname>SYMLINK
</varname></term>
190 <para>Match the name of a symlink targeting the node. It can
191 be used once a SYMLINK key has been set in one of the preceding
192 rules. There may be multiple symlinks; only one needs to match.
198 <term><varname>SUBSYSTEM
</varname></term>
200 <para>Match the subsystem of the event device.
</para>
204 <term><varname>DRIVER
</varname></term>
206 <para>Match the driver name of the event device. Only set this key for devices
207 which are bound to a driver at the time the event is generated.
</para>
211 <term><varname>ATTR{
<replaceable>filename
</replaceable>}
</varname></term>
213 <para>Match sysfs attribute values of the event device. Trailing
214 whitespace in the attribute values is ignored unless the specified match
215 value itself contains trailing whitespace.
218 <term><varname>SYSCTL{
<replaceable>kernel parameter
</replaceable>}
</varname></term>
220 <para>Match a kernel parameter value.
226 <term><varname>KERNELS
</varname></term>
228 <para>Search the devpath upwards for a matching device name.
</para>
233 <term><varname>SUBSYSTEMS
</varname></term>
235 <para>Search the devpath upwards for a matching device subsystem name.
</para>
240 <term><varname>DRIVERS
</varname></term>
242 <para>Search the devpath upwards for a matching device driver name.
</para>
247 <term><varname>ATTRS{
<replaceable>filename
</replaceable>}
</varname></term>
249 <para>Search the devpath upwards for a device with matching sysfs attribute values.
250 If multiple
<varname>ATTRS
</varname> matches are specified, all of them
251 must match on the same device. Trailing whitespace in the attribute values is ignored
252 unless the specified match value itself contains trailing whitespace.
</para>
257 <term><varname>TAGS
</varname></term>
259 <para>Search the devpath upwards for a device with matching tag.
</para>
264 <term><varname>ENV{
<replaceable>key
</replaceable>}
</varname></term>
266 <para>Match against a device property value.
</para>
271 <term><varname>TAG
</varname></term>
273 <para>Match against a device tag.
</para>
278 <term><varname>TEST{
<replaceable>octal mode mask
</replaceable>}
</varname></term>
280 <para>Test the existence of a file. An octal mode mask can be specified
286 <term><varname>PROGRAM
</varname></term>
288 <para>Execute a program to determine whether there
289 is a match; the key is true if the program returns
290 successfully. The device properties are made available to the
291 executed program in the environment. The program's standard output
292 is available in the
<varname>RESULT
</varname> key.
</para>
293 <para>This can only be used for very short-running foreground tasks. For details,
294 see
<varname>RUN
</varname>.
</para>
299 <term><varname>RESULT
</varname></term>
301 <para>Match the returned string of the last
<varname>PROGRAM
</varname> call.
302 This key can be used in the same or in any later rule after a
303 <varname>PROGRAM
</varname> call.
</para>
308 <para>Most of the fields support shell glob pattern matching and
309 alternate patterns. The following special characters are supported:
</para>
312 <term><literal>*
</literal></term>
314 <para>Matches zero or more characters.
</para>
318 <term><literal>?
</literal></term>
320 <para>Matches any single character.
</para>
324 <term><literal>[]
</literal></term>
326 <para>Matches any single character specified within the brackets. For
327 example, the pattern string
<literal>tty[SR]
</literal>
328 would match either
<literal>ttyS
</literal> or
<literal>ttyR
</literal>.
329 Ranges are also supported via the
<literal>-
</literal> character.
330 For example, to match on the range of all digits, the pattern
331 <literal>[
0-
9]
</literal> could be used. If the first character
332 following the
<literal>[
</literal> is a
<literal>!
</literal>,
333 any characters not enclosed are matched.
</para>
337 <term><literal>|
</literal></term>
339 <para>Separates alternative patterns. For example, the pattern string
340 <literal>abc|x*
</literal> would match either
<literal>abc
</literal>
341 or
<literal>x*
</literal>.
</para>
346 <para>The following keys can get values assigned:
</para>
347 <variablelist class='udev-directives'
>
349 <term><varname>NAME
</varname></term>
351 <para>The name to use for a network interface. See
352 <citerefentry><refentrytitle>systemd.link
</refentrytitle><manvolnum>5</manvolnum></citerefentry>
353 for a higher-level mechanism for setting the interface name.
354 The name of a device node cannot be changed by udev, only additional
355 symlinks can be created.
</para>
360 <term><varname>SYMLINK
</varname></term>
362 <para>The name of a symlink targeting the node. Every matching rule adds
363 this value to the list of symlinks to be created.
</para>
364 <para>The set of characters to name a symlink is limited. Allowed
365 characters are
<literal>0-
9A-Za-z#+-.:=@_/
</literal>, valid UTF-
8 character
366 sequences, and
<literal>\x00
</literal> hex encoding. All other
367 characters are replaced by a
<literal>_
</literal> character.
</para>
368 <para>Multiple symlinks may be specified by separating the names by the
369 space character. In case multiple devices claim the same name, the link
370 always points to the device with the highest link_priority. If the current
371 device goes away, the links are re-evaluated and the device with the
372 next highest link_priority becomes the owner of the link. If no
373 link_priority is specified, the order of the devices (and which one of
374 them owns the link) is undefined.
</para>
375 <para>Symlink names must never conflict with the kernel's default device
376 node names, as that would result in unpredictable behavior.
382 <term><varname>OWNER
</varname>,
<varname>GROUP
</varname>,
<varname>MODE
</varname></term>
384 <para>The permissions for the device node. Every specified value overrides
385 the compiled-in default value.
</para>
390 <term><varname>SECLABEL{
<replaceable>module
</replaceable>}
</varname></term>
392 <para>Applies the specified Linux Security Module label to the device node.
</para>
397 <term><varname>ATTR{
<replaceable>key
</replaceable>}
</varname></term>
399 <para>The value that should be written to a sysfs attribute of the
405 <term><varname>SYSCTL{
<replaceable>kernel parameter
</replaceable>}
</varname></term>
407 <para>The value that should be written to kernel parameter.
</para>
412 <term><varname>ENV{
<replaceable>key
</replaceable>}
</varname></term>
414 <para>Set a device property value. Property names with a leading
<literal>.
</literal>
415 are neither stored in the database nor exported to events or
416 external tools (run by, for example, the
<varname>PROGRAM
</varname>
422 <term><varname>TAG
</varname></term>
424 <para>Attach a tag to a device. This is used to filter events for users
425 of libudev's monitor functionality, or to enumerate a group of tagged
426 devices. The implementation can only work efficiently if only a few
427 tags are attached to a device. It is only meant to be used in
428 contexts with specific device filter requirements, and not as a
429 general-purpose flag. Excessive use might result in inefficient event
435 <term><varname>RUN{
<replaceable>type
</replaceable>}
</varname></term>
437 <para>Add a program to the list of programs to be executed after
438 processing all the rules for a specific event, depending on
439 <literal>type
</literal>:
</para>
442 <term><literal>program
</literal></term>
444 <para>Execute an external program specified as the assigned
445 value. If no absolute path is given, the program is expected
446 to live in
<filename>/usr/lib/udev
</filename>; otherwise, the
447 absolute path must be specified.
</para>
448 <para>This is the default if no
<replaceable>type
</replaceable>
453 <term><literal>builtin
</literal></term>
455 <para>As
<varname>program
</varname>, but use one of the
456 built-in programs rather than an external one.
</para>
460 <para>The program name and following arguments are separated by spaces.
461 Single quotes can be used to specify arguments with spaces.
</para>
462 <para>This can only be used for very short-running foreground tasks. Running an
463 event process for a long period of time may block all further events for
464 this or a dependent device.
</para>
465 <para>Starting daemons or other long-running processes is not appropriate
466 for udev; the forked processes, detached or not, will be unconditionally
467 killed after the event handling has finished.
</para>
472 <term><varname>LABEL
</varname></term>
474 <para>A named label to which a
<varname>GOTO
</varname> may jump.
</para>
479 <term><varname>GOTO
</varname></term>
481 <para>Jumps to the next
<varname>LABEL
</varname> with a matching name.
</para>
486 <term><varname>IMPORT{
<replaceable>type
</replaceable>}
</varname></term>
488 <para>Import a set of variables as device properties,
489 depending on
<literal>type
</literal>:
</para>
492 <term><literal>program
</literal></term>
494 <para>Execute an external program specified as the assigned
495 value and, if it returns successfully,
496 import its output, which must be in environment key
497 format. Path specification, command/argument separation,
498 and quoting work like in
<varname>RUN
</varname>.
</para>
502 <term><literal>builtin
</literal></term>
504 <para>Similar to
<literal>program
</literal>, but use one of the
505 built-in programs rather than an external one.
</para>
509 <term><literal>file
</literal></term>
511 <para>Import a text file specified as the assigned value, the content
512 of which must be in environment key format.
</para>
516 <term><literal>db
</literal></term>
518 <para>Import a single property specified as the assigned value from the
519 current device database. This works only if the database is already populated
520 by an earlier event.
</para>
524 <term><literal>cmdline
</literal></term>
526 <para>Import a single property from the kernel command line. For simple flags
527 the value of the property is set to
<literal>1</literal>.
</para>
531 <term><literal>parent
</literal></term>
533 <para>Import the stored keys from the parent device by reading
534 the database entry of the parent device. The value assigned to
535 <option>IMPORT{parent}
</option> is used as a filter of key names
536 to import (with the same shell glob pattern matching used for
541 <para>This can only be used for very short-running foreground tasks. For details
542 see
<option>RUN
</option>.
</para>
547 <term><varname>OPTIONS
</varname></term>
549 <para>Rule and device options:
</para>
550 <variablelist class='udev-directives'
>
552 <term><option>link_priority=
<replaceable>value
</replaceable></option></term>
554 <para>Specify the priority of the created symlinks. Devices with higher
555 priorities overwrite existing symlinks of other devices. The default is
0.
</para>
559 <term><option>string_escape=
<replaceable>none|replace
</replaceable></option></term>
561 <para>Usually, control and other possibly unsafe characters are replaced
562 in strings used for device naming. The mode of replacement can be specified
563 with this option.
</para>
567 <term><option>static_node=
</option></term>
569 <para>Apply the permissions specified in this rule to the
570 static device node with the specified name. Also, for every
571 tag specified in this rule, create a symlink
573 <filename>/run/udev/static_node-tags/
<replaceable>tag
</replaceable></filename>
574 pointing at the static device node with the specified name.
575 Static device node creation is performed by systemd-tmpfiles
576 before systemd-udevd is started. The static nodes might not
577 have a corresponding kernel device; they are used to trigger
578 automatic kernel module loading when they are accessed.
</para>
582 <term><option>watch
</option></term>
584 <para>Watch the device node with inotify; when the node is
585 closed after being opened for writing, a change uevent is
590 <term><option>nowatch
</option></term>
592 <para>Disable the watching of a device node with inotify.
</para>
600 <para>The
<varname>NAME
</varname>,
<varname>SYMLINK
</varname>,
601 <varname>PROGRAM
</varname>,
<varname>OWNER
</varname>,
602 <varname>GROUP
</varname>,
<varname>MODE
</varname>,
<varname>SECLABEL
</varname>,
603 and
<varname>RUN
</varname> fields support simple string substitutions.
604 The
<varname>RUN
</varname> substitutions are performed after all rules
605 have been processed, right before the program is executed, allowing for
606 the use of device properties set by earlier matching rules. For all other
607 fields, substitutions are performed while the individual rule is being
608 processed. The available substitutions are:
</para>
609 <variablelist class='udev-directives'
>
611 <term><option>$kernel
</option>,
<option>%k
</option></term>
613 <para>The kernel name for this device.
</para>
618 <term><option>$number
</option>,
<option>%n
</option></term>
620 <para>The kernel number for this device. For example,
621 <literal>sda3
</literal> has kernel number
<literal>3</literal>.
627 <term><option>$devpath
</option>,
<option>%p
</option></term>
629 <para>The devpath of the device.
</para>
634 <term><option>$id
</option>,
<option>%b
</option></term>
636 <para>The name of the device matched while searching the devpath
637 upwards for
<option>SUBSYSTEMS
</option>,
<option>KERNELS
</option>,
638 <option>DRIVERS
</option>, and
<option>ATTRS
</option>.
644 <term><option>$driver
</option></term>
646 <para>The driver name of the device matched while searching the
647 devpath upwards for
<option>SUBSYSTEMS
</option>,
648 <option>KERNELS
</option>,
<option>DRIVERS
</option>, and
649 <option>ATTRS
</option>.
655 <term><option>$attr{
<replaceable>file
</replaceable>}
</option>,
<option>%s{
<replaceable>file
</replaceable>}
</option></term>
657 <para>The value of a sysfs attribute found at the device where
658 all keys of the rule have matched. If the matching device does not
659 have such an attribute, and a previous
<option>KERNELS
</option>,
660 <option>SUBSYSTEMS
</option>,
<option>DRIVERS
</option>, or
661 <option>ATTRS
</option> test selected a parent device, then the
662 attribute from that parent device is used.
664 <para>If the attribute is a symlink, the last element of the
665 symlink target is returned as the value.
671 <term><option>$env{
<replaceable>key
</replaceable>}
</option>,
<option>%E{
<replaceable>key
</replaceable>}
</option></term>
673 <para>A device property value.
</para>
678 <term><option>$major
</option>,
<option>%M
</option></term>
680 <para>The kernel major number for the device.
</para>
685 <term><option>$minor
</option>,
<option>%m
</option></term>
687 <para>The kernel minor number for the device.
</para>
692 <term><option>$result
</option>,
<option>%c
</option></term>
694 <para>The string returned by the external program requested with
695 <varname>PROGRAM
</varname>.
696 A single part of the string, separated by a space character, may be selected
697 by specifying the part number as an attribute:
<literal>%c{N}
</literal>.
698 If the number is followed by the
<literal>+
</literal> character, this part plus all remaining parts
699 of the result string are substituted:
<literal>%c{N+}
</literal>.
</para>
704 <term><option>$parent
</option>,
<option>%P
</option></term>
706 <para>The node name of the parent device.
</para>
711 <term><option>$name
</option></term>
713 <para>The current name of the device. If not changed by a rule, it is the
714 name of the kernel device.
</para>
719 <term><option>$links
</option></term>
721 <para>A space-separated list of the current symlinks. The value is
722 only set during a remove event or if an earlier rule assigned a value.
</para>
727 <term><option>$root
</option>,
<option>%r
</option></term>
729 <para>The udev_root value.
</para>
734 <term><option>$sys
</option>,
<option>%S
</option></term>
736 <para>The sysfs mount point.
</para>
741 <term><option>$devnode
</option>,
<option>%N
</option></term>
743 <para>The name of the device node.
</para>
748 <term><option>%%
</option></term>
750 <para>The
<literal>%
</literal> character itself.
</para>
755 <term><option>$$
</option></term>
757 <para>The
<literal>$
</literal> character itself.
</para>
764 <title>See Also
</title>
767 <refentrytitle>systemd-udevd.service
</refentrytitle><manvolnum>8</manvolnum>
770 <refentrytitle>udevadm
</refentrytitle><manvolnum>8</manvolnum>
773 <refentrytitle>systemd.link
</refentrytitle><manvolnum>5</manvolnum>