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

SEE ALSO

444       systemd-udevd.service(8), udevadm(8), systemd.link(5)
445
446
447
448systemd 245                                                            UDEV(7)
Impressum