55-lfs.txt 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. Purpose of rules file:
  2. This is the core rules file for Udev on LFS. If these rules were not included,
  3. most devices would either only work for root, or would not work at all.
  4. Description of rules:
  5. By default, Udev creates device nodes with UID 0, GID 0, and permissions 0660,
  6. and in one flat directory structure with all nodes in /dev. This does not
  7. always work well.
  8. KERNEL=="ptmx"
  9. Any uevent generated by the kernel with a name matching "ptmx" will match this
  10. rule. Note that the matching done by Udev is shell-style; these are not regex
  11. matches. For the ptmx device, we first change the permisions, by assigning to
  12. the MODE value:
  13. KERNEL=="ptmx", MODE="0666"
  14. We also assign a different GID to /dev/ptmx (also all other TTY devices), by
  15. assigning to the GROUP value:
  16. KERNEL=="ptmx", MODE="0666", "GROUP="tty"
  17. There are also devices that should not be in /dev, because historically they
  18. have been created in subdirectories instead. For instance, all Alsa devices
  19. have traditionally been put into the /dev/snd subdirectory:
  20. KERNEL=="controlC[0-9]*", <...>, NAME="snd/%k"
  21. "%k" expands into "the original value of KERNEL" (note: not the pattern that was
  22. matched against). This type of rule puts any matching device into the snd/
  23. subdirectory.
  24. Sometimes we need to move devices based on more than just their name. For
  25. example, USB printer devices need to be moved to /dev/usb/lpX, but we can't
  26. match only "lp[0-9]*", because that would also match parallel port printers.
  27. So we match both KERNEL and SUBSYSTEMS in this case, to move USB printers only.
  28. Some devices also commonly have symlinks pointing to them -- for example,
  29. /dev/mouse is usually a symlink to /dev/input/mice. We acheive this by
  30. assigning to the SYMLINK value. But note that SYMLINK can store multiple values
  31. (because each device node could have multiple symlinks pointing to it), so we
  32. need to add to the list of symlinks, not overwrite the whole list:
  33. KERNEL=="mice", <...>, SYMLINK+="mouse"
  34. If we needed to add multiple symlinks, they would be space-separated inside the
  35. double quotes.
  36. Of course, symlinks, permissions, and device names can all be combined in a
  37. rule if needed. But note that if you combine permissions and symlinks, or if
  38. you combine GROUP and symlinks, the permissions of the symlink will not be
  39. modified, only those of the target device. (This is because the kernel does
  40. not pay any attention to the permissions on symlinks, only the permissions on
  41. their targets, and there's no reason to change something that won't be used.)
  42. Finally, we have this rule:
  43. SUBSYSTEM=="usb_device", PROGRAM="/bin/sh -c 'X=%k; X=$${X#usbdev}; B=$${X%%%%.*} D=$${X#*.}; echo bus/usb/$$B/$$D'", NAME="%c"
  44. This rule matches any device under the SUBSYSTEM of usb_device. (All devices
  45. that were traditionally created under /proc/bus/usb/ use this subsystem.) We
  46. tell Udev to run the specified PROGRAM; Udev will save the output of this
  47. program (it will be available under %c later).
  48. The program itself is a shell that starts by setting the variable X to the
  49. original kernel name (which is "usbdevB.D" for these devices, where B and D are
  50. the bus and device numbers of the USB device). Then, the rule re-sets X to the
  51. value of X with the string "usbdev" removed from the start. So now, X has the
  52. value "B.D". Then, the rule sets B to the value of X after a period, and all
  53. characters following it, have been removed from the end; this sets B to just
  54. the string "B" (just the bus number of the USB device). Then, the rule sets D
  55. to the value of X after a period, and all characters before it, have been
  56. removed from the beginning; this sets D to just the string "D" (just the device
  57. number).
  58. Then, the rule echoes "bus/usb/$B/$D" (bus/usb/bus-number/device-number), so
  59. Udev will capture that value. The rule sets NAME="%c" to put the device node
  60. at /dev/bus/usb/bus-number/device-number. (This is the same layout that the
  61. /proc/bus/usb/ devices used.)
  62. Most of the doubled characters in this rule are doubled so that Udev does not
  63. interpret them. The rule looks all the more confusing because of this method
  64. of escaping special characters.
  65. A final word of caution: Any particular rule must be written on one line, and a
  66. comma must separate each part of the rule.