7

Let's take a scenario where a Linux system has booted and is running correctly. A user comes along and hotplugs a USB memory device.

The sequence of events that happen are illustrated on the diagram below:

enter image description here

Where does modprobe load its driver into ? Is the driver for the requested device found in /sys/bus/drivers after modprobe loads it or before ?

What I'm trying to establish here is the relationship between entries in /sys/ and the events that happen on the graph above.

6

The uevent message contains information about the device (example). This information contains registered vendor and model identification for devices connected to buses such as PCI and USB. Udev parses these events and constructs a fixed-form module name which it passes to modprobe. modprobe looks under /lib/modules/VERSION for a file called depmod.alias which is generated when the kernel is installed and that maps the fixed-form module names to actual driver module file names. See Are driver modules loaded and unloaded automatically? for more details about the process — that answer describes the earlier days when the kernel called modprobe directly, but the way modprobe and module aliases work hasn't changed.

See also Michael Opdenacker's presentation “Hotplugging with udev” which has more examples and describes other aspects of device management with udev, and the Linux from scratch guide which has a section on how the fixed-form module names are defined.

modprobe loads a module by calling the init_module system call. It doesn't interact with sysfs in any way. When the module is loaded, the kernel creates an entry for it in /sys/module. Any entry that appears elsewhere in sysfs is up to the code in the module (e.g. a module with a driver for a type of USB devices will call some generic USB support code that adds an entry under /sys/bus/usb/drivers).

  • Thank you for the answer but it doesn't answer my original question. Prior to asking it I have indeed looked at Michaels presentation and other links that you provided. I have also read Patricks Mochels paper about sysfs. I must have either missed something or it wasn't described in any of the sources that I went through so far. When modprobe dynamically loads kernel module does that module (driver) then appear at /sys/bus/drivers directory ? Also does modprobe communicate back with the kernel through netlink socket ? Does it communicate back to sysfs ? – Shady Programmer Dec 14 '16 at 11:42
  • 2
    The questions in your comment are not what you asked in your initial question! But I edited my answer to address them anyway. No, modprobe doesn't communicate through netlink or sysfs (both features are younger than module loading), it calls the init_module system call. – Gilles Dec 14 '16 at 13:11
  • Thank you it's all clear now! Also - yes I've chanced another two related questions in my previous comment on top of the original one cause you seemed to be quite knowledgeable so thank you for answering them as well. Now that my question is answered I'll be able to sleep peacefully, for another day at least ... – Shady Programmer Dec 14 '16 at 14:26

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.