UDEV(7) | udev | UDEV(7) |
udev - Dynamic device management
udev supplies the system software with device events, manages permissions of device nodes, may create additional symlinks in the /dev directory and may rename network interfaces. The kernel usually just assigns unpredictable device names based on the order of discovery. Meaningful symlinks or network device names provide a way to reliably identify devices based on their properties or current configuration.
The udev daemon, udevd(8), receives device uevents directly from the kernel whenever a device is added or removed from the system, or it changes its state. When udev receives a device event, it matches its configured set of rules against various device attributes to identify the device. Rules that match may provide additional device information to be stored in the udev database or to be used to create meaningful symlink names.
All device information udev processes is stored in the udev database and sent out to possible event subscribers. Access to all stored data and the event sources is provided by the library libudev.
The udev rules are read from the files located in the system rules directory /lib/udev/rules.d (additionally /usr/lib/udev/rules.d when built with --enable-split-usr), the volatile runtime directory /run/udev/rules.d and the local administration directory /etc/udev/rules.d. All rules files are collectively sorted and processed in lexical order, regardless of the directories in which they live. However, files with identical filenames replace each other. Files in /etc have the highest priority, files in /run take precedence over files with the same name in /lib (or /usr/lib). This can be used to override a system-supplied rules file with a local file if needed; a symlink in /etc with the same name as a rules file in /lib, pointing to /dev/null, disables the rules file entirely. Rule files must have the extension .rules; other extensions are ignored.
Every line in the rules file contains at least one key-value pair. Except for empty lines or lines beginning with #, which are ignored. There are two kinds of keys: match and assignment. If all match keys match against their values, the rule gets applied and the assignment keys get the specified values assigned.
A matching rule may rename a network interface, add symlinks pointing to the device node, or run a specified program as part of the event handling.
A rule consists of a comma-separated list of one or more key-value pairs. Each key has a distinct operation, depending on the used operator. Valid operators are:
==
!=
=
+=
-=
:=
The following key names can be used to match against device properties. Some of the keys also match against properties of the parent devices in sysfs, not only the device that has generated the event. If multiple keys that match a parent device are specified in a single rule, all these keys must match at one and the same parent device.
ACTION
DEVPATH
KERNEL
NAME
SYMLINK
SUBSYSTEM
DRIVER
ATTR{filename}, SYSCTL{kernel parameter}
KERNELS
SUBSYSTEMS
DRIVERS
ATTRS{filename}
TAGS
ENV{key}
TAG
TEST{octal mode mask}
PROGRAM
This can only be used for very short-running foreground tasks. For details, see RUN.
RESULT
Most of the fields support shell glob pattern matching and alternate patterns. The following special characters are supported:
*
?
[]
|
The following keys can get values assigned:
NAME
SYMLINK
The set of characters to name a symlink is limited. Allowed characters are 0-9A-Za-z#+-.:=@_/, valid UTF-8 character sequences, and \x00 hex encoding. All other characters are replaced by a _ character.
Multiple symlinks may be specified by separating the names by the space character. In case multiple devices claim the same name, the link always points to the device with the highest link_priority. If the current device goes away, the links are re-evaluated and the device with the next highest link_priority becomes the owner of the link. If no link_priority is specified, the order of the devices (and which one of them owns the link) is undefined.
Symlink names must never conflict with the kernel's default device node names, as that would result in unpredictable behavior.
OWNER, GROUP, MODE
SECLABEL{module}
ATTR{key}
SYSCTL{kernel parameter}
ENV{key}
TAG
RUN{type}
program
This is the default if no type is specified.
builtin
The program name and following arguments are separated by spaces. Single quotes can be used to specify arguments with spaces.
This can only be used for very short-running foreground tasks. Running an event process for a long period of time may block all further events for this or a dependent device.
Starting daemons or other long-running processes is not appropriate for udev; the forked processes, detached or not, will be unconditionally killed after the event handling has finished.
LABEL
GOTO
IMPORT{type}
program
builtin
file
db
cmdline
parent
This can only be used for very short-running foreground tasks. For details see RUN.
WAIT_FOR
OPTIONS
link_priority=value
string_escape=none|replace
static_node=
watch
nowatch
The NAME, SYMLINK, PROGRAM, OWNER, GROUP, MODE, and RUN fields support simple string substitutions. The RUN substitutions are performed after all rules have been processed, right before the program is executed, allowing for the use of device properties set by earlier matching rules. For all other fields, substitutions are performed while the individual rule is being processed. The available substitutions are:
$kernel, %k
$number, %n
$devpath, %p
$id, %b
$driver
$attr{file}, %s{file}
If the attribute is a symlink, the last element of the symlink target is returned as the value.
$env{key}, %E{key}
$major, %M
$minor, %m
$result, %c
$parent, %P
$name
$links
$sys, %S
$devnode, %N
%%
$$
The hwdb files are read from the files located in the system hwdb directory /usr/lib/udev/hwdb.d, the local administration directory /etc/udev/hwdb.d, and any other directory in the UDEV_HWDB_PATH search path variable. All hwdb files are collectively sorted and processed in lexical order, regardless of the directories in which they live. However, files with identical filenames replace each other. Files in /etc have the highest priority, then files in /usr/lib, and the ones in UDEV_HWDB_PATH comes last. Files with higher priority take precedence over files with the same name and lower priority. This order can be used to override a system-supplied hwdb file with a local file if needed; a symlink in /etc with the same name as a hwdb file in /usr/lib or UDEV_HWDB_PATH, pointing to /dev/null, disables the hwdb file entirely. hwdb files must have the extension .hwdb; other extensions are ignored.
The hwdb file contains data records consisting of matches and associated key-value pairs. Every record in the hwdb starts with one or more match string, specifying a shell glob to compare the database lookup string against. Multiple match lines are specified in additional consecutive lines. Every match line is compared individually, they are combined by OR. Every match line must start at the first character of the line.
The match lines are followed by one or more key-value pair lines, which are recognized by a leading space character. The key name and value are separated by =. An empty line signifies the end of a record. Lines beginning with # are ignored.
The content of all hwdb files is read by udevadm(8) and compiled to a binary database located at /etc/udev/hwdb.bin, or alternatively /usr/lib/udev/hwdb.bin, if you want to ship the compiled database in an immutable image by using --usr, or anywhere on the system by using --output. If UDEV_HWDB_BIN is set at run-time, and its value identifies a file in the file system, then the binary database located under this name will be used. During runtime only the binary database is used.
udevd(8), udevadm(8)
udev |