From Gentoo Wiki
Jump to: navigation, search
This page contains changes which are not marked for translation.

Other languages:
Deutsch • ‎English • ‎español • ‎français • ‎русский • ‎中文（中国大陆）‎ • ‎日本語 • ‎한국어

Not to be confused with eudev.

udev (user /dev) is systemd's device manager for the Linux kernel. It manages device nodes in /dev and handles all user space actions when adding or removing devices.

What is udev?

The /dev directory

Most Linux users understand that /dev/sda1 is just a fast way of referring to the first partition on the first disk that the kernel found. That's pretty easy, right?

But consider hotpluggable devices like USB, IEEE 1394, hot-swappable PCI, etc. What is the first device for each of these? And for how long? What will the other devices be named when the first one disappears? How will that affect ongoing transactions? Wouldn't it be fun if a printing job were suddenly moved from a high-end laser printer to an almost-dead matrix printer just because someone decided to pull the plug on the laser printer (which just happened to be the first printer)?

Enter the device manager. A modern device manager (including udev and eudev) must:

  • Run in userspace;
  • Dynamically create and remove device files;
  • Provide consistent device naming;
  • Provide a userspace application program interface (API).

Every time a change happens within the device structure, the kernel emits a uevent which gets picked up by the device manager. The device manager then follows the rules declared in the /etc/udev/rules.d, /run/udev/rules.d and /lib/udev/rules.d directories. Based on the information contained within the uevent, it finds the rule or rules it needs to trigger and performs the required actions. These actions may involve the creation or deletion of device files, and may also trigger the loading of particular firmware files into kernel memory.




udev requires the following kernel options:

General setup  --->
        [ ] Enable deprecated sysfs features to support old userspace tools
        [*] Enable signalfd() system call
Enable the block layer  --->
    [*] Block layer SG support v4
Networking support  --->
    Networking options  --->
        <*> Unix domain sockets
Device Drivers  --->
    Generic Driver Options  --->
        ()  path to uevent helper
        [*] Maintain a devtmpfs filesystem to mount at /dev
File systems  --->
    [*] Inotify support for userspace
    Pseudo filesystems --->
        [*] /proc file system support
        [*] sysfs file system support

USE flags


FILE /etc/portage/make.conf


acl Add support for Access Control Lists
static-libs Build static versions of dynamic libraries as well







root #rc-update add udev sysinit

Keep classic 'eth0' naming

Network device names such as eth0 or wlan0 as provided by the kernel are normally changed on system boot (see dmesg) by the /lib/udev/rules.d/80-net-name-slot.rules udev rule.

To keep the classic naming this rule can be overwritten with an equally named empty file in the /etc/udev/rules.d directory:

root #touch /etc/udev/rules.d/80-net-name-slot.rules

Advanced configuration



The rule definitions are stored in two locations:



The event matching is based on information such as:


Based on this information, the rule can then state if:

  2. Links need to be created in /dev
  3. Commands need to be executed


Persistent device names




Some useful commands are:

  • Show all messages about a given device file:
  • Monitor udev activities:
root #udevadm monitor
  • Assign a persistent name to an Ethernet device:
FILE /etc/udev/rules.d/ethernet.rules

See the udevadm man page for more information.


Log monitor messages


FILE /etc/conf.d/udev


Debug mode

Enabling debug mode will output more log messages:

FILE /etc/conf.d/udev

Set the logging priority:

FILE /etc/udev/udev.conf


Missing device files /dev/null and /dev/console


root #mkdir test
root #mount --bind / test
root #cd test/dev
root #mknod -m 660 console c 5 1
root #mknod -m 660 null c 1 3
root #cd ../..
root #umount test
root #rmdir test

NIC assigned eth0, but is moved to eth1


Remember to also remove old files from old versions of udev:

root #rm /etc/udev/rules.d/70-persistent-net.rules /etc/systemd/network/99-default.link

Also make sure not to pass net.ifnames=0 on the kernel commandline. This setting would disable the predictable interface names feature of udev altogether.

See also

External resources
