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