YOUR FEEDBACK
John Portnov wrote: This code does not work for me. I created a new website and a C# console applic...


2008 East
DIAMOND SPONSOR:
Data Direct
Frontiers in Data Access: The Coming Wave in Data Services
PLATINUM SPONSORS:
Red Hat
The Opening of Virtualization
Intel
Virtualization – Path to Predictive Enterprise
Green Hills
IT Security in a Hostile World
JBoss / freedom oss
Practical SOA Approach
GOLD SPONSORS:
Software AG
The Art & Science of SOA: How Governance Enables Adoption
PlateSpin
Effective Planning for Virtual Infrastructure Growth
Fujitsu
Automated Business Process Discovery & Virtualization Service
Ceedo
Workspace Virtualization
Click For 2007 West
Event Webcasts

2008 East
PLATINUM SPONSORS:
Appcelerator
Think Fast: Accelerate AJAX Development with Appcelerator
GOLD SPONSORS:
DreamFace Interactive
The Ultimate Framework for Creating Personalized Web 2.0 Mashups
ICEsoft
AJAX and Social Computing for the Enterprise
Kaazing
Enterprise Comet: Real–Time, Real–Time, or Real–Time Web 2.0?
Nexaweb
Now Playing: Desktop Apps in the Browser!
Sun
jMaki as an AJAX Mashup Framework
POWER PANELS:
The Business Value
of RIAs
What Lies Beyond AJAX?
KEYNOTES:
Douglas Crockford
Can We Fix the Web?
Anthony Franco
2008: The Year of the RIA
Click For 2007 Event Webcasts
SYS-CON.TV
TOP LINKS YOU MUST CLICK ON


Linux.SYS-CON.com: Device Management with udev and HAL on Fedora Core 4
Hotplugging everything on Fedora Core 4

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!

On Fedora Core 4, device files are no longer handled in a static way. Instead they're now dynamically generated as needed by udev and managed by HAL (Hardware Abstraction Layer). Previously a device file was created for each possible device, leading to a very large number of device files in the /etc/dev directory. Now, your system will detect only those devices it uses and create device files for those only, giving you a much smaller listing of device files. Both udev and HAL are hotplug systems, with udev used for creating devices and HAL designed for providing information about them, as well as managing the configuration for removable devices such as those with file systems like USB card readers and CD-ROMs.

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
Devices are now treated as hotplugged, meaning they can be easily attached and removed. Their configuration is dynamically detected and does not rely on manual administrative settings. The hotplug tool used to detect device files is udev, user devices. Each time your system is booted, udev will automatically detect your devices and generate device files for them in the /etc/dev directory. This means that the /etc/dev directory and its files are re-created each time you boot. It is a dynamic directory, no longer static. udev uses a set of rules to direct how device files are to be generated, including any corresponding symbolic links. These are located in the /etc/udev/rules.d files. As part of the hotplug system, udev will automatically detect kernel devices that are added or removed from the system. When the device interface is first created, its corresponding sysfs file is located and read, determining any additional attributes such as serial numbers and device major and minor numbers that can be used to uniquely identify the device. These can be used as keys in udev rules to create the device interface. Once the device is created, it's listed in the udev database, which keeps track of currently installed devices.

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
udev uses the udev rules.d files to dynamically create your device files. The rules files already present in the rules.d directory have been provided for your Fedora Core distribution and are designed specifically for it. You should never modify these rules. To customize your setup, create your own separate rules files in /etc/udev/rules.d. In your rules file you would normally define only symlinks, using SYMLINK fields alone, as described in the following sections. These set up symbolic links to devices, letting you access them with other device names. NAME fields are used to create the original device interface, a task usually left to udev.

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
Certain device files are really symbolic links bearing common device names that are often linked to the actual device file used. A symbolic link is another name for a file that is used like a shortcut, referencing that file. Common devices such as printer, CD-ROM, hard drive, SCSI, and sound devices, along with many others, will have corresponding symbolic links. For example, a /dev/cdrom symbolic link links to the actual device file used for your CD-ROM.

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.

About Richard Petersen
Richard Petersen holds a M.L.I.S. in Library and Information Studies. He currently teaches Unix and C/C++ courses at the University of California, Berkeley.

YOUR FEEDBACK
LinuxWorld News Desk wrote: LinuxWorld: Device Management with udev and HAL on Fedora Core 4. 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!
LATEST LINUX STORIES
Red Hat CTO Brian Stevens, Citrix CTO Simon Crosby, Egenera CTO Pete Manca, Allen Stewart, Group Manager, Windows Virtualization at Microsoft, and Brian Duckering, Sr. Director of Products and Alliances at Symantec were the top industry executives who joined Jeremy Geelan in the 4th Fl...
IBM introduced a series of new products, services and initiatives that further expand IBM's commitment to Linux and open source by enabling the next generation of Linux. As the company marks ten years of support for Linux, IBM announced a number of cross-company initiatives to driv...
Two of the biggest launches in Rich Internet Application history took place in 2007/2008 when Adobe launched AIR 1.0 in February '08 and Microsoft launched Silverlight (September '07). At the 6th International AJAXWorld RIA Conference & Expo in October SYS-CON Events is delighted to be...
VMware, which seems to be as far from open source as you can get these days, has joined the Linux Foundation, promising to make more contributions to the Linux community. It's cultivating the Linux crowd as adoption of Linux expands as a result of its position as a platform for cloud c...
IBM, Canonical, Novell, Red Hat and the distributions’ hardware partners are ganging up on Microsoft, intending to push a Microsoft-free desktop alternative involving Linux, Lotus Notes and Lotus Symphony. They think they see an auspicious constellation of stars in the sky – like P...
In 2005, Scott McNealy of Sun Microsystems quipped that open source software was 'free like a puppy is free.' Just as you can pick out a puppy from the pound without paying expensive breeder fees, you can download and use open source software without buying a single license. But puppie...
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021


SYS-CON FEATURED WHITEPAPERS

ADS BY GOOGLE