source: udev-config/doc/55-lfs.txt@ a737f40

10.0 10.0-rc1 10.1 10.1-rc1 11.0 11.0-rc1 11.0-rc2 11.0-rc3 11.1 11.1-rc1 11.2 11.2-rc1 11.3 11.3-rc1 12.0 12.0-rc1 12.1 12.1-rc1 6.4 6.5 6.6 6.7 6.8 7.0 7.1 7.2 7.3 7.4 7.5 7.5-systemd 7.6 7.6-systemd 7.7 7.7-systemd 7.8 7.8-systemd 7.9 7.9-systemd 8.0 8.1 8.2 8.3 8.4 9.0 9.1 arm bdubbs/gcc13 ml-11.0 multilib renodr/libudev-from-systemd s6-init trunk xry111/arm64 xry111/arm64-12.0 xry111/clfs-ng xry111/lfs-next xry111/loongarch xry111/loongarch-12.0 xry111/loongarch-12.1 xry111/mips64el xry111/pip3 xry111/rust-wip-20221008 xry111/update-glibc
Last change on this file since a737f40 was 1c48007, checked in by Bruce Dubbs <bdubbs@…>, 16 years ago

Moved bootscripts and udev-config to BOOK
Updated Makefile to automatically generate bootscript and udev-config tarballs
Updated licesnse to be the same as BLFS

git-svn-id: http://svn.linuxfromscratch.org/LFS/trunk/BOOK@8548 4aa44e1e-78dd-0310-a6d2-fbcd4c07a689

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