Understanding depmod in Linux Kernel Module Maps
The depmod (dependency module) command is a core Linux
maintenance utility responsible for generating and updating module
dependency lists and map files. By scanning compiled kernel modules
located in the /lib/modules/$(uname -r)/ directory,
depmod analyzes their internal symbols to determine which
modules rely on others. It writes these relationships into structured
files—most notably modules.dep—allowing dynamic module
loaders like modprobe to automatically resolve
prerequisites and load device drivers seamlessly.
How depmod Works
Linux kernel modules often do not exist in isolation. Many
specialized drivers depend on core subsystem modules to provide
essential functions and symbols. When depmod is executed,
it reads the Executable and Linkable Format (ELF) headers of every
.ko (kernel object) file in the kernel's module tree.
During this scan, depmod extracts two key pieces of
information:
- Provided symbols: Functions and variables exported
by a module using
EXPORT_SYMBOL. - Required symbols: External functions and variables a module expects to be present in memory.
By matching the unresolved symbols of one module to the exported
symbols of another, depmod creates an accurate dependency
graph across the entire module catalog.
Generated Files and Module Maps
Once depmod parses the modules, it writes several index
and mapping files directly into the active kernel’s module directory.
The primary files include:
modules.depandmodules.dep.bin: Plain text and binary representations of the full dependency graph. Each line lists a module followed by all other modules required for it to run.modules.aliasandmodules.alias.bin: Maps generic device identifiers (like PCI IDs or USB vendor/product IDs) to specific module names.modules.symbolsandmodules.symbols.bin: Maps exported kernel symbols to the specific module that provides them.modules.devname: Records static device nodes provided by modules for systems usingsystemd-udevd.
The binary (.bin) versions are optimized indexes
designed to speed up lookups during boot or device hotplugging.
The Role of depmod in Module Loading
The output of depmod is essential for the
modprobe utility. When a user or system event requests a
module via modprobe <module_name>, the utility does
not inspect raw binaries to discover dependencies. Instead, it reads
modules.dep.bin.
If Module B requires Module A,
modprobe consults the map generated by depmod,
loads Module A first, and then loads Module B.
Without an accurate, updated dependency map, modprobe
cannot identify prerequisite modules, causing module insertion to fail
with unresolved symbol errors.
Common Usage and Triggers
depmod is typically executed automatically during kernel
package installations, system boots, or hardware configuration changes
handled by package managers. However, manual execution is necessary when
compiling out-of-tree drivers, installing third-party kernel modules, or
testing custom modules.
depmod -a: Scans all modules for the current kernel and rebuilds the dependency maps completely.depmod -a <kernel-version>: Updates the module map files for a specified, non-running kernel version (commonly used during kernel compilation and packaging).depmod -n: Performs a dry run, outputting the resultingmodules.depfile to standard output without altering existing files on the disk.