Connect your devices with udev

From LXF Wiki

Revision as of 18:33, 30 Jan 2009; view current revision
←Older revision | Newer revision→

DEVICE-NAMING SYSTEM: Connect your devices with udev

(Original version written by Neil Bothwick for LXF issue 66.)

Learn how to code a name for your hardware when 'Bob' just won't do.

'Everything is a file' is one of the Unix creeds. It sounds strange at first, but in a way it's true. Of course, we're not suggesting that your hard disk is a file—we all know it's a precision-engineered piece of electromechanical hardware designed to store as much of your valuable data as possible before crashing the heads into the disk and destroying the lot.

However, your hard disk is represented as a file in the Linux filesystem, usually as /dev/hda/. You probably already know this, but any piece of hardware you connect to your computer is represented by a device file in /dev, be it your MP3 player or your webcam. The /dev directory was originally a standard directory containing device files for every piece of hardware likely to be connected. This usually meant that whenever a driver was installed, the relevant files were created in /dev. This had two really important disadvantages. The first was that as more devices were supported, the number of files in the directory was becoming unmanageable.

It also meant that if you tried to connect a piece of hardware for which there was no device file, you had to create it yourself, first scouring Google for the correct major and minor device number to pass to the mknod command.

As the number of devices supported by Linux increased, especially the huge number of removable devices that could be connected to USB or IEEE1394 (aka Firewire) ports, this became unacceptable. Not only was /dev becoming totally unwieldy, but we were in danger of running out of major and minor device numbers to cover every possible device that could be connected, even though any one computer would only ever see a tiny fraction of them.

The solution was devfs, a system in the Linux kernel that would react to devices being connected or discovered and create their /dev entries automatically. While this improved the situation, there are some issues with devfs that mean its use is now deprecated. The main problem with devfs is that it has a number of bugs, ranging from annoying to serious, some of which cannot be fixed.