[LFS Trac] #1790: udev rules need documented

LFS Trac trac at linuxfromscratch.org
Tue May 9 15:50:45 PDT 2006

#1790: udev rules need documented
 Reporter:  archaic at linuxfromscratch.org  |        Owner:  lfs-book at linuxfromscratch.org
     Type:  task                          |       Status:  new                          
 Priority:  normal                        |    Milestone:  6.2                          
Component:  Book                          |      Version:  SVN                          
 Severity:  normal                        |   Resolution:                               
 Keywords:                                |  
Comment (by archaic at linuxfromscratch.org):

 Okay, here's round one. Please help correct this for accuracy, grammar,
 and readability. I don't know how pedantic and technical I should be for
 the book.

 All discussion of devices below refers to devices which can be properly
 exported by the kernel via sysfs (as discussed on xref="the page that
 dicusses this").

 Uevent: An event generated by the kernel whenever a device is added or
 removed. In this context, added doesn't necessarily mean the device was
 just plugged in. It means the kernel now recognizes it. All devices are
 "added" when the kernel is first booting up.

 ACTION=="add", DEVPATH=="/devices/*", ENV{PHYSDEVBUS}=="?*",

 The files, directories, and symlinks in /sys do not all appear at once.
 They appear as the kernel identifies and enumerates them. However, the
 uevent will be generated as soon as the device is known to the kernel. For
 some devices, it may take the kernel an extra few milliseconds to export
 all the information to /sys/devices while Udev may already be processing
 the uevent. To avoid race conditions, this rule matches those devices
 (which have an ACTION of add, DEVPATH of /devices/*, and a non-empty
 environment variable named PHYSDEVBUS) and causes Udev to wait until the
 kernel has created the needed "bus" file (in this case it will be a
 symlink) for that particular device before it attempts to match any other
 rule. This gives the kernel time to enumerate the various devices and
 export them via sysfs.

 ACTION=="add", SUBSYSTEM=="scsi", WAIT_FOR_SYSFS="ioerr_cnt"

 Very similar to the previous rule, any uevent for devices handled by the
 kernel's SCSI subsystem where the ACTION to take is "add" the device, Udev
 will wait for the existence of the file /sys/bus/scsi/devices/<device


 The majority of rules exist to create device nodes. In the above example
 any uevent generated by the kernel with the name "mice" will cause a
 device node to be created at /dev/mice with a default ownership of
 root:root and default permissions of 0660. To change the permissions or
 ownership, one would fine-tune the above rule as such:

 KERNEL=="mice", MODE="0644", GROUP="some group"

 Further additions to the rule allow modifying the location where the
 device node is created. For example, /dev/mice is not the standard
 location for the mice device node, /dev/input/mice is. We can acheive this

 KERNEL=="mice", MODE="0644", GROUP="some group", NAME="input/%k"

 Finally, if this device commonly has a symlink associated with it -- for
 example, /dev/mouse often is a symlink to /dev/input/mice -- you can
 acheive this with the following:

 KERNEL=="mice", MODE="0644", GROUP="some group", NAME="input/%k",

 A final word of caution: Any particular rule must be written on one line
 and a comma must separate each part of the rule.

Ticket URL: <http://wiki.linuxfromscratch.org/lfs/ticket/1790>
LFS Trac <http://wiki.linuxfromscratch.org/lfs/>
Linux From Scratch: Your Distro, Your Rules.

More information about the lfs-book mailing list