|
YOUR FEEDBACK
Did you read today's front page stories & breaking news?
SYS-CON.TV |
TOP LINKS YOU MUST CLICK ON Trends Linux.SYS-CON.com: Device Management with udev and HAL on Fedora Core 4
Hotplugging everything on Fedora Core 4
By: Richard Petersen
Oct. 22, 2005 06:00 PM
This article discusses the implementation details for the new device management methods udev and HAL, now used on all Fedora Core 3 and 4 systems for all devices. It's time to relearn how devices are managed!
Managing devices is at the same time easier but much more complex. You have to use udev and HAL to configure devices, though much of this is now automatic. Device information is maintained in a special device file system called sysfs located at /sys. This is a virtual file system like /proc and is used to keep track of all devices supported by the kernel. In this article, I'll cover the initial basics of udev and HAL configuration and device management. The goal is to give you a sense of how devices are now managed on Fedora Core 4 and where to go to find the rules that now determine how devices are created.
udev: Device Files As /etc/dev is now dynamic, any changes you would make manually to the /etc/dev directory will be lost when you reboot. This includes the creation of any symbolic links such as /dev/cdrom that many software applications use. Instead, such symbolic links have to be configured in udev rules files located in the /etc/udev/rules.d directory. Default rules are already in place for the commonly used symbolic links, but you can create rules to add your own.
udev rules Each line maps a device attribute to a device name, as well as specifying any symbolic names (links). Attributes are specified using keys, of which there may be more than one. If all the keys match a device, then the associated name is used for it and a device file of that name will be generated. Instead of listing a device name, a program or script may be specified instead to generate the name. This is often the case for CD-ROM devices, where the device name could be a cdrecorder, cdrom, or dvdrom. The key fields, such as KERNEL, support pattern matching to specify collections of devices. These operate as standard filename expansion operations: *, ?, [ ]". For example, mouse* will match all devices beginning with the pattern "mouse". The following field uses the KERNEL key to match on all mouse devices as listed by the kernel: KERNEL="mouse*" The next key will match on all printer devices numbered lp0 through lp9. It uses brackets to specify a range of numbers or characters, in this case 0 through 9, [0-9]: KERNEL="lp[0-9]*" The NAME, SYMLINK, and PROGRAM fields support string substitution codes similar to the way printf codes work. Such a code is preceded by a % symbol. The code allows several possible devices and names to be referenced in the same rule. For example, %k references the kernel name for a device. The udev Man page provides many examples of udev rules using various fields. On Fedora Core 4, the 50-udev.rules file holds rules that primarily use KERNEL keys to designate devices. The KERNEL key is followed by either a NAME field to specify the device filename or a SYMLINK field to set up a symbolic link for a device file. The following rule uses the KERNEL key to match on all mouse devices as listed by the kernel. Corresponding device names are placed in the /dev/input directory, and the name used is the kernel name for the device (%k): KERNEL="mouse*", NAME="input/%k" You can use more then one key in a rule. The following rule uses both a BUS key and a KERNEL key to set up device files for USB printers, whose kernel names will be used to create device files in /dev/usb: BUS="usb", KERNEL="lp[0-9]*", NAME="usb/%k"
Symbolic Links Symbolic links are created by udev using the SYMLINK field. The symbolic links for a device can be listed either with the same rule creating a device file or in a separate rule that will specify only a symbolic link. Rules that specify a symbolic link only will have just a SYMLINK field with no NAME field. In this case the symbolic link is kept on a list awaiting the creation of its device. This allows you to add other symbolic links for a device in other rules files. For example, you could create your own rules file with symbolic links for devices. Such a file would have rules that used just SYMLINK fields for devices. Rules with NAME fields would be still be handled by the original udev rule files like 50-rules.udev. YOUR FEEDBACK
LATEST LINUX STORIES
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||