]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/udev.xml
man/systemd-sysext: list ephemeral/ephemeral-import in the list of options
[thirdparty/systemd.git] / man / udev.xml
CommitLineData
514094f9 1<?xml version='1.0'?>
3a54a157 2<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
eea10b26 3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
7b86ada7 4
f48f7543 5<!--
db9ecf05 6 SPDX-License-Identifier: LGPL-2.1-or-later
96b2fb93 7 Copyright © 2014 Jason St. John
f48f7543
ZJS
8-->
9
4623eecb 10<refentry id="udev" xmlns:xi="http://www.w3.org/2001/XInclude">
63749b1a 11 <refentryinfo>
7b86ada7 12 <title>udev</title>
d3a2386d 13 <productname>systemd</productname>
63749b1a
KS
14 </refentryinfo>
15
16 <refmeta>
17 <refentrytitle>udev</refentrytitle>
18 <manvolnum>7</manvolnum>
19 </refmeta>
20
21 <refnamediv>
22 <refname>udev</refname>
eb75d0ed 23 <refpurpose>Dynamic device management</refpurpose>
63749b1a
KS
24 </refnamediv>
25
bc117ec3
YLY
26 <refsect1>
27 <title>Description</title>
63749b1a 28 <para>udev supplies the system software with device events, manages permissions
3b121157 29 of device nodes and may create additional symlinks in the <filename>/dev/</filename>
63749b1a
KS
30 directory, or renames network interfaces. The kernel usually just assigns unpredictable
31 device names based on the order of discovery. Meaningful symlinks or network device
32 names provide a way to reliably identify devices based on their properties or
33 current configuration.</para>
34
b79f817b 35 <para>The udev daemon, <citerefentry><refentrytitle>systemd-udevd.service</refentrytitle>
0e4fa2ab 36 <manvolnum>8</manvolnum></citerefentry>, receives device uevents directly from
63749b1a
KS
37 the kernel whenever a device is added or removed from the system, or it changes its
38 state. When udev receives a device event, it matches its configured set of rules
0e846301
MW
39 against various device attributes to identify the device. Rules that match may
40 provide additional device information to be stored in the udev database or
63749b1a
KS
41 to be used to create meaningful symlink names.</para>
42
0e846301 43 <para>All device information udev processes is stored in the udev database and
63749b1a 44 sent out to possible event subscribers. Access to all stored data and the event
17fd0f60 45 sources is provided by the library libudev.</para>
63749b1a
KS
46 </refsect1>
47
bc117ec3
YLY
48 <refsect1>
49 <title>Rules Files</title>
116b91e8
ZJS
50 <para>The udev rules are read from the files located in the system rules directories
51 <filename>/usr/lib/udev/rules.d</filename> and <filename>/usr/local/lib/udev/rules.d</filename>, the
52 volatile runtime directory <filename>/run/udev/rules.d</filename> and the local administration
53 directory <filename>/etc/udev/rules.d</filename>. All rules files are collectively sorted and
54 processed in lexical order, regardless of the directories in which they live. However, files with
3b121157
ZJS
55 identical filenames replace each other. Files in <filename>/etc/</filename> have the highest priority,
56 files in <filename>/run/</filename> take precedence over files with the same name under
57 <filename>/usr/</filename>. This can be used to override a system-supplied rules file with a local
58 file if needed; a symlink in <filename>/etc/</filename> with the same name as a rules file in
59 <filename>/usr/lib/</filename>, pointing to <filename>/dev/null</filename>, disables the rules file
116b91e8
ZJS
60 entirely. Rule files must have the extension <filename>.rules</filename>; other extensions are
61 ignored.</para>
63749b1a 62
feedf8f3 63 <para>Every line in the rules file contains at least one key-value pair.
909f413d 64 Except for empty lines or lines beginning with <literal>#</literal>, which are ignored.
bb31a4ac 65 There are two kinds of keys: match and assignment.
6ec0ac43
TG
66 If all match keys match against their values, the rule gets applied and the
67 assignment keys get the specified values assigned.</para>
63749b1a
KS
68
69 <para>A matching rule may rename a network interface, add symlinks
70 pointing to the device node, or run a specified program as part of
71 the event handling.</para>
72
bc117ec3
YLY
73 <para>A rule consists of a comma-separated list of one or more key-operator-value expressions.
74 Each expression has a distinct effect, depending on the key and operator used.</para>
75
76 <refsect2>
77 <title>Operators</title>
78 <variablelist>
79 <varlistentry>
80 <term><literal>==</literal></term>
81 <listitem>
5929b6b5 82 <para>Compare for equality. (The specified key has the specified value.)</para>
bc117ec3
YLY
83 </listitem>
84 </varlistentry>
85
86 <varlistentry>
87 <term><literal>!=</literal></term>
88 <listitem>
44855c77 89 <para>Compare for inequality. (The specified key does not have the specified value, or the
5929b6b5
ZJS
90 specified key is not present at all.)
91 </para>
bc117ec3
YLY
92 </listitem>
93 </varlistentry>
94
95 <varlistentry>
96 <term><literal>=</literal></term>
97 <listitem>
98 <para>Assign a value to a key. Keys that represent a list are reset
99 and only this single value is assigned.</para>
100 </listitem>
101 </varlistentry>
102
103 <varlistentry>
104 <term><literal>+=</literal></term>
105 <listitem>
106 <para>Add the value to a key that holds a list of entries.</para>
107 </listitem>
108 </varlistentry>
109
110 <varlistentry>
111 <term><literal>-=</literal></term>
112 <listitem>
113 <para>Remove the value from a key that holds a list of entries.</para>
aefdc112
AK
114
115 <xi:include href="version-info.xml" xpointer="v217"/>
bc117ec3
YLY
116 </listitem>
117 </varlistentry>
118
119 <varlistentry>
120 <term><literal>:=</literal></term>
121 <listitem>
91c27ac6 122 <para>Assign a value to a key finally; disallow any later changes.</para>
ec07c3c8
AK
123
124 <xi:include href="version-info.xml" xpointer="v247"/>
bc117ec3
YLY
125 </listitem>
126 </varlistentry>
127 </variablelist>
128 </refsect2>
129
130 <refsect2>
131 <title>Values</title>
132 <para>Values are written as double quoted strings, such as ("string").
133 To include a quotation mark (") in the value, precede it by a backslash (\").
4fc8a70d 134 Any other occurrences of a backslash followed by a character are not unescaped.
bc117ec3
YLY
135 That is, "\t\n" is treated as four characters:
136 backslash, lowercase t, backslash, lowercase n.</para>
137
138 <para>The string can be prefixed with a lowercase e (e"string\n") to mark the string as
c8cd6d7b
ZJS
139 C-style escaped, see
140 <ulink url="https://en.wikipedia.org/wiki/Escape_sequences_in_C#Table_of_escape_sequences">Escape sequences in C</ulink>.
bc117ec3 141 For example, e"string\n" is parsed as 7 characters: 6 lowercase letters and a newline.
5c09eac7 142 This can be useful for writing special characters when a kernel driver requires them.</para>
bc117ec3 143
5f5c5c48
YW
144 <para>The string can be prefixed with a lowercase i (i"string") to mark that the string or pattern
145 will match case-insensitively. For example, i"foo" will match
146 <literal>foo</literal>, <literal>FOO</literal>, <literal>FoO</literal> and so on. The prefix can be
147 used only for match (<literal>==</literal>) or unmatch (<literal>!=</literal>) rules, e.g.
148 <varname>ATTR{foo}==i"abcd"</varname>.</para>
149
bc117ec3
YLY
150 <para>Please note that <constant>NUL</constant> is not allowed in either string variant.</para>
151 </refsect2>
152
153 <refsect2>
154 <title>Keys</title>
155 <para>The following key names can be used to match against device properties.
156 Some of the keys also match against properties of the parent devices in sysfs,
157 not only the device that has generated the event. If multiple keys that match
158 a parent device are specified in a single rule, all these keys must match at
159 one and the same parent device.</para>
160 <variablelist class='udev-directives'>
161 <varlistentry>
162 <term><varname>ACTION</varname></term>
163 <listitem>
164 <para>Match the name of the event action.</para>
165 </listitem>
166 </varlistentry>
167
168 <varlistentry>
169 <term><varname>DEVPATH</varname></term>
170 <listitem>
171 <para>Match the devpath of the event device.</para>
172 </listitem>
173 </varlistentry>
174
175 <varlistentry>
176 <term><varname>KERNEL</varname></term>
177 <listitem>
178 <para>Match the name of the event device.</para>
179 </listitem>
180 </varlistentry>
181
9479d92e
ZJS
182 <varlistentry>
183 <term><varname>KERNELS</varname></term>
184 <listitem>
185 <para>Search the devpath upwards for a matching device name.</para>
186 </listitem>
187 </varlistentry>
188
bc117ec3
YLY
189 <varlistentry>
190 <term><varname>NAME</varname></term>
191 <listitem>
192 <para>Match the name of a network interface. It can be used once the
193 NAME key has been set in one of the preceding rules.</para>
194 </listitem>
195 </varlistentry>
196
197 <varlistentry>
198 <term><varname>SYMLINK</varname></term>
199 <listitem>
2b43ab00
YW
200 <para>Match the name of a symlink targeting the node. It can be used once a SYMLINK key has
201 been set in one of the preceding rules. There may be multiple symlinks; only one needs to
202 match. If the operator is <literal>!=</literal>, the token returns true only if there is no
203 symlink matched.</para>
bc117ec3
YLY
204 </listitem>
205 </varlistentry>
206
207 <varlistentry>
208 <term><varname>SUBSYSTEM</varname></term>
209 <listitem>
210 <para>Match the subsystem of the event device.</para>
211 </listitem>
212 </varlistentry>
9479d92e 213
bc117ec3 214 <varlistentry>
9479d92e 215 <term><varname>SUBSYSTEMS</varname></term>
bc117ec3 216 <listitem>
9479d92e 217 <para>Search the devpath upwards for a matching device subsystem name.</para>
bc117ec3
YLY
218 </listitem>
219 </varlistentry>
220
221 <varlistentry>
9479d92e 222 <term><varname>DRIVER</varname></term>
bc117ec3 223 <listitem>
9479d92e
ZJS
224 <para>Match the driver name of the event device. Only set this key for devices
225 which are bound to a driver at the time the event is generated.</para>
bc117ec3
YLY
226 </listitem>
227 </varlistentry>
228
229 <varlistentry>
9479d92e 230 <term><varname>DRIVERS</varname></term>
bc117ec3 231 <listitem>
9479d92e 232 <para>Search the devpath upwards for a matching device driver name.</para>
bc117ec3
YLY
233 </listitem>
234 </varlistentry>
235
236 <varlistentry>
9479d92e 237 <term><varname>ATTR{<replaceable>filename</replaceable>}</varname></term>
bc117ec3 238 <listitem>
9479d92e
ZJS
239 <para>Match sysfs attribute value of the event device.</para>
240
241 <para>Trailing whitespace in the attribute values is ignored unless the specified match value
242 itself contains trailing whitespace.</para>
bc117ec3
YLY
243 </listitem>
244 </varlistentry>
245
246 <varlistentry>
247 <term><varname>ATTRS{<replaceable>filename</replaceable>}</varname></term>
248 <listitem>
9479d92e
ZJS
249 <para>Search the devpath upwards for a device with matching sysfs attribute values. If
250 multiple <varname>ATTRS</varname> matches are specified, all of them must match on the same
251 device.</para>
252
253 <para>Trailing whitespace in the attribute values is ignored unless the specified match value
254 itself contains trailing whitespace.</para>
bc117ec3
YLY
255 </listitem>
256 </varlistentry>
257
258 <varlistentry>
9479d92e 259 <term><varname>SYSCTL{<replaceable>kernel parameter</replaceable>}</varname></term>
bc117ec3 260 <listitem>
9479d92e 261 <para>Match a kernel parameter value.</para>
aefdc112
AK
262
263 <xi:include href="version-info.xml" xpointer="v240"/>
bc117ec3
YLY
264 </listitem>
265 </varlistentry>
266
267 <varlistentry>
268 <term><varname>ENV{<replaceable>key</replaceable>}</varname></term>
269 <listitem>
270 <para>Match against a device property value.</para>
271 </listitem>
272 </varlistentry>
273
274 <varlistentry>
275 <term><varname>CONST{<replaceable>key</replaceable>}</varname></term>
276 <listitem>
277 <para>Match against a system-wide constant. Supported keys are:</para>
278 <variablelist>
279 <varlistentry>
280 <term><literal>arch</literal></term>
281 <listitem>
282 <para>System's architecture. See <option>ConditionArchitecture=</option> in
283 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>
284 for possible values.</para>
aefdc112
AK
285
286 <xi:include href="version-info.xml" xpointer="v244"/>
bc117ec3
YLY
287 </listitem>
288 </varlistentry>
289 <varlistentry>
290 <term><literal>virt</literal></term>
291 <listitem>
292 <para>System's virtualization environment. See
293 <citerefentry><refentrytitle>systemd-detect-virt</refentrytitle><manvolnum>1</manvolnum></citerefentry>
294 for possible values.</para>
aefdc112
AK
295
296 <xi:include href="version-info.xml" xpointer="v244"/>
bc117ec3
YLY
297 </listitem>
298 </varlistentry>
6e2e83b4
DB
299 <varlistentry>
300 <term><literal>cvm</literal></term>
301 <listitem>
302 <para>System's confidential virtualization technology. See
303 <citerefentry><refentrytitle>systemd-detect-virt</refentrytitle><manvolnum>1</manvolnum></citerefentry>
304 for possible values.</para>
ec07c3c8
AK
305
306 <xi:include href="version-info.xml" xpointer="v254"/>
6e2e83b4
DB
307 </listitem>
308 </varlistentry>
bc117ec3
YLY
309 </variablelist>
310 <para>Unknown keys will never match.</para>
aefdc112
AK
311
312 <xi:include href="version-info.xml" xpointer="v244"/>
bc117ec3
YLY
313 </listitem>
314 </varlistentry>
315
316 <varlistentry>
317 <term><varname>TAG</varname></term>
318 <listitem>
2b43ab00
YW
319 <para>Match against one of device tags. It can be used once a TAG key has been set in one of
320 the preceding rules. There may be multiple tags; only one needs to match. If the operator is
321 <literal>!=</literal>, the token returns true only if there is no tag matched.</para>
bc117ec3
YLY
322 </listitem>
323 </varlistentry>
324
9479d92e
ZJS
325 <varlistentry>
326 <term><varname>TAGS</varname></term>
327 <listitem>
2b43ab00
YW
328 <para>Search the devpath upwards for a device with matching tag. If the operator is
329 <literal>!=</literal>, the token returns true only if there is no tag matched.</para>
9479d92e
ZJS
330 </listitem>
331 </varlistentry>
332
bc117ec3
YLY
333 <varlistentry>
334 <term><varname>TEST{<replaceable>octal mode mask</replaceable>}</varname></term>
335 <listitem>
336 <para>Test the existence of a file. An octal mode mask can be specified
337 if needed.</para>
338 </listitem>
339 </varlistentry>
340
341 <varlistentry>
342 <term><varname>PROGRAM</varname></term>
343 <listitem>
344 <para>Execute a program to determine whether there is a match; the key is true if the program
345 returns successfully. The device properties are made available to the executed program in the
346 environment. The program's standard output is available in the <varname>RESULT</varname>
347 key.</para>
348
349 <para>This can only be used for very short-running foreground tasks. For details, see
350 <varname>RUN</varname>.</para>
351
352 <para>Note that multiple <varname>PROGRAM</varname> keys may be specified in one rule, and
353 <literal>=</literal>, <literal>:=</literal>, and <literal>+=</literal> have the same effect as
354 <literal>==</literal>.</para>
355 </listitem>
356 </varlistentry>
357
358 <varlistentry>
359 <term><varname>RESULT</varname></term>
360 <listitem>
361 <para>Match the returned string of the last <varname>PROGRAM</varname> call.
362 This key can be used in the same or in any later rule after a
363 <varname>PROGRAM</varname> call.</para>
364 </listitem>
365 </varlistentry>
366 </variablelist>
367
368 <para>Most of the fields support shell glob pattern matching and
369 alternate patterns. The following special characters are supported:</para>
370 <variablelist>
371 <varlistentry>
372 <term><literal>*</literal></term>
373 <listitem>
374 <para>Matches zero or more characters.</para>
375 </listitem>
376 </varlistentry>
377 <varlistentry>
378 <term><literal>?</literal></term>
379 <listitem>
380 <para>Matches any single character.</para>
381 </listitem>
382 </varlistentry>
383 <varlistentry>
384 <term><literal>[]</literal></term>
385 <listitem>
386 <para>Matches any single character specified within the brackets. For
387 example, the pattern string <literal>tty[SR]</literal>
388 would match either <literal>ttyS</literal> or <literal>ttyR</literal>.
389 Ranges are also supported via the <literal>-</literal> character.
390 For example, to match on the range of all digits, the pattern
391 <literal>[0-9]</literal> could be used. If the first character
392 following the <literal>[</literal> is a <literal>!</literal>,
393 any characters not enclosed are matched.</para>
394 </listitem>
395 </varlistentry>
396 <varlistentry>
397 <term><literal>|</literal></term>
398 <listitem>
399 <para>Separates alternative patterns. For example, the pattern string
400 <literal>abc|x*</literal> would match either <literal>abc</literal>
401 or <literal>x*</literal>.</para>
aefdc112
AK
402
403 <xi:include href="version-info.xml" xpointer="v217"/>
bc117ec3
YLY
404 </listitem>
405 </varlistentry>
406 </variablelist>
407
408 <para>The following keys can get values assigned:</para>
409 <variablelist class='udev-directives'>
410 <varlistentry>
411 <term><varname>NAME</varname></term>
412 <listitem>
413 <para>The name to use for a network interface. See
414 <citerefentry><refentrytitle>systemd.link</refentrytitle><manvolnum>5</manvolnum></citerefentry>
415 for a higher-level mechanism for setting the interface name.
416 The name of a device node cannot be changed by udev, only additional
417 symlinks can be created.</para>
418 </listitem>
419 </varlistentry>
420
421 <varlistentry>
422 <term><varname>SYMLINK</varname></term>
423 <listitem>
424 <para>The name of a symlink targeting the node. Every matching rule adds
425 this value to the list of symlinks to be created.</para>
426 <para>The set of characters to name a symlink is limited. Allowed
427 characters are <literal>0-9A-Za-z#+-.:=@_/</literal>, valid UTF-8 character
428 sequences, and <literal>\x00</literal> hex encoding. All other
429 characters are replaced by a <literal>_</literal> character.</para>
430 <para>Multiple symlinks may be specified by separating the names by the
431 space character. In case multiple devices claim the same name, the link
432 always points to the device with the highest link_priority. If the current
433 device goes away, the links are re-evaluated and the device with the
434 next highest link_priority becomes the owner of the link. If no
435 link_priority is specified, the order of the devices (and which one of
436 them owns the link) is undefined.</para>
437 <para>Symlink names must never conflict with the kernel's default device
438 node names, as that would result in unpredictable behavior.
439 </para>
440 </listitem>
441 </varlistentry>
442
443 <varlistentry>
444 <term><varname>OWNER</varname>, <varname>GROUP</varname>, <varname>MODE</varname></term>
445 <listitem>
446 <para>The permissions for the device node. Every specified value overrides
447 the compiled-in default value.</para>
448 </listitem>
449 </varlistentry>
450
451 <varlistentry>
452 <term><varname>SECLABEL{<replaceable>module</replaceable>}</varname></term>
453 <listitem>
454 <para>Applies the specified Linux Security Module label to the device node.</para>
aefdc112
AK
455
456 <xi:include href="version-info.xml" xpointer="v209"/>
bc117ec3
YLY
457 </listitem>
458 </varlistentry>
459
460 <varlistentry>
461 <term><varname>ATTR{<replaceable>key</replaceable>}</varname></term>
462 <listitem>
463 <para>The value that should be written to a sysfs attribute of the
464 event device.</para>
465 </listitem>
466 </varlistentry>
467
468 <varlistentry>
469 <term><varname>SYSCTL{<replaceable>kernel parameter</replaceable>}</varname></term>
470 <listitem>
471 <para>The value that should be written to kernel parameter.</para>
aefdc112
AK
472
473 <xi:include href="version-info.xml" xpointer="v220"/>
bc117ec3
YLY
474 </listitem>
475 </varlistentry>
476
477 <varlistentry>
478 <term><varname>ENV{<replaceable>key</replaceable>}</varname></term>
479 <listitem>
480 <para>Set a device property value. Property names with a leading <literal>.</literal>
481 are neither stored in the database nor exported to events or
482 external tools (run by, for example, the <varname>PROGRAM</varname>
483 match key).</para>
484 </listitem>
485 </varlistentry>
486
487 <varlistentry>
488 <term><varname>TAG</varname></term>
489 <listitem>
490 <para>Attach a tag to a device. This is used to filter events for users
491 of libudev's monitor functionality, or to enumerate a group of tagged
492 devices. The implementation can only work efficiently if only a few
493 tags are attached to a device. It is only meant to be used in
494 contexts with specific device filter requirements, and not as a
495 general-purpose flag. Excessive use might result in inefficient event
496 handling.</para>
497 </listitem>
498 </varlistentry>
499
500 <varlistentry>
501 <term><varname>RUN{<replaceable>type</replaceable>}</varname></term>
502 <listitem>
503 <para>Specify a program to be executed after processing of all the rules for the event. With
504 <literal>+=</literal>, this invocation is added to the list, and with <literal>=</literal> or
505 <literal>:=</literal>, it replaces any previous contents of the list. Please note that both
4fc8a70d 506 <literal>program</literal> and <literal>builtin</literal> types described below share a common
bc117ec3
YLY
507 list, so clearing the list with <literal>:=</literal> and <literal>=</literal> affects both
508 types.</para>
509
510 <para><replaceable>type</replaceable> may be:</para>
511 <variablelist>
512 <varlistentry>
513 <term><literal>program</literal></term>
514 <listitem>
515 <para>Execute an external program specified as the assigned
516 value. If no absolute path is given, the program is expected
517 to live in <filename>/usr/lib/udev</filename>; otherwise, the
518 absolute path must be specified.</para>
519 <para>This is the default if no <replaceable>type</replaceable>
520 is specified.</para>
521 </listitem>
522 </varlistentry>
523 <varlistentry>
524 <term><literal>builtin</literal></term>
525 <listitem>
526 <para>As <varname>program</varname>, but use one of the
527 built-in programs rather than an external one.</para>
aefdc112
AK
528
529 <xi:include href="version-info.xml" xpointer="v199"/>
bc117ec3
YLY
530 </listitem>
531 </varlistentry>
532 </variablelist>
533
534 <para>The program name and following arguments are separated by spaces. Single quotes can be
535 used to specify arguments with spaces.</para>
536
537 <para>This can only be used for very short-running foreground tasks. Running an event process for
538 a long period of time may block all further events for this or a dependent device.</para>
539
540 <para>Note that running programs that access the network or mount/unmount filesystems is not
541 allowed inside of udev rules, due to the default sandbox that is enforced on
542 <filename>systemd-udevd.service</filename>.</para>
543
544 <para>Starting daemons or other long-running processes is not allowed; the forked processes,
545 detached or not, will be unconditionally killed after the event handling has finished. In order
546 to activate long-running processes from udev rules, provide a service unit and pull it in from a
547 udev device using the <varname>SYSTEMD_WANTS</varname> device property. See
548 <citerefentry><refentrytitle>systemd.device</refentrytitle><manvolnum>5</manvolnum></citerefentry>
549 for details.</para>
550 </listitem>
551 </varlistentry>
552
553 <varlistentry>
554 <term><varname>LABEL</varname></term>
555 <listitem>
556 <para>A named label to which a <varname>GOTO</varname> may jump.</para>
557 </listitem>
558 </varlistentry>
559
560 <varlistentry>
561 <term><varname>GOTO</varname></term>
562 <listitem>
563 <para>Jumps to the next <varname>LABEL</varname> with a matching name.</para>
564 </listitem>
565 </varlistentry>
566
567 <varlistentry>
568 <term><varname>IMPORT{<replaceable>type</replaceable>}</varname></term>
569 <listitem>
570 <para>Import a set of variables as device properties, depending on
571 <replaceable>type</replaceable>:</para>
572
573 <variablelist>
574 <varlistentry>
575 <term><literal>program</literal></term>
576 <listitem>
577 <para>Execute an external program specified as the assigned
578 value and, if it returns successfully,
579 import its output, which must be in environment key
580 format. Path specification, command/argument separation,
581 and quoting work like in <varname>RUN</varname>.</para>
aefdc112
AK
582
583 <xi:include href="version-info.xml" xpointer="v199"/>
bc117ec3
YLY
584 </listitem>
585 </varlistentry>
586 <varlistentry>
587 <term><literal>builtin</literal></term>
588 <listitem>
589 <para>Similar to <literal>program</literal>, but use one of the
590 built-in programs rather than an external one.</para>
aefdc112
AK
591
592 <xi:include href="version-info.xml" xpointer="v199"/>
bc117ec3
YLY
593 </listitem>
594 </varlistentry>
07d16cc0 595 <varlistentry>
bc117ec3
YLY
596 <term><literal>file</literal></term>
597 <listitem>
598 <para>Import a text file specified as the assigned value, the content
599 of which must be in environment key format.</para>
600 </listitem>
601 </varlistentry>
602 <varlistentry>
603 <term><literal>db</literal></term>
604 <listitem>
605 <para>Import a single property specified as the assigned value from the
606 current device database. This works only if the database is already populated
607 by an earlier event.</para>
608 </listitem>
609 </varlistentry>
610 <varlistentry>
611 <term><literal>cmdline</literal></term>
612 <listitem>
613 <para>Import a single property from the kernel command line. For simple flags
614 the value of the property is set to <literal>1</literal>.</para>
615 </listitem>
616 </varlistentry>
617 <varlistentry>
618 <term><literal>parent</literal></term>
619 <listitem>
620 <para>Import the stored keys from the parent device by reading
621 the database entry of the parent device. The value assigned to
622 <option>IMPORT{parent}</option> is used as a filter of key names
623 to import (with the same shell glob pattern matching used for
624 comparisons).</para>
625 </listitem>
626 </varlistentry>
627 </variablelist>
628
629 <para>This can only be used for very short-running foreground tasks. For details see
630 <option>RUN</option>.</para>
631
632 <para>Note that multiple <varname>IMPORT{}</varname> keys may be specified in one rule, and
633 <literal>=</literal>, <literal>:=</literal>, and <literal>+=</literal> have the same effect as
634 <literal>==</literal>. The key is true if the import is successful, unless <literal>!=</literal>
635 is used as the operator which causes the key to be true if the import failed.</para>
636 </listitem>
637 </varlistentry>
638
639 <varlistentry>
640 <term><varname>OPTIONS</varname></term>
641 <listitem>
642 <para>Rule and device options:</para>
643 <variablelist class='udev-directives'>
644 <varlistentry>
645 <term><option>link_priority=<replaceable>value</replaceable></option></term>
646 <listitem>
647 <para>Specify the priority of the created symlinks. Devices with higher
648 priorities overwrite existing symlinks of other devices. The default is 0.</para>
649 </listitem>
650 </varlistentry>
651 <varlistentry>
652 <term><option>string_escape=<replaceable>none|replace</replaceable></option></term>
653 <listitem>
91c27ac6
YW
654 <para>When <literal>replace</literal>, possibly unsafe characters in strings
655 assigned to <varname>NAME</varname>, <varname>SYMLINK</varname>, and
656 <varname>ENV{<replaceable>key</replaceable>}</varname> are replaced. When
657 <literal>none</literal>, no replacement is performed. When unset, the replacement
658 is performed for <varname>NAME</varname>, <varname>SYMLINK</varname>, but not for
659 <varname>ENV{<replaceable>key</replaceable>}</varname>. Defaults to unset.</para>
bc117ec3
YLY
660 </listitem>
661 </varlistentry>
662 <varlistentry>
663 <term><option>static_node=</option></term>
664 <listitem>
665 <para>Apply the permissions specified in this rule to the
666 static device node with the specified name. Also, for every
667 tag specified in this rule, create a symlink
668 in the directory
669 <filename>/run/udev/static_node-tags/<replaceable>tag</replaceable></filename>
670 pointing at the static device node with the specified name.
671 Static device node creation is performed by systemd-tmpfiles
672 before systemd-udevd is started. The static nodes might not
673 have a corresponding kernel device; they are used to trigger
674 automatic kernel module loading when they are accessed.</para>
675 </listitem>
676 </varlistentry>
677 <varlistentry>
678 <term><option>watch</option></term>
679 <listitem>
680 <para>Watch the device node with inotify; when the node is
681 closed after being opened for writing, a change uevent is
682 synthesized.</para>
683 </listitem>
684 </varlistentry>
685 <varlistentry>
686 <term><option>nowatch</option></term>
687 <listitem>
688 <para>Disable the watching of a device node with inotify.</para>
689 </listitem>
690 </varlistentry>
691 <varlistentry>
692 <term><option>db_persist</option></term>
693 <listitem>
32e27670
LP
694 <para>Set the flag (sticky bit) on the udev database entry of the event device. Device
695 properties are then kept in the database even when <command>udevadm info
696 --cleanup-db</command> is called. This option can be useful in certain cases
697 (e.g. Device Mapper devices) for persisting device state on the transition from
698 initrd.</para>
aefdc112
AK
699
700 <xi:include href="version-info.xml" xpointer="v241"/>
bc117ec3
YLY
701 </listitem>
702 </varlistentry>
563a94d0
YW
703 <varlistentry>
704 <term><option>log_level=<replaceable>level</replaceable></option></term>
705 <listitem>
706 <para>Takes a log level name like <literal>debug</literal> or
707 <literal>info</literal>, or a special value <literal>reset</literal>. When a log
708 level name is specified, the maximum log level is changed to that level. When
709 <literal>reset</literal> is set, then the previously specified log level is
710 revoked. Defaults to the log level of the main process of
711 <command>systemd-udevd</command>.</para>
712 <para>This may be useful when debugging events for certain devices. Note that the
713 log level is applied when the line including this rule is processed. So, for
714 debugging, it is recommended that this is specified at earlier place, e.g., the
715 first line of <filename>00-debug.rules</filename>.</para>
c86efe34 716 <para>Example for debugging uevent processing for network interfaces:
563a94d0
YW
717 <programlisting># /etc/udev/rules.d/00-debug-net.rules
718SUBSYSTEM=="net", OPTIONS="log_level=debug"</programlisting></para>
ec07c3c8
AK
719
720 <xi:include href="version-info.xml" xpointer="v248"/>
563a94d0
YW
721 </listitem>
722 </varlistentry>
b4ffb776
YW
723 <varlistentry>
724 <term><option>dump</option></term>
725 <listitem>
726 <para>Dump the status of the event currently processing. It may be useful for debugging
727 udev rules by inserting this option.</para>
728
729 <xi:include href="version-info.xml" xpointer="v258"/>
730 </listitem>
731 </varlistentry>
bc117ec3
YLY
732 </variablelist>
733 </listitem>
734 </varlistentry>
735 </variablelist>
736
793166ae 737 <para>The <varname>ENV</varname>, <varname>GROUP</varname>,
738 <varname>MODE</varname>, <varname>NAME</varname>,
739 <varname>OWNER</varname>, <varname>PROGRAM</varname>,
740 <varname>RUN</varname>, <varname>SECLABEL</varname>, and
741 <varname>SYMLINK</varname> fields support simple string substitutions.
bc117ec3
YLY
742 The <varname>RUN</varname> substitutions are performed after all rules
743 have been processed, right before the program is executed, allowing for
793166ae 744 the use of device properties set by earlier matching rules. For all
745 other fields, substitutions are performed while the individual rule is
746 being processed. The available substitutions are:</para>
bc117ec3
YLY
747 <variablelist class='udev-directives'>
748 <varlistentry>
749 <term><option>$kernel</option>, <option>%k</option></term>
750 <listitem>
751 <para>The kernel name for this device.</para>
752 </listitem>
753 </varlistentry>
754
755 <varlistentry>
756 <term><option>$number</option>, <option>%n</option></term>
757 <listitem>
758 <para>The kernel number for this device. For example, <literal>sda3</literal> has kernel number
759 3.</para>
760 </listitem>
761 </varlistentry>
762
763 <varlistentry>
764 <term><option>$devpath</option>, <option>%p</option></term>
765 <listitem>
766 <para>The devpath of the device.</para>
767 </listitem>
768 </varlistentry>
769
770 <varlistentry>
771 <term><option>$id</option>, <option>%b</option></term>
772 <listitem>
773 <para>The name of the device matched while searching the devpath
774 upwards for <option>SUBSYSTEMS</option>, <option>KERNELS</option>,
775 <option>DRIVERS</option>, and <option>ATTRS</option>.
776 </para>
777 </listitem>
778 </varlistentry>
779
780 <varlistentry>
781 <term><option>$driver</option></term>
782 <listitem>
783 <para>The driver name of the device matched while searching the
784 devpath upwards for <option>SUBSYSTEMS</option>,
785 <option>KERNELS</option>, <option>DRIVERS</option>, and
786 <option>ATTRS</option>.
787 </para>
788 </listitem>
789 </varlistentry>
790
791 <varlistentry>
792 <term><option>$attr{<replaceable>file</replaceable>}</option>, <option>%s{<replaceable>file</replaceable>}</option></term>
793 <listitem>
794 <para>The value of a sysfs attribute found at the device where
795 all keys of the rule have matched. If the matching device does not
796 have such an attribute, and a previous <option>KERNELS</option>,
797 <option>SUBSYSTEMS</option>, <option>DRIVERS</option>, or
798 <option>ATTRS</option> test selected a parent device, then the
799 attribute from that parent device is used.
800 </para>
801 <para>If the attribute is a symlink, the last element of the
802 symlink target is returned as the value.
803 </para>
804 </listitem>
805 </varlistentry>
806
807 <varlistentry>
808 <term><option>$env{<replaceable>key</replaceable>}</option>, <option>%E{<replaceable>key</replaceable>}</option></term>
809 <listitem>
810 <para>A device property value.</para>
811 </listitem>
812 </varlistentry>
813
814 <varlistentry>
815 <term><option>$major</option>, <option>%M</option></term>
816 <listitem>
817 <para>The kernel major number for the device.</para>
818 </listitem>
819 </varlistentry>
820
821 <varlistentry>
822 <term><option>$minor</option>, <option>%m</option></term>
823 <listitem>
824 <para>The kernel minor number for the device.</para>
825 </listitem>
826 </varlistentry>
827
828 <varlistentry>
829 <term><option>$result</option>, <option>%c</option></term>
830 <listitem>
831 <para>The string returned by the external program requested with
832 <varname>PROGRAM</varname>.
833 A single part of the string, separated by a space character, may be selected
834 by specifying the part number as an attribute: <literal>%c{N}</literal>.
835 If the number is followed by the <literal>+</literal> character, this part plus all remaining parts
836 of the result string are substituted: <literal>%c{N+}</literal>.</para>
837 </listitem>
838 </varlistentry>
839
840 <varlistentry>
841 <term><option>$parent</option>, <option>%P</option></term>
842 <listitem>
843 <para>The node name of the parent device.</para>
844 </listitem>
845 </varlistentry>
846
847 <varlistentry>
848 <term><option>$name</option></term>
849 <listitem>
850 <para>The current name of the device. If not changed by a rule, it is the
851 name of the kernel device.</para>
852 </listitem>
853 </varlistentry>
854
855 <varlistentry>
856 <term><option>$links</option></term>
857 <listitem>
858 <para>A space-separated list of the current symlinks. The value is
859 only set during a remove event or if an earlier rule assigned a value.</para>
860 </listitem>
861 </varlistentry>
862
863 <varlistentry>
864 <term><option>$root</option>, <option>%r</option></term>
865 <listitem>
866 <para>The udev_root value.</para>
867 </listitem>
868 </varlistentry>
869
870 <varlistentry>
871 <term><option>$sys</option>, <option>%S</option></term>
872 <listitem>
873 <para>The sysfs mount point.</para>
874 </listitem>
875 </varlistentry>
876
877 <varlistentry>
878 <term><option>$devnode</option>, <option>%N</option></term>
879 <listitem>
880 <para>The name of the device node.</para>
881 </listitem>
882 </varlistentry>
883
884 <varlistentry>
885 <term><option>%%</option></term>
886 <listitem>
887 <para>The <literal>%</literal> character itself.</para>
888 </listitem>
889 </varlistentry>
890
891 <varlistentry>
892 <term><option>$$</option></term>
893 <listitem>
894 <para>The <literal>$</literal> character itself.</para>
895 </listitem>
896 </varlistentry>
897 </variablelist>
898 </refsect2>
63749b1a
KS
899 </refsect1>
900
63749b1a
KS
901 <refsect1>
902 <title>See Also</title>
13a69c12
DT
903 <para><simplelist type="inline">
904 <member><citerefentry>
b79f817b 905 <refentrytitle>systemd-udevd.service</refentrytitle><manvolnum>8</manvolnum>
13a69c12
DT
906 </citerefentry></member>
907 <member><citerefentry>
63749b1a 908 <refentrytitle>udevadm</refentrytitle><manvolnum>8</manvolnum>
13a69c12
DT
909 </citerefentry></member>
910 <member><citerefentry>
1ff28eae 911 <refentrytitle>systemd.link</refentrytitle><manvolnum>5</manvolnum>
13a69c12
DT
912 </citerefentry></member>
913 </simplelist></para>
63749b1a
KS
914 </refsect1>
915</refentry>