|
Table of Contents
Linux Udev PresentationThis is the full text of a presentation prepared for the August meeting of the San Antonio Linux Users Group. For more information about satlug go to www.satlug.org. Please feel free to download the actual openoffice presentation here. Note: I still need to upload the last section of this page, sorry it has taken so long. :) History of devices in Unix and LinuxThe basic design of the Unix system is that everything should look like a file. Any program that needs to send or receive information to a device can open it, read from it (or write to it), and close it using the simple programming interfaces available for all files.
Traditionally, almost all devices attached to a Unix-type system are available under the But, how do they get there? Device nodes
The traditional Unix way of creating device nodes in [neptune ~]$ ls -l /dev/hd* brw-rw---- 1 root disk 3, 0 2005-07-14 13:58 /dev/hda brw-rw---- 1 root disk 3, 1 2005-07-14 13:58 /dev/hda1 brw-rw---- 1 root disk 3, 2 2005-07-14 13:58 /dev/hda2 brw-rw---- 1 root disk 3, 3 2005-07-14 13:58 /dev/hda3 brw-rw---- 1 root disk 3, 5 2005-07-14 13:58 /dev/hda5 brw-rw---- 1 root disk 3, 6 2005-07-14 13:58 /dev/hda6 brw-rw---- 1 root disk 3, 64 2005-07-14 17:02 /dev/hdb brw-rw---- 1 root disk 3, 65 2005-07-14 17:02 /dev/hdb1 brw-rw---- 1 root optical 22, 0 2005-07-14 17:02 /dev/hdc Creating device nodes
Tradtionally, the way to create a device node in [neptune ~]$ mknod --help Usage: mknod [OPTION]... NAME TYPE [MAJOR MINOR] Of course, you had to know what type of device you had (block, character, special, FIFO) and the major and minor numbers for the device. You also had to set up the permissions for the device node after creating it. Problems with the tried and true
The old way was not very flexible, from a user's standpoint. It was designed to be set up once and then never changed. Typically, all device nodes possible were set up in Devices could not be created “on-the fly” when new hardware was attached to the system. Plug and play devices like USB devices weren't handled well, if at all.
Running out of subdevices, terminal lines for example, was a problem. If you had only allocated a certain number of terminal entries in Kernel-space device management: devfs
The first device manager for linux was devfs. Devfs is a file system (like ext3 or reiserfs) that could create and manage device nodes. It had to be mounted at Devfs allowed for automatic loading of kernel modules whenever a device node was accessed. Devfs seemed to be a good answer to the problems, but it wasn't quite as flexible as the users wanted it to be. Some problems with devfs
Some of the problems of the non-managed The feature of devfs to autoload a module when the device node was accessed turned out to cause problems with some modules when a device node was accessed without having a device attached to it. The most important problem was that since devfs was part of the kernel, adding new device information was only possible by the kernel maintainers. The only way for users to get new devices added to their devfs system was by upgrading their kernel! User-Space Device Manager: udevAnd now, udev to the rescue!
udev is a user-mode daemon that has special permission by the kernel to work in the
Since udev is only resonsible for maintenance of the Since udev is maintained outside of the kernel tree, updates to udev can be made rapidly, allowing new devices to be recognized much sooner than by waiting to upgrade the kernel. The Benefits of Using udev
Migrating from a devfs to a udev SystemPrerequisites
Using udev requires that your kernel and your distribution support udev, hotplug, and the Building a udev-enabled kernel is quite simple. The only kernel option that you must enable is CONFIG_HOTPLUG. Once you are sure that udev is working properly, you can disable devfs support in your kernel permanently. If devfs is compiled into your kernel, devfs will be used unless you pass a boot-time kernel parameter to disable devfs. Booting a udev KernelCheck to make sure that your kernel supports hotplug[neptune ~]$ cat /proc/config.gz | gunzip | grep -i "CONFIG_HOTPLUG" CONFIG_HOTPLUG=y CONFIG_HOTPLUG_PCI_PCIE=m # CONFIG_HOTPLUG_PCI_PCIE_POLL_EVENT_MODE is not set CONFIG_HOTPLUG_PCI=m CONFIG_HOTPLUG_PCI_FAKE=m CONFIG_HOTPLUG_PCI_COMPAQ=m # CONFIG_HOTPLUG_PCI_COMPAQ_NVRAM is not set CONFIG_HOTPLUG_PCI_IBM=m CONFIG_HOTPLUG_PCI_ACPI=m CONFIG_HOTPLUG_PCI_ACPI_IBM=m CONFIG_HOTPLUG_PCI_CPCI=y CONFIG_HOTPLUG_PCI_CPCI_ZT5550=m CONFIG_HOTPLUG_PCI_CPCI_GENERIC=m CONFIG_HOTPLUG_PCI_SHPC=m # CONFIG_HOTPLUG_PCI_SHPC_POLL_EVENT_MODE is not set Check to make sure you mount ''/sys'' as a sysfs filesystem
NOTE: Some distributions mount [neptune ~]$ mount | grep /sys none on /sys type sysfs (rw)
If you do not have
If your distribution doesn't automatically mount sysfs /sys sysfs defaults 0 0 Check to make sure hotplug is installed[neptune ~]$ ls /sbin/hotplug /sbin/udevd /sbin/hotplug
If hotplug and udev are not installed, you can probably use your package management tools to install them (yum on Fedora, apt-get on debian, emerge on gentoo, pacman on arch, etc…). If not, you can download hotplug and udev at http://www.us.kernel.org/pub/linux/utils/kernel/hotplug/ and install them using the standard ” Check to make sure that your fstab file is good
One of the changes using devfs was that the way the disk drives were labelled changed. The old naming scheme was the familiar
Udev reverts to the original naming scheme (thankfully), but a lot of distributions have configured udev to allow allow both devfs and udev names. If you try to boot using udev and you cannot mount your partitions properly, or if you want to use a udev-only system, you will need to modify your # devfs naming scheme /dev/discs/disc0/part1 /boot ext3 sync,noatime 0 0 /dev/discs/disc0/part2 swap swap defaults,noatime 0 0 /dev/discs/disc0/part5 / reiserfs defaults,noatime 0 0 # udev naming scheme /dev/hda1 /boot ext3 sync,noatime 0 0 /dev/hda2 swap swap defaults,noatime 0 0 /dev/hda5 / reiserfs defaults,noatime 0 0
Some distributions enable devfs in the kernel, but disable the CONFIG_DEVFS_MOUNT option. In that case, Booting the kernel
The only thing left is to tell the kernel not to use devfs. This is done by adding the # a portion of the /boot/grub/grub.conf title Linux 2.6 (using udev) root (hd0,0) kernel /vmlinuz26 root=/dev/hda5 ro vga=773 devfs=nomount single title Linux 2.6 (using devfs) root (hd0,0) kernel /vmlinuz26 root=/dev/hda5 ro vga=773 # a portion of the /etc/lilo.conf file # Linux 2.6 (using udev) image = /boot/vmlinuz26 append = "root=/dev/hda5 ro vga=773 devfs=nomount single" label = linux-devfs # Linux 2.6 (using devfs) image = /boot/vmlinuz26 label = linux-devfs append = "root=/dev/hda5 ro vga=773"
Don't forget to run the NOTE: it is always best to reboot into single user mode when trying out a feature that is likely to break your system if not configured properly. Did it Work?Reboot (into single-user mode the first time!)
Depending on your distribution, you should have some sort of bootup message saying that the udev system is starting. You can verify that udev started by checking to make sure that [neptune ~]$ mount /dev/hda5 on / type reiserfs (rw,noatime) none on /proc type proc (rw) none on /sys type sysfs (rw) none on /dev/pts type devpts (rw) none on /dev/shm type tmpfs (rw) tmpfs on /tmp type tmpfs (rw) /dev/hda1 on /boot type ext3 (rw,sync,noatime) /dev/hda6 on /home type reiserfs (rw,noatime) /dev/hdb1 on /shared type reiserfs (rw,noatime) none on /proc/bus/usb type usbfs (rw) A listing of the files in /dev should also give you a clue. There should only be about 90-100 files and directories in the top-level of /dev. In particular, there will only be enough /dev/hd* or /dev/sd* devices to cover the actual devices that you have attached to your system (or /dev/discs/* if you like that sort of thing). It Worked! What Next?
One minor “gotcha” for a devfs to udev migration is that udev doesn't always create a [neptune ~]$ cd /dev [neptune /dev]$ ln -s input/mice mouse [neptune /dev]$ ls -l mouse lrwxrwxrwx 1 root root 10 2005-07-14 23:30 mouse -> input/mice udev TricksUSB Thumb DriveModifying the Config FilesDid it Work?USB PrinterModifying the Config FilesDid it Work?The Future is Now (Project Utopia)Project UtopiaReal Plug and Play |