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       directory /usr/lib/udev/rules.d, the volatile runtime directory
31       /run/udev/rules.d and the local administration directory
32       /etc/udev/rules.d. All rules files are collectively sorted and
33       processed in lexical order, regardless of the directories in which they
34       live. However, files with identical filenames replace each other. Files
35       in /etc have the highest priority, files in /run take precedence over
36       files with the same name in /usr/lib. This can be used to override a
37       system-supplied rules file with a local file if needed; a symlink in
38       /etc with the same name as a rules file in /usr/lib, pointing to
39       /dev/null, disables the rules file entirely. Rule files must have the
40       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}, SYSCTL{kernel parameter}
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.  Match a kernel
111           parameter value.
112
113       KERNELS
114           Search the devpath upwards for a matching device name.
115
116       SUBSYSTEMS
117           Search the devpath upwards for a matching device subsystem name.
118
119       DRIVERS
120           Search the devpath upwards for a matching device driver name.
121
122       ATTRS{filename}
123           Search the devpath upwards for a device with matching sysfs
124           attribute values. If multiple ATTRS matches are specified, all of
125           them must match on the same device. Trailing whitespace in the
126           attribute values is ignored unless the specified match value itself
127           contains trailing whitespace.
128
129       TAGS
130           Search the devpath upwards for a device with matching tag.
131
132       ENV{key}
133           Match against a device property value.
134
135       TAG
136           Match against a device tag.
137
138       TEST{octal mode mask}
139           Test the existence of a file. An octal mode mask can be specified
140           if needed.
141
142       PROGRAM
143           Execute a program to determine whether there is a match; the key is
144           true if the program returns successfully. The device properties are
145           made available to the executed program in the environment. The
146           program's standard output is available in the RESULT key.
147
148           This can only be used for very short-running foreground tasks. For
149           details, see RUN.
150
151       RESULT
152           Match the returned string of the last PROGRAM call. This key can be
153           used in the same or in any later rule after a PROGRAM call.
154
155       Most of the fields support shell glob pattern matching and alternate
156       patterns. The following special characters are supported:
157
158       "*"
159           Matches zero or more characters.
160
161       "?"
162           Matches any single character.
163
164       "[]"
165           Matches any single character specified within the brackets. For
166           example, the pattern string "tty[SR]" would match either "ttyS" or
167           "ttyR". Ranges are also supported via the "-" character. For
168           example, to match on the range of all digits, the pattern "[0-9]"
169           could be used. If the first character following the "[" is a "!",
170           any characters not enclosed are matched.
171
172       "|"
173           Separates alternative patterns. For example, the pattern string
174           "abc|x*" would match either "abc" or "x*".
175
176       The following keys can get values assigned:
177
178       NAME
179           The name to use for a network interface. See systemd.link(5) for a
180           higher-level mechanism for setting the interface name. The name of
181           a device node cannot be changed by udev, only additional symlinks
182           can be created.
183
184       SYMLINK
185           The name of a symlink targeting the node. Every matching rule adds
186           this value to the list of symlinks to be created.
187
188           The set of characters to name a symlink is limited. Allowed
189           characters are "0-9A-Za-z#+-.:=@_/", valid UTF-8 character
190           sequences, and "\x00" hex encoding. All other characters are
191           replaced by a "_" character.
192
193           Multiple symlinks may be specified by separating the names by the
194           space character. In case multiple devices claim the same name, the
195           link always points to the device with the highest link_priority. If
196           the current device goes away, the links are re-evaluated and the
197           device with the next highest link_priority becomes the owner of the
198           link. If no link_priority is specified, the order of the devices
199           (and which one of them owns the link) is undefined.
200
201           Symlink names must never conflict with the kernel's default device
202           node names, as that would result in unpredictable behavior.
203
204       OWNER, GROUP, MODE
205           The permissions for the device node. Every specified value
206           overrides the compiled-in default value.
207
208       SECLABEL{module}
209           Applies the specified Linux Security Module label to the device
210           node.
211
212       ATTR{key}
213           The value that should be written to a sysfs attribute of the event
214           device.
215
216       SYSCTL{kernel parameter}
217           The value that should be written to kernel parameter.
218
219       ENV{key}
220           Set a device property value. Property names with a leading "."  are
221           neither stored in the database nor exported to events or external
222           tools (run by, for example, the PROGRAM match key).
223
224       TAG
225           Attach a tag to a device. This is used to filter events for users
226           of libudev's monitor functionality, or to enumerate a group of
227           tagged devices. The implementation can only work efficiently if
228           only a few tags are attached to a device. It is only meant to be
229           used in contexts with specific device filter requirements, and not
230           as a general-purpose flag. Excessive use might result in
231           inefficient event handling.
232
233       RUN{type}
234           Add a program to the list of programs to be executed after
235           processing all the rules for a specific event, depending on "type":
236
237           "program"
238               Execute an external program specified as the assigned value. If
239               no absolute path is given, the program is expected to live in
240               /usr/lib/udev; otherwise, the absolute path must be specified.
241
242               This is the default if no type is specified.
243
244           "builtin"
245               As program, but use one of the built-in programs rather than an
246               external one.
247
248           The program name and following arguments are separated by spaces.
249           Single quotes can be used to specify arguments with spaces.
250
251           This can only be used for very short-running foreground tasks.
252           Running an event process for a long period of time may block all
253           further events for this or a dependent device.
254
255           Starting daemons or other long-running processes is not appropriate
256           for udev; the forked processes, detached or not, will be
257           unconditionally killed after the event handling has finished.
258
259           Note that running programs that access the network or mount/unmount
260           filesystems is not allowed inside of udev rules, due to the default
261           sandbox that is enforced on systemd-udevd.service.
262
263       LABEL
264           A named label to which a GOTO may jump.
265
266       GOTO
267           Jumps to the next LABEL with a matching name.
268
269       IMPORT{type}
270           Import a set of variables as device properties, depending on
271           "type":
272
273           "program"
274               Execute an external program specified as the assigned value
275               and, if it returns successfully, import its output, which must
276               be in environment key format. Path specification,
277               command/argument separation, and quoting work like in RUN.
278
279           "builtin"
280               Similar to "program", but use one of the built-in programs
281               rather than an external one.
282
283           "file"
284               Import a text file specified as the assigned value, the content
285               of which must be in environment key format.
286
287           "db"
288               Import a single property specified as the assigned value from
289               the current device database. This works only if the database is
290               already populated by an earlier event.
291
292           "cmdline"
293               Import a single property from the kernel command line. For
294               simple flags the value of the property is set to "1".
295
296           "parent"
297               Import the stored keys from the parent device by reading the
298               database entry of the parent device. The value assigned to
299               IMPORT{parent} is used as a filter of key names to import (with
300               the same shell glob pattern matching used for comparisons).
301
302           This can only be used for very short-running foreground tasks. For
303           details see RUN.
304
305       WAIT_FOR
306           Wait for a file to become available or until a timeout of 10
307           seconds expires. The path is relative to the sysfs device; if no
308           path is specified, this waits for an attribute to appear.
309
310       OPTIONS
311           Rule and device options:
312
313           link_priority=value
314               Specify the priority of the created symlinks. Devices with
315               higher priorities overwrite existing symlinks of other devices.
316               The default is 0.
317
318           string_escape=none|replace
319               Usually, control and other possibly unsafe characters are
320               replaced in strings used for device naming. The mode of
321               replacement can be specified with this option.
322
323           static_node=
324               Apply the permissions specified in this rule to the static
325               device node with the specified name. Also, for every tag
326               specified in this rule, create a symlink in the directory
327               /run/udev/static_node-tags/tag pointing at the static device
328               node with the specified name. Static device node creation is
329               performed by systemd-tmpfiles before systemd-udevd is started.
330               The static nodes might not have a corresponding kernel device;
331               they are used to trigger automatic kernel module loading when
332               they are accessed.
333
334           watch
335               Watch the device node with inotify; when the node is closed
336               after being opened for writing, a change uevent is synthesized.
337
338           nowatch
339               Disable the watching of a device node with inotify.
340
341       The NAME, SYMLINK, PROGRAM, OWNER, GROUP, MODE, SECLABEL, and RUN
342       fields support simple string substitutions. The RUN substitutions are
343       performed after all rules have been processed, right before the program
344       is executed, allowing for the use of device properties set by earlier
345       matching rules. For all other fields, substitutions are performed while
346       the individual rule is being processed. The available substitutions
347       are:
348
349       $kernel, %k
350           The kernel name for this device.
351
352       $number, %n
353           The kernel number for this device. For example, "sda3" has kernel
354           number "3".
355
356       $devpath, %p
357           The devpath of the device.
358
359       $id, %b
360           The name of the device matched while searching the devpath upwards
361           for SUBSYSTEMS, KERNELS, DRIVERS, and ATTRS.
362
363       $driver
364           The driver name of the device matched while searching the devpath
365           upwards for SUBSYSTEMS, KERNELS, DRIVERS, and ATTRS.
366
367       $attr{file}, %s{file}
368           The value of a sysfs attribute found at the device where all keys
369           of the rule have matched. If the matching device does not have such
370           an attribute, and a previous KERNELS, SUBSYSTEMS, DRIVERS, or ATTRS
371           test selected a parent device, then the attribute from that parent
372           device is used.
373
374           If the attribute is a symlink, the last element of the symlink
375           target is returned as the value.
376
377       $env{key}, %E{key}
378           A device property value.
379
380       $major, %M
381           The kernel major number for the device.
382
383       $minor, %m
384           The kernel minor number for the device.
385
386       $result, %c
387           The string returned by the external program requested with PROGRAM.
388           A single part of the string, separated by a space character, may be
389           selected by specifying the part number as an attribute: "%c{N}". If
390           the number is followed by the "+" character, this part plus all
391           remaining parts of the result string are substituted: "%c{N+}".
392
393       $parent, %P
394           The node name of the parent device.
395
396       $name
397           The current name of the device. If not changed by a rule, it is the
398           name of the kernel device.
399
400       $links
401           A space-separated list of the current symlinks. The value is only
402           set during a remove event or if an earlier rule assigned a value.
403
404       $root, %r
405           The udev_root value.
406
407       $sys, %S
408           The sysfs mount point.
409
410       $devnode, %N
411           The name of the device node.
412
413       %%
414           The "%" character itself.
415
416       $$
417           The "$" character itself.
418

SEE ALSO

420       systemd-udevd.service(8), udevadm(8), systemd.link(5)
421
422
423
424systemd 239                                                            UDEV(7)
Impressum