3

What is a device manager in the context of Linux?  That is, what is it that a device manager actually does?

https://en.wikipedia.org/wiki/Udev says

udev (userspace /dev) is a device manager for the Linux kernel.

What does that mean?

Wikipedia continues:

As the successor of devfsd and hotplug, udev primarily manages device nodes in the /dev directory.  At the same time, udev also handles all user space events raised when hardware devices are added into the system or removed from it, including firmware loading as required by certain devices.

This sentence doesn't make any sense to me.  Firstly, what does "manages device nodes in the /dev directory" mean?

slebetman said:

It's a piece of software that automatically enable or disable device drivers.  The "automatic" part is usually done by detecting that a new device has been attached to the machine.  In addition to activating device drivers, it also automatically configures the device (for example, it automatically mounts a USB drive when it detects it, instead of you needing to open a disk manager or run a command to mount the drive).

"automatically enable or disable device drivers" for what purpose?  so the kernel can talk to the devices or the program?  so the devices can operate in user space or kernel space?

6
  • 3
    The next sentence on the page that you link to reads "As the successor of devfsd and hotplug, udev primarily manages device nodes in the /dev directory. At the same time, udev also handles all user space events raised when hardware devices are added into the system or removed from it, including firmware loading as required by certain devices." Does that not explain it?
    – Kusalananda
    Feb 8 at 9:09
  • > "As the successor of devfsd and hotplug, udev primarily manages device nodes in the /dev directory. At the same time, udev also handles all user space events raised when hardware devices are added into the system or removed from it, including firmware loading as required by certain devices." this sentence doesn't make any sense to me, firstly what does it mean "manages device nodes in the /dev directory"? Feb 8 at 11:57
  • It's a piece of software that automatically enable or disable device drivers. The "automatic" part is usually done by detecting that a new device has been attached to the machine. In addition to activating device drivers it also automatically configures the device (for example, it automatically mounts a USB drive when it detects it instead of you needing to open a disk manager or run a command to mount the drive)
    – slebetman
    Feb 8 at 18:29
  • > "automatically enable or disable device drivers" for what purpose? so the kernel can talk to the devices or the program? so the devices can operate in user space or kernel space? Feb 8 at 18:35
  • 1
    Please note there isn't a slot called "device manager" that is designed to fit something like udev. Rather, something like udev was invented, and then we called it "device manager" because it manages devices. Feb 8 at 23:50

1 Answer 1

10

Udev handles the setup of all newly detected devices (including both "hot-plugged" devices after the system has booted as well as permanently connected "cold-plugged" devices while the system is booting):

  • It will load kernel modules (drivers) on demand, whenever the kernel informs it of a newly detected device.

  • It will update device nodes in /dev for those devices: it sets their ownership, groups, permissions; it also creates symlinks such as /dev/disk/by-uuid.

    In the past, udev also used to create all of the device nodes in /dev (using 'mknod'), as well as remove them when a device was disconnected. That's no longer necessary in current Linux – instead the kernel has "devtmpfs" where devices will spring into existence automatically – but udev still takes care of changing permissions and creating symlinks.

  • It will process custom rules, which may e.g. run helper programs to initialize the device (such as remapping keyboard scancodes, or uploading firmware into a printer, or just poking at /sys knobs), or which may augment the device's metadata for userspace programs (e.g. touchpad dimensions for libinput; see also systemd-hwdb).

The general process is:

  1. The kernel detects a device (e.g. a low level "USB device VID:PID" on the USB bus) and emits an uevent via Netlink.

  2. Udev processes all rules found in /{etc,lib,usr/lib}/udev/rules.d/. Module loading is a special rule found there, as is practically everything else that udev does.

  3. Udev emits an augmented uevent via Netlink for userspace to react to.

    Most programs deliberately ignore the initial kernel event but wait for the augmented event from udev; that way they'll only start using the device after its rules have finished doing what they need to do.

Udev isn't strictly mandatory – you could have a kernel that has all necessary drivers either compiled in or manually loaded using modprobe, and most things would work. (As long as the driver is loaded, it'll automatically get attached to recognized devices – that's not handled by udev.)

What wouldn't work is software that relies on udev to announce newly detected devices or to provide the additional metadata, e.g. X11 wouldn't notice when you plugged in a new display or mouse.

2
  • Efficient answer indeed. I would have first answered to "what is…" by : An hardware abstraction layer. since that is what was at first needed as a replacement for hal
    – MC68020
    Feb 13 at 17:11
  • @MC68020: It's not really a replacement – it came into existence a few months earlier than hal did, and hal still relied on udev for the hotplug events and other things. So it's more like that hal's functionality got absorbed into udev... Feb 13 at 17:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .