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