You plug your back-up hard disk ' in! After a few seconds, you get a notification "Back-up is complete." You then unplug the hard drive and your: back-up for the day is ready with you. Now imagine this: you plug your EVDO/CDMA Internet data card in, and within a few seconds you get a notification: "Internet connected." When the device is unplugged, you get a message stating the Net is disconnected. Can you ever think of such a user experience under GNUlLinux?
Of course you can! udev helps you achieve this and a lot more. Let's tune into what's so great about udev!
What is udev? udev is a device manager for Linux that runs in user space. It deals with device node creation, while taking care of the persistent naming of devices upon the availability of real hardware. By the UNIX concept, everything is a file. We access our devices via corresponding files in the /dev directory. As you know, /dev is a directory containing device nodes for all standard devices. Traditional UNIX systems had static device nodes under the /dev directory. What happens when you plug your MP3 player in the USB port?
You might have noticed that it is /dev/ sdal, or some other node, through which you access the contents of the filesystem. /dev/sdal is a device node corresponding to that device. This kind of static device node system worked fine, since there were a limited number of devices in earlier times. The existence of these device nodes was independent of actual devices connected to the hardware.
It was a real hassle to decide whether a piece of hardware existed or not, since all possible device nodes existed. Now, as the number of Linux-supported devices increased, especially USB removable devices and IEEE 1394 (Firewire ports), the number of static nodes required under /dev increased to a huge number-nearly l8,OOO-and it became unmanageable. Also, if some device nodes that corresponded to a connected device did not exist under /dev, you had to Google for the major and minor number for the device, and create the device node manually, using the mknod command. Since each device has its unique major and minor numbers, this was a pretty tough situation!
As a result, a pseudo RAM-based file system sysjs, mounted under /sys, was introduced. Users now could check whether a device existed or not, by looking into the directory tree of devices under /sys. Still, this wasn't a satisfactory solution, since either of the devices were statically built, or we had to create the device nodes manually, using major and minor numbers for the corresponding device.
Give the following tree command a try:
Since our area of interest is making life easier with udev, let's move on to hacking udev. udev runs in the memory all the time as a daemon and listens to kernel messages. The kernel always sends a messagelwhenever it notices a hardware change. You can observe it by running the dmesg command. The following is the dmesg output when I connect an external hard disk:
So, let's take a look at the duties of udev:
• Listen to kernel messages. If some device is connected, create its device nodes according to the order in which it is connected. udev has the ability to identify each
of the devices uniquely. Device nodes are created only when the device is connected.
• Removal of device nodes when the device is unplugged.
• Create symlinks for device nodes, and execute commands upon udev events.
• Follow the udev rules. The udev daemon is controlled by a set of user-specified rules.
Consider the following scenario, with which I'll try to elaborate the usefulness of udev. Let's suppose you have two printers-one an inkjet and the other a laser colour printer. Usually, the one that is connected first is designated as /dev/lpO and the second one /dev/lpl. How do you understand which one is laser and which one is inkjet? Is it by looking at which one is switched on first?
udev is brilliant in solving such nonsense. What if you are able to get /dev/laser for the laser printer and /dev/ ink jet for the inkjet printer. udev can identify each of the ink jet for the inkjet printer. udev can identify each of the devices uniquely by specifying certain parameters through udev rules.




Reply With Quote
Copyright Techfuels
Bookmarks