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           Unknown keys will never match.
167
168       TAG
169           Match against one of device tags. It can be used once a TAG key has
170           been set in one of the preceding rules. There may be multiple tags;
171           only one needs to match. If the operator is "!=", the token returns
172           true only if there is no tag matched.
173
174       TAGS
175           Search the devpath upwards for a device with matching tag. If the
176           operator is "!=", the token returns true only if there is no tag
177           matched.
178
179       TEST{octal mode mask}
180           Test the existence of a file. An octal mode mask can be specified
181           if needed.
182
183       PROGRAM
184           Execute a program to determine whether there is a match; the key is
185           true if the program returns successfully. The device properties are
186           made available to the executed program in the environment. The
187           program's standard output is available in the RESULT key.
188
189           This can only be used for very short-running foreground tasks. For
190           details, see RUN.
191
192           Note that multiple PROGRAM keys may be specified in one rule, and
193           "=", ":=", and "+=" have the same effect as "==".
194
195       RESULT
196           Match the returned string of the last PROGRAM call. This key can be
197           used in the same or in any later rule after a PROGRAM call.
198
199       Most of the fields support shell glob pattern matching and alternate
200       patterns. The following special characters are supported:
201
202       "*"
203           Matches zero or more characters.
204
205       "?"
206           Matches any single character.
207
208       "[]"
209           Matches any single character specified within the brackets. For
210           example, the pattern string "tty[SR]" would match either "ttyS" or
211           "ttyR". Ranges are also supported via the "-" character. For
212           example, to match on the range of all digits, the pattern "[0-9]"
213           could be used. If the first character following the "[" is a "!",
214           any characters not enclosed are matched.
215
216       "|"
217           Separates alternative patterns. For example, the pattern string
218           "abc|x*" would match either "abc" or "x*".
219
220       The following keys can get values assigned:
221
222       NAME
223           The name to use for a network interface. See systemd.link(5) for a
224           higher-level mechanism for setting the interface name. The name of
225           a device node cannot be changed by udev, only additional symlinks
226           can be created.
227
228       SYMLINK
229           The name of a symlink targeting the node. Every matching rule adds
230           this value to the list of symlinks to be created.
231
232           The set of characters to name a symlink is limited. Allowed
233           characters are "0-9A-Za-z#+-.:=@_/", valid UTF-8 character
234           sequences, and "\x00" hex encoding. All other characters are
235           replaced by a "_" character.
236
237           Multiple symlinks may be specified by separating the names by the
238           space character. In case multiple devices claim the same name, the
239           link always points to the device with the highest link_priority. If
240           the current device goes away, the links are re-evaluated and the
241           device with the next highest link_priority becomes the owner of the
242           link. If no link_priority is specified, the order of the devices
243           (and which one of them owns the link) is undefined.
244
245           Symlink names must never conflict with the kernel's default device
246           node names, as that would result in unpredictable behavior.
247
248       OWNER, GROUP, MODE
249           The permissions for the device node. Every specified value
250           overrides the compiled-in default value.
251
252       SECLABEL{module}
253           Applies the specified Linux Security Module label to the device
254           node.
255
256       ATTR{key}
257           The value that should be written to a sysfs attribute of the event
258           device.
259
260       SYSCTL{kernel parameter}
261           The value that should be written to kernel parameter.
262
263       ENV{key}
264           Set a device property value. Property names with a leading "."  are
265           neither stored in the database nor exported to events or external
266           tools (run by, for example, the PROGRAM match key).
267
268       TAG
269           Attach a tag to a device. This is used to filter events for users
270           of libudev's monitor functionality, or to enumerate a group of
271           tagged devices. The implementation can only work efficiently if
272           only a few tags are attached to a device. It is only meant to be
273           used in contexts with specific device filter requirements, and not
274           as a general-purpose flag. Excessive use might result in
275           inefficient event handling.
276
277       RUN{type}
278           Specify a program to be executed after processing of all the rules
279           for the event. With "+=", this invocation is added to the list, and
280           with "=" or ":=", it replaces any previous contents of the list.
281           Please note that both "program" and "builtin" types described below
282           share a common list, so clearing the list with ":=" and "=" affects
283           both types.
284
285           type may be:
286
287           "program"
288               Execute an external program specified as the assigned value. If
289               no absolute path is given, the program is expected to live in
290               /usr/lib/udev; otherwise, the absolute path must be specified.
291
292               This is the default if no type is specified.
293
294           "builtin"
295               As program, but use one of the built-in programs rather than an
296               external one.
297
298           The program name and following arguments are separated by spaces.
299           Single quotes can be used to specify arguments with spaces.
300
301           This can only be used for very short-running foreground tasks.
302           Running an event process for a long period of time may block all
303           further events for this or a dependent device.
304
305           Note that running programs that access the network or mount/unmount
306           filesystems is not allowed inside of udev rules, due to the default
307           sandbox that is enforced on systemd-udevd.service.
308
309           Starting daemons or other long-running processes is not allowed;
310           the forked processes, detached or not, will be unconditionally
311           killed after the event handling has finished. In order to activate
312           long-running processes from udev rules, provide a service unit and
313           pull it in from a udev device using the SYSTEMD_WANTS device
314           property. See systemd.device(5) for details.
315
316       LABEL
317           A named label to which a GOTO may jump.
318
319       GOTO
320           Jumps to the next LABEL with a matching name.
321
322       IMPORT{type}
323           Import a set of variables as device properties, depending on type:
324
325           "program"
326               Execute an external program specified as the assigned value
327               and, if it returns successfully, import its output, which must
328               be in environment key format. Path specification,
329               command/argument separation, and quoting work like in RUN.
330
331           "builtin"
332               Similar to "program", but use one of the built-in programs
333               rather than an external one.
334
335           "file"
336               Import a text file specified as the assigned value, the content
337               of which must be in environment key format.
338
339           "db"
340               Import a single property specified as the assigned value from
341               the current device database. This works only if the database is
342               already populated by an earlier event.
343
344           "cmdline"
345               Import a single property from the kernel command line. For
346               simple flags the value of the property is set to "1".
347
348           "parent"
349               Import the stored keys from the parent device by reading the
350               database entry of the parent device. The value assigned to
351               IMPORT{parent} is used as a filter of key names to import (with
352               the same shell glob pattern matching used for comparisons).
353
354           This can only be used for very short-running foreground tasks. For
355           details see RUN.
356
357           Note that multiple IMPORT{} keys may be specified in one rule, and
358           "=", ":=", and "+=" have the same effect as "==". The key is true
359           if the import is successful, unless "!=" is used as the operator
360           which causes the key to be true if the import failed.
361
362       OPTIONS
363           Rule and device options:
364
365           link_priority=value
366               Specify the priority of the created symlinks. Devices with
367               higher priorities overwrite existing symlinks of other devices.
368               The default is 0.
369
370           string_escape=none|replace
371               When "replace", possibly unsafe characters in strings assigned
372               to NAME, SYMLINK, and ENV{key} are replaced. When "none", no
373               replacement is performed. When unset, the replacement is
374               performed for NAME, SYMLINK, but not for ENV{key}. Defaults to
375               unset.
376
377           static_node=
378               Apply the permissions specified in this rule to the static
379               device node with the specified name. Also, for every tag
380               specified in this rule, create a symlink in the directory
381               /run/udev/static_node-tags/tag pointing at the static device
382               node with the specified name. Static device node creation is
383               performed by systemd-tmpfiles before systemd-udevd is started.
384               The static nodes might not have a corresponding kernel device;
385               they are used to trigger automatic kernel module loading when
386               they are accessed.
387
388           watch
389               Watch the device node with inotify; when the node is closed
390               after being opened for writing, a change uevent is synthesized.
391
392           nowatch
393               Disable the watching of a device node with inotify.
394
395           db_persist
396               Set the flag (sticky bit) on the udev database entry of the
397               event device. Device properties are then kept in the database
398               even when udevadm info --cleanup-db is called. This option can
399               be useful in certain cases (e.g. Device Mapper devices) for
400               persisting device state on the transition from initrd.
401
402           log_level=level
403               Takes a log level name like "debug" or "info", or a special
404               value "reset". When a log level name is specified, the maximum
405               log level is changed to that level. When "reset" is set, then
406               the previously specified log level is revoked. Defaults to the
407               log level of the main process of systemd-udevd.
408
409               This may be useful when debugging events for certain devices.
410               Note that the log level is applied when the line including this
411               rule is processed. So, for debugging, it is recommended that
412               this is specified at earlier place, e.g., the first line of
413               00-debug.rules.
414
415               Example for debugging uevent processing for network interfaces:
416
417                   # /etc/udev/rules.d/00-debug-net.rules
418                   SUBSYSTEM=="net", OPTIONS="log_level=debug"
419
420       The NAME, SYMLINK, PROGRAM, OWNER, GROUP, MODE, SECLABEL, and RUN
421       fields support simple string substitutions. The RUN substitutions are
422       performed after all rules have been processed, right before the program
423       is executed, allowing for the use of device properties set by earlier
424       matching rules. For all other fields, substitutions are performed while
425       the individual rule is being processed. The available substitutions
426       are:
427
428       $kernel, %k
429           The kernel name for this device.
430
431       $number, %n
432           The kernel number for this device. For example, "sda3" has kernel
433           number 3.
434
435       $devpath, %p
436           The devpath of the device.
437
438       $id, %b
439           The name of the device matched while searching the devpath upwards
440           for SUBSYSTEMS, KERNELS, DRIVERS, and ATTRS.
441
442       $driver
443           The driver name of the device matched while searching the devpath
444           upwards for SUBSYSTEMS, KERNELS, DRIVERS, and ATTRS.
445
446       $attr{file}, %s{file}
447           The value of a sysfs attribute found at the device where all keys
448           of the rule have matched. If the matching device does not have such
449           an attribute, and a previous KERNELS, SUBSYSTEMS, DRIVERS, or ATTRS
450           test selected a parent device, then the attribute from that parent
451           device is used.
452
453           If the attribute is a symlink, the last element of the symlink
454           target is returned as the value.
455
456       $env{key}, %E{key}
457           A device property value.
458
459       $major, %M
460           The kernel major number for the device.
461
462       $minor, %m
463           The kernel minor number for the device.
464
465       $result, %c
466           The string returned by the external program requested with PROGRAM.
467           A single part of the string, separated by a space character, may be
468           selected by specifying the part number as an attribute: "%c{N}". If
469           the number is followed by the "+" character, this part plus all
470           remaining parts of the result string are substituted: "%c{N+}".
471
472       $parent, %P
473           The node name of the parent device.
474
475       $name
476           The current name of the device. If not changed by a rule, it is the
477           name of the kernel device.
478
479       $links
480           A space-separated list of the current symlinks. The value is only
481           set during a remove event or if an earlier rule assigned a value.
482
483       $root, %r
484           The udev_root value.
485
486       $sys, %S
487           The sysfs mount point.
488
489       $devnode, %N
490           The name of the device node.
491
492       %%
493           The "%" character itself.
494
495       $$
496           The "$" character itself.
497

SEE ALSO

499       systemd-udevd.service(8), udevadm(8), systemd.link(5)
500

NOTES

502        1. C-style escaped
503           https://en.wikipedia.org/wiki/Escape_sequences_in_C#Table_of_escape_sequences
504
505
506
507systemd 253                                                            UDEV(7)
Impressum