4

So i was just wondering if my explanations of udev and how it works seem correct and my understanding is correct please let me know.

SO my understanding of udev is that it is a dynamic device manager on Linux which runs as a daemon.

  • when a change to a device occurs such as if a device is plugged in the kernel sends a uevent to udev, udev then can go to sysfs to find details on the device such as the vendor, device name and model etc.
  • once it has the details of the device, Udev then matches these attributes to the rules set for a specific kind of device in this case it may be a usb device. if a rule like "create symlink for all usb devices" exists then udev will do this. udev checks the rules and matches the attributes to verify the device and then can start adding changes to the device as well as do whatever the rules say to the device.

That is basically my current understanding please correct me if im wrong and tell me extra info.

  • 1
    What you understood about udev is correct... I answered a summarized explanation about udev and many links to different posts – intika Nov 8 '19 at 2:06
1
+100

UDEV

Udev stand for "userspace /dev" it is a device manager for the Linux kernel. It is part of systemd (an init system used to bootstrap user space and manage user processes).

Originally udev was independent from systemd, it was merged with systemd in 2012, this lead to some complication for distribution running without systemd like explained here for the gentoo distribution.

This application (udev) is meant to replace 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 (via kernel modules). Concretely udev is run as systemd service (systemd-udevd.service) to achieve its tasks, it listens to kernel uevents. For every event, systemd-udevd executes matching instructions specified in udev rules (/etc/udev/rules.d/), details about rules writing are available on this article.

At the Linux kernel level the required device information is exported by the sysfs file system. For every device the kernel has detected and initialized, a directory with the device name is created. It contains attribute files with device-specific properties. Every time a device is added or removed, the kernel sends a uevent to notify udev of the change.

The behavior of the udev daemon (service) can be configured using udev.conf(5) (/etc/udev/udev.conf), its command line options, environment variables, and on the kernel command line, or changed dynamically with udevadm control.

The udev, as a whole, is divided into three parts:

  • Library libudev that allows access to device information.
  • User space daemon (sytemd) udevd that manages the virtual /dev.
  • Administrative command-line utility udevadm for diagnostics.

Udev itself is divided on those three parts but it completely rely on the kernel device management and it's uevents calls, 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.

Note that other application/daemon may listen to uevents calls over libudev, gudev or directly from the kernel with GUdevClient

Further infos on udev are available on the sources of this answer: debian wiki, arch linux wiki, opensource.com, the geek diary, freedesktop.org, wikipedia, pks.mpg.de and other linked sites.

Details about operation layers of udev are explained here and illustrated with this diagram:

enter image description here

-1

Here on reactivated.net/writing_udev_rules I found a good explanation. It is from 2003-2006.

man udev (systemd) is very condensed. And man systemd-udevd.service is short. I think udev has complicated history, being integrated to systemd and forked off as eudev.

And just like with systemd itself, udev is configured on many levels. "Out of the box" (the distro box) it has to "populate" /dev (I understand - because static nodes are obsolete).

I see three main uses for udev:

  1. "persistent" names in /dev/disk/by-... for removable storages, via SYMLINK=
  2. dito net interfaces. via NAME=
  3. Any other device event (keyboard, usb gadgets, ...) that needs (or wants) automation.

Your summary has motivated me to finally find out about udev in detail. Now I see the connection with the sysfs entries (thank you), and I also found the difference between a MATCH== and a ACTION=...


I would offer 100 points to have nicely explained:

What does the kernel (plus modules like usb_storage) do? (Plus /etc/fstab?)

And what does systemd do? What "udev"?


I know I needed libinput in the end to make xorg run.


man udevadm, under udevadm control -e:

systemctl stop systemd-udevd-control.socket systemd-udevd-kernel.socket systemd-udevd.service

Otherwise it restarts. This is the happy end of this "answer" ;)


The only "action" I could produce so far: a line in the log:

'systemd-udevd[22327]: Process '...' failed with exit code 1.

  • are you trying to say i have helped you with my question? lol – Qasim Nov 8 '19 at 11:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.