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

SEE ALSO

453       systemd-udevd.service(8), udevadm(8), systemd.link(5)
454
455
456
457systemd 246                                                            UDEV(7)
Impressum