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