table of contents
UDEV(7) | udev | UDEV(7) |
NAME¶
udev - Dynamic device management
DESCRIPTION¶
udev supplies the system software with device events, manages permissions of device nodes and may create additional symlinks in the /dev/ directory, or renames 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, systemd-udevd.service(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.
RULES FILES¶
The udev rules are read from the files located in the system rules directories /usr/lib/udev/rules.d and /usr/local/lib/udev/rules.d, 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 under /usr/. 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 /usr/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-operator-value expressions. Each expression has a distinct effect, depending on the key and operator used.
Operators¶
"=="
"!="
"="
"+="
"-="
Added in version 217.
":="
Added in version 247.
Values¶
Values are written as double quoted strings, such as ("string"). To include a quotation mark (") in the value, precede it by a backslash (\"). Any other occurrences of a backslash followed by a character are not unescaped. That is, "\t\n" is treated as four characters: backslash, lowercase t, backslash, lowercase n.
The string can be prefixed with a lowercase e (e"string\n") to mark the string as C-style escaped, see Escape sequences in C[1]. For example, e"string\n" is parsed as 7 characters: 6 lowercase letters and a newline. This can be useful for writing special characters when a kernel driver requires them.
Please note that NUL is not allowed in either string variant.
Keys¶
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
KERNELS
NAME
SYMLINK
SUBSYSTEM
SUBSYSTEMS
DRIVER
DRIVERS
ATTR{filename}
Trailing whitespace in the attribute values is ignored unless the specified match value itself contains trailing whitespace.
ATTRS{filename}
Trailing whitespace in the attribute values is ignored unless the specified match value itself contains trailing whitespace.
SYSCTL{kernel parameter}
Added in version 240.
ENV{key}
CONST{key}
"arch"
Added in version 244.
"virt"
Added in version 244.
"cvm"
Added in version 254.
Unknown keys will never match.
Added in version 244.
TAG
TAGS
TEST{octal mode mask}
PROGRAM
This can only be used for very short-running foreground tasks. For details, see RUN.
Note that multiple PROGRAM keys may be specified in one rule, and "=", ":=", and "+=" have the same effect as "==".
RESULT
Most of the fields support shell glob pattern matching and alternate patterns. The following special characters are supported:
"*"
"?"
"[]"
"|"
Added in version 217.
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}
Added in version 209.
ATTR{key}
SYSCTL{kernel parameter}
Added in version 220.
ENV{key}
TAG
RUN{type}
type may be:
"program"
This is the default if no type is specified.
"builtin"
Added in version 199.
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.
Note that running programs that access the network or mount/unmount filesystems is not allowed inside of udev rules, due to the default sandbox that is enforced on systemd-udevd.service.
Starting daemons or other long-running processes is not allowed; the forked processes, detached or not, will be unconditionally killed after the event handling has finished. In order to activate long-running processes from udev rules, provide a service unit and pull it in from a udev device using the SYSTEMD_WANTS device property. See systemd.device(5) for details.
LABEL
GOTO
IMPORT{type}
"program"
Added in version 199.
"builtin"
Added in version 199.
"file"
"db"
"cmdline"
"parent"
This can only be used for very short-running foreground tasks. For details see RUN.
Note that multiple IMPORT{} keys may be specified in one rule, and "=", ":=", and "+=" have the same effect as "==". The key is true if the import is successful, unless "!=" is used as the operator which causes the key to be true if the import failed.
OPTIONS
link_priority=value
string_escape=none|replace
static_node=
watch
nowatch
db_persist
Added in version 241.
log_level=level
This may be useful when debugging events for certain devices. Note that the log level is applied when the line including this rule is processed. So, for debugging, it is recommended that this is specified at earlier place, e.g., the first line of 00-debug.rules.
Example for debugging uevent processing for network interfaces:
# /etc/udev/rules.d/00-debug-net.rules SUBSYSTEM=="net", OPTIONS="log_level=debug"
Added in version 248.
The ENV, GROUP, MODE, NAME, OWNER, PROGRAM, RUN, SECLABEL, and SYMLINK 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
$root, %r
$sys, %S
$devnode, %N
%%
$$
SEE ALSO¶
NOTES¶
- 1.
- Escape sequences in C
systemd 256.7 |