Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is depmod necessary for building and working with kernel modules?

Tags:

linux

kernel

From what I read, the purpose of depmod is to track dependencies for each kernel module for when it gets loaded. Why can't this be simply determined automatically when the kernel module is loaded, similar to dynamically loading a userspace shared library?

like image 818
zer0stimulus Avatar asked Jan 02 '12 03:01

zer0stimulus


People also ask

What is Depmod used for?

The depmod (Dependency Modules) command is used to generate a list of dependency description of kernel modules and its associated map files. This analyzes the kernel modules in the directory /lib/modules/kernel-release and creates a “Makefile”-like dependency file named modules.

Why do we need kernel modules?

Using modules can save memory, because they are loaded only when the system is actually using them. All parts of the base kernel stay loaded, in real storage, not just virtual storage. Modules are much faster to maintain and debug.

What is a Linux kernel module and how do you load a new module?

A kernel module is a program which can loaded into or unloaded from the kernel upon demand, without necessarily recompiling it (the kernel) or rebooting the system, and is intended to enhance the functionality of the kernel.


1 Answers

depmod does more than just compute direct dependencies - it also builds a mapping between hardware identifiers and the modules that handle them. This is used to find the correct module to load for a detected piece of hardware.

As for why it doesn't do demand loading like userspace does, part of this is because the kernel linker is not allowed to access the filesystem, by design. The philosophy in the kernel is the layout of the filesystem is completely up to userspace, and so there's no guarantee that foo.ko will be found in /lib/modules/3.0.1/drivers/somesubsys/foo.ko. As such, the kernel relies on userspace utilities (like depmod and modprobe) to pass it the raw data for its modules, in the order it needs to load them; if userspace fails in this job, it simply returns an error, and lets userspace deal with the mess.

like image 83
bdonlan Avatar answered Oct 27 '22 07:10

bdonlan