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