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:

  1. Provided symbols: Functions and variables exported by a module using EXPORT_SYMBOL.
  2. 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:

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.