1UDEV(7)                              udev                              UDEV(7)
2
3
4

NAME

6       udev - Dynamic device management
7

DESCRIPTION

9       udev supplies the system software with device events, manages
10       permissions of device nodes and may create additional symlinks in the
11       /dev/ directory, or renames network interfaces. The kernel usually just
12       assigns unpredictable device names based on the order of discovery.
13       Meaningful symlinks or network device names provide a way to reliably
14       identify devices based on their properties or current configuration.
15
16       The udev daemon, systemd-udevd.service(8), receives device uevents
17       directly from the kernel whenever a device is added or removed from the
18       system, or it changes its state. When udev receives a device event, it
19       matches its configured set of rules against various device attributes
20       to identify the device. Rules that match may provide additional device
21       information to be stored in the udev database or to be used to create
22       meaningful symlink names.
23
24       All device information udev processes is stored in the udev database
25       and sent out to possible event subscribers. Access to all stored data
26       and the event sources is provided by the library libudev.
27

RULES FILES

29       The udev rules are read from the files located in the system rules
30       directories /usr/lib/udev/rules.d and /usr/local/lib/udev/rules.d, the
31       volatile runtime directory /run/udev/rules.d and the local
32       administration directory /etc/udev/rules.d. All rules files are
33       collectively sorted and processed in lexical order, regardless of the
34       directories in which they live. However, files with identical filenames
35       replace each other. Files in /etc/ have the highest priority, files in
36       /run/ take precedence over files with the same name under /usr/. This
37       can be used to override a system-supplied rules file with a local file
38       if needed; a symlink in /etc/ with the same name as a rules file in
39       /usr/lib/, pointing to /dev/null, disables the rules file entirely.
40       Rule files must have the extension .rules; other extensions are
41       ignored.
42
43       Every line in the rules file contains at least one key-value pair.
44       Except for empty lines or lines beginning with "#", which are ignored.
45       There are two kinds of keys: match and assignment. If all match keys
46       match against their values, the rule gets applied and the assignment
47       keys get the specified values assigned.
48
49       A matching rule may rename a network interface, add symlinks pointing
50       to the device node, or run a specified program as part of the event
51       handling.
52
53       A rule consists of a comma-separated list of one or more
54       key-operator-value expressions. Each expression has a distinct effect,
55       depending on the key and operator used.
56
57   Operators
58       "=="
59           Compare for equality. (The specified key has the specified value.)
60
61       "!="
62           Compare for inequality. (The specified key doesn't have the
63           specified value, or the specified key is not present at all.)
64
65       "="
66           Assign a value to a key. Keys that represent a list are reset and
67           only this single value is assigned.
68
69       "+="
70           Add the value to a key that holds a list of entries.
71
72       "-="
73           Remove the value from a key that holds a list of entries.
74
75       ":="
76           Assign a value to a key finally; disallow any later changes.
77
78   Values
79       Values are written as double quoted strings, such as ("string"). To
80       include a quotation mark (") in the value, precede it by a backslash
81       (\"). Any other occurrences of a backslash followed by a character are
82       not unescaped. That is, "\t\n" is treated as four characters:
83       backslash, lowercase t, backslash, lowercase n.
84
85       The string can be prefixed with a lowercase e (e"string\n") to mark the
86       string as C-style escaped[1]. For example, e"string\n" is parsed as 7
87       characters: 6 lowercase letters and a newline. This can be useful for
88       writing special characters when a kernel driver requires them.
89
90       Please note that NUL is not allowed in either string variant.
91
92   Keys
93       The following key names can be used to match against device properties.
94       Some of the keys also match against properties of the parent devices in
95       sysfs, not only the device that has generated the event. If multiple
96       keys that match a parent device are specified in a single rule, all
97       these keys must match at one and the same parent device.
98
99       ACTION
100           Match the name of the event action.
101
102       DEVPATH
103           Match the devpath of the event device.
104
105       KERNEL
106           Match the name of the event device.
107
108       KERNELS
109           Search the devpath upwards for a matching device name.
110
111       NAME
112           Match the name of a network interface. It can be used once the NAME
113           key has been set in one of the preceding rules.
114
115       SYMLINK
116           Match the name of a symlink targeting the node. It can be used once
117           a SYMLINK key has been set in one of the preceding rules. There may
118           be multiple symlinks; only one needs to match. If the operator is
119           "!=", the token returns true only if there is no symlink matched.
120
121       SUBSYSTEM
122           Match the subsystem of the event device.
123
124       SUBSYSTEMS
125           Search the devpath upwards for a matching device subsystem name.
126
127       DRIVER
128           Match the driver name of the event device. Only set this key for
129           devices which are bound to a driver at the time the event is
130           generated.
131
132       DRIVERS
133           Search the devpath upwards for a matching device driver name.
134
135       ATTR{filename}
136           Match sysfs attribute value of the event device.
137
138           Trailing whitespace in the attribute values is ignored unless the
139           specified match value itself contains trailing whitespace.
140
141       ATTRS{filename}
142           Search the devpath upwards for a device with matching sysfs
143           attribute values. If multiple ATTRS matches are specified, all of
144           them must match on the same device.
145
146           Trailing whitespace in the attribute values is ignored unless the
147           specified match value itself contains trailing whitespace.
148
149       SYSCTL{kernel parameter}
150           Match a kernel parameter value.
151
152       ENV{key}
153           Match against a device property value.
154
155       CONST{key}
156           Match against a system-wide constant. Supported keys are:
157
158           "arch"
159               System's architecture. See ConditionArchitecture= in
160               systemd.unit(5) for possible values.
161
162           "virt"
163               System's virtualization environment. See systemd-detect-virt(1)
164               for possible values.
165
166           "cvm"
167               System's confidential virtualization technology. See systemd-
168               detect-virt(1) for possible values.
169
170           Unknown keys will never match.
171
172       TAG
173           Match against one of device tags. It can be used once a TAG key has
174           been set in one of the preceding rules. There may be multiple tags;
175           only one needs to match. If the operator is "!=", the token returns
176           true only if there is no tag matched.
177
178       TAGS
179           Search the devpath upwards for a device with matching tag. If the
180           operator is "!=", the token returns true only if there is no tag
181           matched.
182
183       TEST{octal mode mask}
184           Test the existence of a file. An octal mode mask can be specified
185           if needed.
186
187       PROGRAM
188           Execute a program to determine whether there is a match; the key is
189           true if the program returns successfully. The device properties are
190           made available to the executed program in the environment. The
191           program's standard output is available in the RESULT key.
192
193           This can only be used for very short-running foreground tasks. For
194           details, see RUN.
195
196           Note that multiple PROGRAM keys may be specified in one rule, and
197           "=", ":=", and "+=" have the same effect as "==".
198
199       RESULT
200           Match the returned string of the last PROGRAM call. This key can be
201           used in the same or in any later rule after a PROGRAM call.
202
203       Most of the fields support shell glob pattern matching and alternate
204       patterns. The following special characters are supported:
205
206       "*"
207           Matches zero or more characters.
208
209       "?"
210           Matches any single character.
211
212       "[]"
213           Matches any single character specified within the brackets. For
214           example, the pattern string "tty[SR]" would match either "ttyS" or
215           "ttyR". Ranges are also supported via the "-" character. For
216           example, to match on the range of all digits, the pattern "[0-9]"
217           could be used. If the first character following the "[" is a "!",
218           any characters not enclosed are matched.
219
220       "|"
221           Separates alternative patterns. For example, the pattern string
222           "abc|x*" would match either "abc" or "x*".
223
224       The following keys can get values assigned:
225
226       NAME
227           The name to use for a network interface. See systemd.link(5) for a
228           higher-level mechanism for setting the interface name. The name of
229           a device node cannot be changed by udev, only additional symlinks
230           can be created.
231
232       SYMLINK
233           The name of a symlink targeting the node. Every matching rule adds
234           this value to the list of symlinks to be created.
235
236           The set of characters to name a symlink is limited. Allowed
237           characters are "0-9A-Za-z#+-.:=@_/", valid UTF-8 character
238           sequences, and "\x00" hex encoding. All other characters are
239           replaced by a "_" character.
240
241           Multiple symlinks may be specified by separating the names by the
242           space character. In case multiple devices claim the same name, the
243           link always points to the device with the highest link_priority. If
244           the current device goes away, the links are re-evaluated and the
245           device with the next highest link_priority becomes the owner of the
246           link. If no link_priority is specified, the order of the devices
247           (and which one of them owns the link) is undefined.
248
249           Symlink names must never conflict with the kernel's default device
250           node names, as that would result in unpredictable behavior.
251
252       OWNER, GROUP, MODE
253           The permissions for the device node. Every specified value
254           overrides the compiled-in default value.
255
256       SECLABEL{module}
257           Applies the specified Linux Security Module label to the device
258           node.
259
260       ATTR{key}
261           The value that should be written to a sysfs attribute of the event
262           device.
263
264       SYSCTL{kernel parameter}
265           The value that should be written to kernel parameter.
266
267       ENV{key}
268           Set a device property value. Property names with a leading "."  are
269           neither stored in the database nor exported to events or external
270           tools (run by, for example, the PROGRAM match key).
271
272       TAG
273           Attach a tag to a device. This is used to filter events for users
274           of libudev's monitor functionality, or to enumerate a group of
275           tagged devices. The implementation can only work efficiently if
276           only a few tags are attached to a device. It is only meant to be
277           used in contexts with specific device filter requirements, and not
278           as a general-purpose flag. Excessive use might result in
279           inefficient event handling.
280
281       RUN{type}
282           Specify a program to be executed after processing of all the rules
283           for the event. With "+=", this invocation is added to the list, and
284           with "=" or ":=", it replaces any previous contents of the list.
285           Please note that both "program" and "builtin" types described below
286           share a common list, so clearing the list with ":=" and "=" affects
287           both types.
288
289           type may be:
290
291           "program"
292               Execute an external program specified as the assigned value. If
293               no absolute path is given, the program is expected to live in
294               /usr/lib/udev; otherwise, the absolute path must be specified.
295
296               This is the default if no type is specified.
297
298           "builtin"
299               As program, but use one of the built-in programs rather than an
300               external one.
301
302           The program name and following arguments are separated by spaces.
303           Single quotes can be used to specify arguments with spaces.
304
305           This can only be used for very short-running foreground tasks.
306           Running an event process for a long period of time may block all
307           further events for this or a dependent device.
308
309           Note that running programs that access the network or mount/unmount
310           filesystems is not allowed inside of udev rules, due to the default
311           sandbox that is enforced on systemd-udevd.service.
312
313           Starting daemons or other long-running processes is not allowed;
314           the forked processes, detached or not, will be unconditionally
315           killed after the event handling has finished. In order to activate
316           long-running processes from udev rules, provide a service unit and
317           pull it in from a udev device using the SYSTEMD_WANTS device
318           property. See systemd.device(5) for details.
319
320       LABEL
321           A named label to which a GOTO may jump.
322
323       GOTO
324           Jumps to the next LABEL with a matching name.
325
326       IMPORT{type}
327           Import a set of variables as device properties, depending on type:
328
329           "program"
330               Execute an external program specified as the assigned value
331               and, if it returns successfully, import its output, which must
332               be in environment key format. Path specification,
333               command/argument separation, and quoting work like in RUN.
334
335           "builtin"
336               Similar to "program", but use one of the built-in programs
337               rather than an external one.
338
339           "file"
340               Import a text file specified as the assigned value, the content
341               of which must be in environment key format.
342
343           "db"
344               Import a single property specified as the assigned value from
345               the current device database. This works only if the database is
346               already populated by an earlier event.
347
348           "cmdline"
349               Import a single property from the kernel command line. For
350               simple flags the value of the property is set to "1".
351
352           "parent"
353               Import the stored keys from the parent device by reading the
354               database entry of the parent device. The value assigned to
355               IMPORT{parent} is used as a filter of key names to import (with
356               the same shell glob pattern matching used for comparisons).
357
358           This can only be used for very short-running foreground tasks. For
359           details see RUN.
360
361           Note that multiple IMPORT{} keys may be specified in one rule, and
362           "=", ":=", and "+=" have the same effect as "==". The key is true
363           if the import is successful, unless "!=" is used as the operator
364           which causes the key to be true if the import failed.
365
366       OPTIONS
367           Rule and device options:
368
369           link_priority=value
370               Specify the priority of the created symlinks. Devices with
371               higher priorities overwrite existing symlinks of other devices.
372               The default is 0.
373
374           string_escape=none|replace
375               When "replace", possibly unsafe characters in strings assigned
376               to NAME, SYMLINK, and ENV{key} are replaced. When "none", no
377               replacement is performed. When unset, the replacement is
378               performed for NAME, SYMLINK, but not for ENV{key}. Defaults to
379               unset.
380
381           static_node=
382               Apply the permissions specified in this rule to the static
383               device node with the specified name. Also, for every tag
384               specified in this rule, create a symlink in the directory
385               /run/udev/static_node-tags/tag pointing at the static device
386               node with the specified name. Static device node creation is
387               performed by systemd-tmpfiles before systemd-udevd is started.
388               The static nodes might not have a corresponding kernel device;
389               they are used to trigger automatic kernel module loading when
390               they are accessed.
391
392           watch
393               Watch the device node with inotify; when the node is closed
394               after being opened for writing, a change uevent is synthesized.
395
396           nowatch
397               Disable the watching of a device node with inotify.
398
399           db_persist
400               Set the flag (sticky bit) on the udev database entry of the
401               event device. Device properties are then kept in the database
402               even when udevadm info --cleanup-db is called. This option can
403               be useful in certain cases (e.g. Device Mapper devices) for
404               persisting device state on the transition from initrd.
405
406           log_level=level
407               Takes a log level name like "debug" or "info", or a special
408               value "reset". When a log level name is specified, the maximum
409               log level is changed to that level. When "reset" is set, then
410               the previously specified log level is revoked. Defaults to the
411               log level of the main process of systemd-udevd.
412
413               This may be useful when debugging events for certain devices.
414               Note that the log level is applied when the line including this
415               rule is processed. So, for debugging, it is recommended that
416               this is specified at earlier place, e.g., the first line of
417               00-debug.rules.
418
419               Example for debugging uevent processing for network interfaces:
420
421                   # /etc/udev/rules.d/00-debug-net.rules
422                   SUBSYSTEM=="net", OPTIONS="log_level=debug"
423
424       The NAME, SYMLINK, PROGRAM, OWNER, GROUP, MODE, SECLABEL, and RUN
425       fields support simple string substitutions. The RUN substitutions are
426       performed after all rules have been processed, right before the program
427       is executed, allowing for the use of device properties set by earlier
428       matching rules. For all other fields, substitutions are performed while
429       the individual rule is being processed. The available substitutions
430       are:
431
432       $kernel, %k
433           The kernel name for this device.
434
435       $number, %n
436           The kernel number for this device. For example, "sda3" has kernel
437           number 3.
438
439       $devpath, %p
440           The devpath of the device.
441
442       $id, %b
443           The name of the device matched while searching the devpath upwards
444           for SUBSYSTEMS, KERNELS, DRIVERS, and ATTRS.
445
446       $driver
447           The driver name of the device matched while searching the devpath
448           upwards for SUBSYSTEMS, KERNELS, DRIVERS, and ATTRS.
449
450       $attr{file}, %s{file}
451           The value of a sysfs attribute found at the device where all keys
452           of the rule have matched. If the matching device does not have such
453           an attribute, and a previous KERNELS, SUBSYSTEMS, DRIVERS, or ATTRS
454           test selected a parent device, then the attribute from that parent
455           device is used.
456
457           If the attribute is a symlink, the last element of the symlink
458           target is returned as the value.
459
460       $env{key}, %E{key}
461           A device property value.
462
463       $major, %M
464           The kernel major number for the device.
465
466       $minor, %m
467           The kernel minor number for the device.
468
469       $result, %c
470           The string returned by the external program requested with PROGRAM.
471           A single part of the string, separated by a space character, may be
472           selected by specifying the part number as an attribute: "%c{N}". If
473           the number is followed by the "+" character, this part plus all
474           remaining parts of the result string are substituted: "%c{N+}".
475
476       $parent, %P
477           The node name of the parent device.
478
479       $name
480           The current name of the device. If not changed by a rule, it is the
481           name of the kernel device.
482
483       $links
484           A space-separated list of the current symlinks. The value is only
485           set during a remove event or if an earlier rule assigned a value.
486
487       $root, %r
488           The udev_root value.
489
490       $sys, %S
491           The sysfs mount point.
492
493       $devnode, %N
494           The name of the device node.
495
496       %%
497           The "%" character itself.
498
499       $$
500           The "$" character itself.
501

SEE ALSO

503       systemd-udevd.service(8), udevadm(8), systemd.link(5)
504

NOTES

506        1. C-style escaped
507           https://en.wikipedia.org/wiki/Escape_sequences_in_C#Table_of_escape_sequences
508
509
510
511systemd 254                                                            UDEV(7)
Impressum