Udev

From Christoph's Personal Wiki
Jump to: navigation, search
The correct title of this article is udev. The initial letter is capitalized due to technical restrictions.

udev is the device manager for the Linux 2.6 kernel series. Its primary function is managing device nodes in /dev. It is the successor of devfs and hotplug, which means that it handles the /dev directory and all user space actions when adding/removing devices, including firmware load.

The latest versions of udev depends on the latest version of the uevent interface of the Linux kernel which has been updated or introduced with Linux kernel 2.6.13. A system using such a new version of udev will not boot with kernels older than 2.6.13 unless udev is disabled with bootparam noudev and a traditional /dev directory is used for device access.

Overview

Unlike the traditional Linux system, where the device nodes in the /dev directory have been a static set of files, udev dynamically provides only the nodes for the devices actually present on a system. Although devfs provided a similar functionality, advocates for udev cited a number of reasons [1] for preferring its implementation over devfs:

  • udev supports persistent device naming, which does not depend on, for example, the order in which the devices are plugged into the system. The default udev setup provides persistent names for storage devices. Any hard disk is recognized by its unique filesystem id, the name of the disk and the physical location on the hardware it is connected to.
  • udev executes entirely in user space, as opposed to devfs' kernel space. One consequence is that udev moved the naming policy out of the kernel and can run arbitrary programs to compose a name for the device from the device's properties, before the node is created.

Operation

udev is a generic kernel device manager. It runs as a daemon on a Linux system and listens to uevents the kernel sends out (via netlink socket) if a new device is initialized or a device is removed from the system. The system provides a set of rules that match against exported values of the event and properties of the discovered device. A matching rule will possibly name and create a device node and run configured programs to set-up and configure the device. udev rules can match on properties like the kernel subsystem, the kernel device name, the physical location of the device, or properties like the device's serial number. Rules can also request information from external programs to name a device or specify a custom name that will always be the same, regardless of the order devices are discovered by the system.

Architecture

The system is divided in three parts:

  • The library namedev, that handles the names to be assigned to the devices
  • The library libsysfs, that allows access to device information (dropped since version 080)
  • The daemon udevd, in user space, that creates the virtual /dev

The system gets calls from the kernel via netlink socket. Earlier versions used hotplug, adding a link to themselves in /etc/hotplug.d/default with this purpose.

External links