Ticket #3317: udev.7

File udev.7, 16.1 KB (added by bdubbs@…, 12 years ago)
Line 
1'\" t
2.TH "UDEV" "7" "" "systemd 199" "udev"
3.\" -----------------------------------------------------------------
4.\" * Define some portability stuff
5.\" -----------------------------------------------------------------
6.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7.\" http://bugs.debian.org/507673
8.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
9.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10.ie \n(.g .ds Aq \(aq
11.el .ds Aq '
12.\" -----------------------------------------------------------------
13.\" * set default formatting
14.\" -----------------------------------------------------------------
15.\" disable hyphenation
16.nh
17.\" disable justification (adjust text to left margin only)
18.ad l
19.\" -----------------------------------------------------------------
20.\" * MAIN CONTENT STARTS HERE *
21.\" -----------------------------------------------------------------
22.SH "NAME"
23udev \- Linux dynamic device management
24.SH "DESCRIPTION"
25.PP
26udev supplies the system software with device events, manages permissions of device nodes and may create additional symlinks in the
27/dev
28directory, or renames network interfaces\&. The kernel usually just assigns unpredictable device names based on the order of discovery\&. Meaningful symlinks or network device names provide a way to reliably identify devices based on their properties or current configuration\&.
29.PP
30The udev daemon,
31\fBudevd\fR(8), receives device uevents directly from the kernel whenever a device is added or removed from the system, or it changes its state\&. When udev receives a device event, it matches its configured set of rules against various device attributes to identify the device\&. Rules that match may provide additional device information to be stored in the udev database or to be used to create meaningful symlink names\&.
32.PP
33All device information udev processes is stored in the udev database and sent out to possible event subscribers\&. Access to all stored data and the event sources is provided by the library libudev\&.
34.SH "RULES FILES"
35.PP
36The udev rules are read from the files located in the system rules directory
37/usr/lib/udev/rules\&.d, the volatile runtime directory
38/run/udev/rules\&.d
39and the local administration directory
40/etc/udev/rules\&.d\&. All rules files are collectively sorted and processed in lexical order, regardless of the directories in which they live\&. However, files with identical file names replace each other\&. Files in
41/etc
42have the highest priority, files in
43/run
44take precedence over files with the same name in
45/lib\&. This can be used to override a system\-supplied rules file with a local file if needed; a symlink in
46/etc
47with the same name as a rules file in
48/lib, pointing to
49/dev/null, disables the rules file entirely\&.
50.PP
51Rule files must have the extension
52\&.rules; other extensions are ignored\&.
53.PP
54Every line in the rules file contains at least one key\-value pair\&. Except for empty lines or lines beginning with \*(Aq#\*(Aq, which are ignored\&. There are two kinds of keys: match and assignment\&. If all match keys match against their values, the rule gets applied and the assignment keys get the specified values assigned\&.
55.PP
56A matching rule may rename a network interface, add symlinks pointing to the device node, or run a specified program as part of the event handling\&.
57.PP
58A rule consists of a comma\-separated list of one or more key\-value pairs\&. Each key has a distinct operation, depending on the used operator\&. Valid operators are:
59.PP
60==
61.RS 4
62Compare for equality\&.
63.RE
64.PP
65!=
66.RS 4
67Compare for inequality\&.
68.RE
69.PP
70=
71.RS 4
72Assign a value to a key\&. Keys that represent a list are reset and only this single value is assigned\&.
73.RE
74.PP
75+=
76.RS 4
77Add the value to a key that holds a list of entries\&.
78.RE
79.PP
80:=
81.RS 4
82Assign a value to a key finally; disallow any later changes\&.
83.RE
84.PP
85The following key names can be used to match against device properties\&. Some of the keys also match against properties of the parent devices in sysfs, not only the device that has generated the event\&. If multiple keys that match a parent device are specified in a single rule, all these keys must match at one and the same parent device\&.
86.PP
87\fBACTION\fR
88.RS 4
89Match the name of the event action\&.
90.RE
91.PP
92\fBDEVPATH\fR
93.RS 4
94Match the devpath of the event device\&.
95.RE
96.PP
97\fBKERNEL\fR
98.RS 4
99Match the name of the event device\&.
100.RE
101.PP
102\fBNAME\fR
103.RS 4
104Match the name of a network interface\&. It can be used once the NAME key has been set in one of the preceding rules\&.
105.RE
106.PP
107\fBSYMLINK\fR
108.RS 4
109Match the name of a symlink targeting the node\&. It can be used once a SYMLINK key has been set in one of the preceding rules\&. There may be multiple symlinks; only one needs to match\&.
110.RE
111.PP
112\fBSUBSYSTEM\fR
113.RS 4
114Match the subsystem of the event device\&.
115.RE
116.PP
117\fBDRIVER\fR
118.RS 4
119Match the driver name of the event device\&. Only set this key for devices which are bound to a driver at the time the event is generated\&.
120.RE
121.PP
122\fBATTR{\fR\fB\fIfilename\fR\fR\fB}\fR
123.RS 4
124Match sysfs attribute values of the event device\&. Trailing whitespace in the attribute values is ignored unless the specified match value itself contains trailing whitespace\&.
125.RE
126.PP
127\fBKERNELS\fR
128.RS 4
129Search the devpath upwards for a matching device name\&.
130.RE
131.PP
132\fBSUBSYSTEMS\fR
133.RS 4
134Search the devpath upwards for a matching device subsystem name\&.
135.RE
136.PP
137\fBDRIVERS\fR
138.RS 4
139Search the devpath upwards for a matching device driver name\&.
140.RE
141.PP
142\fBATTRS{\fR\fB\fIfilename\fR\fR\fB}\fR
143.RS 4
144Search the devpath upwards for a device with matching sysfs attribute values\&. If multiple
145\fBATTRS\fR
146matches are specified, all of them must match on the same device\&. Trailing whitespace in the attribute values is ignored unless the specified match value itself contains trailing whitespace\&.
147.RE
148.PP
149\fBTAGS\fR
150.RS 4
151Search the devpath upwards for a device with matching tag\&.
152.RE
153.PP
154\fBENV{\fR\fB\fIkey\fR\fR\fB}\fR
155.RS 4
156Match against a device property value\&.
157.RE
158.PP
159\fBTAG\fR
160.RS 4
161Match against a device tag\&.
162.RE
163.PP
164\fBTEST{\fR\fB\fIoctal mode mask\fR\fR\fB}\fR
165.RS 4
166Test the existence of a file\&. An octal mode mask can be specified if needed\&.
167.RE
168.PP
169\fBPROGRAM\fR
170.RS 4
171Execute a program to determine whether there is a match; the key is true if the program returns successfully\&. The device properties are made available to the executed program in the environment\&. The program\*(Aqs stdout is available in the RESULT key\&.
172.sp
173This can only be used for very short\-running foreground tasks\&. For details see
174\fBRUN\fR\&.
175.RE
176.PP
177\fBRESULT\fR
178.RS 4
179Match the returned string of the last PROGRAM call\&. This key can be used in the same or in any later rule after a PROGRAM call\&.
180.RE
181.PP
182Most of the fields support shell\-style pattern matching\&. The following pattern characters are supported:
183.PP
184*
185.RS 4
186Matches zero or more characters\&.
187.RE
188.PP
189?
190.RS 4
191Matches any single character\&.
192.RE
193.PP
194[]
195.RS 4
196Matches any single character specified within the brackets\&. For example, the pattern string \*(Aqtty[SR]\*(Aq would match either \*(AqttyS\*(Aq or \*(AqttyR\*(Aq\&. Ranges are also supported via the \*(Aq\-\*(Aq character\&. For example, to match on the range of all digits, the pattern [0\-9] could be used\&. If the first character following the \*(Aq[\*(Aq is a \*(Aq!\*(Aq, any characters not enclosed are matched\&.
197.RE
198.PP
199The following keys can get values assigned:
200.PP
201\fBNAME\fR
202.RS 4
203The name to use for a network interface\&. The name of a device node cannot be changed by udev, only additional symlinks can be created\&.
204.RE
205.PP
206\fBSYMLINK\fR
207.RS 4
208The name of a symlink targeting the node\&. Every matching rule adds this value to the list of symlinks to be created\&.
209.sp
210The set of characters to name a symlink is limited\&. Allowed characters are [0\-9A\-Za\-z#+\-\&.:=@_/], valid utf8 character sequences, and "\ex00" hex encoding\&. All other characters are replaced by a \*(Aq_\*(Aq character\&.
211.sp
212Multiple symlinks may be specified by separating the names by the space character\&. In case multiple devices claim the same name, the link always points to the device with the highest link_priority\&. If the current device goes away, the links are re\-evaluated and the device with the next highest link_priority becomes the owner of the link\&. If no link_priority is specified, the order of the devices (and which one of them owns the link) is undefined\&.
213.sp
214Symlink names must never conflict with the kernel\*(Aqs default device node names, as that would result in unpredictable behavior\&.
215.RE
216.PP
217\fBOWNER\fR, \fBGROUP\fR, \fBMODE\fR
218.RS 4
219The permissions for the device node\&. Every specified value overrides the compiled\-in default value\&.
220.RE
221.PP
222\fBATTR{\fR\fB\fIkey\fR\fR\fB}\fR
223.RS 4
224The value that should be written to a sysfs attribute of the event device\&.
225.RE
226.PP
227\fBENV{\fR\fB\fIkey\fR\fR\fB}\fR
228.RS 4
229Set a device property value\&. Property names with a leading \*(Aq\&.\*(Aq are neither stored in the database nor exported to events or external tools (run by, say, the PROGRAM match key)\&.
230.RE
231.PP
232\fBTAG\fR
233.RS 4
234Attach a tag to a device\&. This is used to filter events for users of libudev\*(Aqs monitor functionality, or to enumerate a group of tagged devices\&. The implementation can only work efficiently if only a few tags are attached to a device\&. It is only meant to be used in contexts with specific device filter requirements, and not as a general\-purpose flag\&. Excessive use might result in inefficient event handling\&.
235.RE
236.PP
237\fBRUN{\fR\fB\fItype\fR\fR\fB}\fR
238.RS 4
239Add a program to the list of programs to be executed after processing all the rules for a specific event, depending on
240type:
241.PP
242program
243.RS 4
244Execute an external program specified as the assigned value\&. If no absolute path is given, the program is expected to live in /usr/lib/udev, otherwise the absolute path must be specified\&.
245.sp
246This is the default if no
247\fItype\fR
248is specified\&.
249.RE
250.PP
251builtin
252.RS 4
253As
254\fBprogram\fR, but use one of the built\-in programs rather than an external one\&.
255.RE
256.sp
257The program name and following arguments are separated by spaces\&. Single quotes can be used to specify arguments with spaces\&.
258.sp
259This can only be used for very short\-running foreground tasks\&. Running an event process for a long period of time may block all further events for this or a dependent device\&.
260.sp
261Starting daemons or other long running processes is not appropriate for udev; the forked processes, detached or not, will be unconditionally killed after the event handling has finished\&.
262.RE
263.PP
264\fBLABEL\fR
265.RS 4
266A named label to which a GOTO may jump\&.
267.RE
268.PP
269\fBGOTO\fR
270.RS 4
271Jumps to the next LABEL with a matching name\&.
272.RE
273.PP
274\fBIMPORT{\fR\fB\fItype\fR\fR\fB}\fR
275.RS 4
276Import a set of variables as device properties, depending on
277type:
278.PP
279program
280.RS 4
281Execute an external program specified as the assigned value and import its output, which must be in environment key format\&. Path specification, command/argument separation, and quoting work like in
282\fBRUN\fR\&.
283.RE
284.PP
285builtin
286.RS 4
287As
288\fBprogram\fR, but use one of the built\-in programs rather than an external one\&.
289.RE
290.PP
291file
292.RS 4
293Import a text file specified as the assigned value, the content of which must be in environment key format\&.
294.RE
295.PP
296db
297.RS 4
298Import a single property specified as the assigned value from the current device database\&. This works only if the database is already populated by an earlier event\&.
299.RE
300.PP
301cmdline
302.RS 4
303Import a single property from the kernel command line\&. For simple flags the value of the property is set to \*(Aq1\*(Aq\&.
304.RE
305.PP
306parent
307.RS 4
308Import the stored keys from the parent device by reading the database entry of the parent device\&. The value assigned to
309\fBIMPORT{parent}\fR
310is used as a filter of key names to import (with the same shell\-style pattern matching used for comparisons)\&.
311.RE
312.sp
313This can only be used for very short\-running foreground tasks\&. For details see
314\fBRUN\fR\&.
315.RE
316.PP
317\fBWAIT_FOR\fR
318.RS 4
319Wait for a file to become available or until a timeout of 10 seconds expires\&. The path is relative to the sysfs device; if no path is specified, this waits for an attribute to appear\&.
320.RE
321.PP
322\fBOPTIONS\fR
323.RS 4
324Rule and device options:
325.PP
326\fBlink_priority=\fR\fB\fIvalue\fR\fR
327.RS 4
328Specify the priority of the created symlinks\&. Devices with higher priorities overwrite existing symlinks of other devices\&. The default is 0\&.
329.RE
330.PP
331\fBevent_timeout=\fR
332.RS 4
333Number of seconds an event waits for operations to finish before giving up and terminating itself\&.
334.RE
335.PP
336\fBstring_escape=\fR\fB\fInone|replace\fR\fR
337.RS 4
338Usually control and other possibly unsafe characters are replaced in strings used for device naming\&. The mode of replacement can be specified with this option\&.
339.RE
340.PP
341\fBstatic_node=\fR
342.RS 4
343Apply the permissions specified in this rule to the static device node with the specified name\&. Static device node creation can be requested by kernel modules\&. These nodes might not have a corresponding kernel device at the time udevd is started; they can trigger automatic kernel module loading\&.
344.RE
345.PP
346\fBwatch\fR
347.RS 4
348Watch the device node with inotify; when the node is closed after being opened for writing, a change uevent is synthesized\&.
349.RE
350.PP
351\fBnowatch\fR
352.RS 4
353Disable the watching of a device node with inotify\&.
354.RE
355.RE
356.PP
357The
358\fBNAME\fR,
359\fBSYMLINK\fR,
360\fBPROGRAM\fR,
361\fBOWNER\fR,
362\fBGROUP\fR,
363\fBMODE\fR
364and
365\fBRUN\fR
366fields support simple string substitutions\&. The
367\fBRUN\fR
368substitutions are performed after all rules have been processed, right before the program is executed, allowing for the use of device properties set by earlier matching rules\&. For all other fields, substitutions are performed while the individual rule is being processed\&. The available substitutions are:
369.PP
370\fB$kernel\fR, \fB%k\fR
371.RS 4
372The kernel name for this device\&.
373.RE
374.PP
375\fB$number\fR, \fB%n\fR
376.RS 4
377The kernel number for this device\&. For example, \*(Aqsda3\*(Aq has kernel number of \*(Aq3\*(Aq
378.RE
379.PP
380\fB$devpath\fR, \fB%p\fR
381.RS 4
382The devpath of the device\&.
383.RE
384.PP
385\fB$id\fR, \fB%b\fR
386.RS 4
387The name of the device matched while searching the devpath upwards for
388\fBSUBSYSTEMS\fR,
389\fBKERNELS\fR,
390\fBDRIVERS\fR
391and
392\fBATTRS\fR\&.
393.RE
394.PP
395\fB$driver\fR
396.RS 4
397The driver name of the device matched while searching the devpath upwards for
398\fBSUBSYSTEMS\fR,
399\fBKERNELS\fR,
400\fBDRIVERS\fR
401and
402\fBATTRS\fR\&.
403.RE
404.PP
405\fB$attr{\fR\fB\fIfile\fR\fR\fB}\fR, \fB%s{\fR\fB\fIfile\fR\fR\fB}\fR
406.RS 4
407The value of a sysfs attribute found at the device where all keys of the rule have matched\&. If the matching device does not have such an attribute, and a previous KERNELS, SUBSYSTEMS, DRIVERS, or ATTRS test selected a parent device, then the attribute from that parent device is used\&.
408.sp
409If the attribute is a symlink, the last element of the symlink target is returned as the value\&.
410.RE
411.PP
412\fB$env{\fR\fB\fIkey\fR\fR\fB}\fR, \fB%E{\fR\fB\fIkey\fR\fR\fB}\fR
413.RS 4
414A device property value\&.
415.RE
416.PP
417\fB$major\fR, \fB%M\fR
418.RS 4
419The kernel major number for the device\&.
420.RE
421.PP
422\fB$minor\fR, \fB%m\fR
423.RS 4
424The kernel minor number for the device\&.
425.RE
426.PP
427\fB$result\fR, \fB%c\fR
428.RS 4
429The string returned by the external program requested with PROGRAM\&. A single part of the string, separated by a space character, may be selected by specifying the part number as an attribute:
430\fB%c{N}\fR\&. If the number is followed by the \*(Aq+\*(Aq character, this part plus all remaining parts of the result string are substituted:
431\fB%c{N+}\fR
432.RE
433.PP
434\fB$parent\fR, \fB%P\fR
435.RS 4
436The node name of the parent device\&.
437.RE
438.PP
439\fB$name\fR
440.RS 4
441The current name of the device\&. If not changed by a rule, it is the name of the kernel device\&.
442.RE
443.PP
444\fB$links\fR
445.RS 4
446A space\-separated list of the current symlinks\&. The value is only set during a remove event or if an earlier rule assigned a value\&.
447.RE
448.PP
449\fB$root\fR, \fB%r\fR
450.RS 4
451The udev_root value\&.
452.RE
453.PP
454\fB$sys\fR, \fB%S\fR
455.RS 4
456The sysfs mount point\&.
457.RE
458.PP
459\fB$devnode\fR, \fB%N\fR
460.RS 4
461The name of the device node\&.
462.RE
463.PP
464%%
465.RS 4
466The \*(Aq%\*(Aq character itself\&.
467.RE
468.PP
469$$
470.RS 4
471The \*(Aq$\*(Aq character itself\&.
472.RE
473.SH "SEE ALSO"
474.PP
475\fBudevd\fR(8),
476\fBudevadm\fR(8)