udev.7 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. '\" t
  2. .TH "UDEV" "7" "" "systemd 202" "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"
  23. udev \- Linux dynamic device management
  24. .SH "DESCRIPTION"
  25. .PP
  26. udev supplies the system software with device events, manages permissions of device nodes and may create additional symlinks in the
  27. /dev
  28. directory, 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
  30. The 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
  33. All 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
  36. The 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
  39. and 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
  42. have the highest priority, files in
  43. /run
  44. take 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
  47. with the same name as a rules file in
  48. /lib, pointing to
  49. /dev/null, disables the rules file entirely\&.
  50. .PP
  51. Rule files must have the extension
  52. \&.rules; other extensions are ignored\&.
  53. .PP
  54. Every 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
  56. A 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
  58. A 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
  62. Compare for equality\&.
  63. .RE
  64. .PP
  65. !=
  66. .RS 4
  67. Compare for inequality\&.
  68. .RE
  69. .PP
  70. =
  71. .RS 4
  72. Assign 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
  77. Add the value to a key that holds a list of entries\&.
  78. .RE
  79. .PP
  80. :=
  81. .RS 4
  82. Assign a value to a key finally; disallow any later changes\&.
  83. .RE
  84. .PP
  85. The 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
  89. Match the name of the event action\&.
  90. .RE
  91. .PP
  92. \fBDEVPATH\fR
  93. .RS 4
  94. Match the devpath of the event device\&.
  95. .RE
  96. .PP
  97. \fBKERNEL\fR
  98. .RS 4
  99. Match the name of the event device\&.
  100. .RE
  101. .PP
  102. \fBNAME\fR
  103. .RS 4
  104. Match 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
  109. Match 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
  114. Match the subsystem of the event device\&.
  115. .RE
  116. .PP
  117. \fBDRIVER\fR
  118. .RS 4
  119. Match 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
  124. Match 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
  129. Search the devpath upwards for a matching device name\&.
  130. .RE
  131. .PP
  132. \fBSUBSYSTEMS\fR
  133. .RS 4
  134. Search the devpath upwards for a matching device subsystem name\&.
  135. .RE
  136. .PP
  137. \fBDRIVERS\fR
  138. .RS 4
  139. Search 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
  144. Search the devpath upwards for a device with matching sysfs attribute values\&. If multiple
  145. \fBATTRS\fR
  146. matches 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
  151. Search 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
  156. Match against a device property value\&.
  157. .RE
  158. .PP
  159. \fBTAG\fR
  160. .RS 4
  161. Match against a device tag\&.
  162. .RE
  163. .PP
  164. \fBTEST{\fR\fB\fIoctal mode mask\fR\fR\fB}\fR
  165. .RS 4
  166. Test the existence of a file\&. An octal mode mask can be specified if needed\&.
  167. .RE
  168. .PP
  169. \fBPROGRAM\fR
  170. .RS 4
  171. Execute 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
  173. This 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
  179. Match 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
  182. Most of the fields support shell\-style pattern matching\&. The following pattern characters are supported:
  183. .PP
  184. *
  185. .RS 4
  186. Matches zero or more characters\&.
  187. .RE
  188. .PP
  189. ?
  190. .RS 4
  191. Matches any single character\&.
  192. .RE
  193. .PP
  194. []
  195. .RS 4
  196. Matches 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
  199. The following keys can get values assigned:
  200. .PP
  201. \fBNAME\fR
  202. .RS 4
  203. The 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
  208. The name of a symlink targeting the node\&. Every matching rule adds this value to the list of symlinks to be created\&.
  209. .sp
  210. The 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
  212. Multiple 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
  214. Symlink 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
  219. The 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
  224. The 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
  229. Set 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
  234. Attach 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
  239. Add a program to the list of programs to be executed after processing all the rules for a specific event, depending on
  240. type:
  241. .PP
  242. program
  243. .RS 4
  244. Execute 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
  246. This is the default if no
  247. \fItype\fR
  248. is specified\&.
  249. .RE
  250. .PP
  251. builtin
  252. .RS 4
  253. As
  254. \fBprogram\fR, but use one of the built\-in programs rather than an external one\&.
  255. .RE
  256. .sp
  257. The program name and following arguments are separated by spaces\&. Single quotes can be used to specify arguments with spaces\&.
  258. .sp
  259. This 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
  261. Starting 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
  266. A named label to which a GOTO may jump\&.
  267. .RE
  268. .PP
  269. \fBGOTO\fR
  270. .RS 4
  271. Jumps to the next LABEL with a matching name\&.
  272. .RE
  273. .PP
  274. \fBIMPORT{\fR\fB\fItype\fR\fR\fB}\fR
  275. .RS 4
  276. Import a set of variables as device properties, depending on
  277. type:
  278. .PP
  279. program
  280. .RS 4
  281. Execute 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
  285. builtin
  286. .RS 4
  287. As
  288. \fBprogram\fR, but use one of the built\-in programs rather than an external one\&.
  289. .RE
  290. .PP
  291. file
  292. .RS 4
  293. Import a text file specified as the assigned value, the content of which must be in environment key format\&.
  294. .RE
  295. .PP
  296. db
  297. .RS 4
  298. Import 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
  301. cmdline
  302. .RS 4
  303. Import 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
  306. parent
  307. .RS 4
  308. Import the stored keys from the parent device by reading the database entry of the parent device\&. The value assigned to
  309. \fBIMPORT{parent}\fR
  310. is used as a filter of key names to import (with the same shell\-style pattern matching used for comparisons)\&.
  311. .RE
  312. .sp
  313. This 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
  319. Wait 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
  324. Rule and device options:
  325. .PP
  326. \fBlink_priority=\fR\fB\fIvalue\fR\fR
  327. .RS 4
  328. Specify 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
  333. Number 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
  338. Usually 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
  343. Apply 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
  348. Watch 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
  353. Disable the watching of a device node with inotify\&.
  354. .RE
  355. .RE
  356. .PP
  357. The
  358. \fBNAME\fR,
  359. \fBSYMLINK\fR,
  360. \fBPROGRAM\fR,
  361. \fBOWNER\fR,
  362. \fBGROUP\fR,
  363. \fBMODE\fR
  364. and
  365. \fBRUN\fR
  366. fields support simple string substitutions\&. The
  367. \fBRUN\fR
  368. substitutions 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
  372. The kernel name for this device\&.
  373. .RE
  374. .PP
  375. \fB$number\fR, \fB%n\fR
  376. .RS 4
  377. The 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
  382. The devpath of the device\&.
  383. .RE
  384. .PP
  385. \fB$id\fR, \fB%b\fR
  386. .RS 4
  387. The name of the device matched while searching the devpath upwards for
  388. \fBSUBSYSTEMS\fR,
  389. \fBKERNELS\fR,
  390. \fBDRIVERS\fR
  391. and
  392. \fBATTRS\fR\&.
  393. .RE
  394. .PP
  395. \fB$driver\fR
  396. .RS 4
  397. The driver name of the device matched while searching the devpath upwards for
  398. \fBSUBSYSTEMS\fR,
  399. \fBKERNELS\fR,
  400. \fBDRIVERS\fR
  401. and
  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
  407. The 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
  409. If 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
  414. A device property value\&.
  415. .RE
  416. .PP
  417. \fB$major\fR, \fB%M\fR
  418. .RS 4
  419. The kernel major number for the device\&.
  420. .RE
  421. .PP
  422. \fB$minor\fR, \fB%m\fR
  423. .RS 4
  424. The kernel minor number for the device\&.
  425. .RE
  426. .PP
  427. \fB$result\fR, \fB%c\fR
  428. .RS 4
  429. The 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
  436. The node name of the parent device\&.
  437. .RE
  438. .PP
  439. \fB$name\fR
  440. .RS 4
  441. The 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
  446. A 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
  451. The udev_root value\&.
  452. .RE
  453. .PP
  454. \fB$sys\fR, \fB%S\fR
  455. .RS 4
  456. The sysfs mount point\&.
  457. .RE
  458. .PP
  459. \fB$devnode\fR, \fB%N\fR
  460. .RS 4
  461. The name of the device node\&.
  462. .RE
  463. .PP
  464. %%
  465. .RS 4
  466. The \*(Aq%\*(Aq character itself\&.
  467. .RE
  468. .PP
  469. $$
  470. .RS 4
  471. The \*(Aq$\*(Aq character itself\&.
  472. .RE
  473. .SH "SEE ALSO"
  474. .PP
  475. \fBudevd\fR(8),
  476. \fBudevadm\fR(8)