How to Generate and Rebuild Kernel Module Dependencies in Ubuntu Using depmod

Modern Linux kernels rely on modular device drivers and loadable kernel modules (LKMs) to support hardware peripherals, storage controllers, network protocols, and cryptographic accelerators on demand. Rather than compiling every conceivable driver into the monolithic kernel image, the kernel loads modules into memory when corresponding hardware devices are detected by udev. However, kernel modules rarely operate in isolation: a high-level driver often depends on auxiliary helper modules, bus controllers, or cryptographic symbols. When compiling out-of-tree hardware drivers, installing DKMS packages, or troubleshooting module insertion errors, Ubuntu administrators use depmod to regenerate the kernel dependency map.

Understanding Kernel Module Dependencies and modules.dep

When you invoke modprobe <module-name>, the kernel module loader does not blindly search disk directories. Instead, it reads a pre-compiled index file located at /lib/modules/$(uname -r)/modules.dep (and its optimized binary equivalent modules.dep.bin). This index maps every available kernel object file (.ko or compressed .ko.zst) to its prerequisite dependencies.

The depmod utility scans the entire kernel module tree under /lib/modules/<kernel-version>/, inspects the ELF symbol tables of every compiled module, calculates inter-module symbol references, and writes updated dependency lists and hardware alias tables.

Primary Files Generated by depmod

When depmod runs, it compiles several binary and plain-text database files inside the target kernel’s directory:

  • modules.dep and modules.dep.bin: The primary dependency ledger listing which modules must be loaded prior to a target module.
  • modules.alias and modules.alias.bin: Maps hardware device IDs (such as PCI vendor/device codes and USB product IDs) to the corresponding kernel module.
  • modules.symbols and modules.symbols.bin: Index of exported kernel symbols and the specific modules that supply them.
  • modules.builtin: Lists modules compiled directly into the monolithic kernel image rather than built as separate .ko files.

Generating Dependencies for the Currently Running Kernel

To recalculate and compile dependencies for your active kernel version after building a custom driver or copying a compiled .ko file into /lib/modules/$(uname -r)/updates/, execute depmod with root privileges:

sudo depmod -a

The -a (all) switch instructs depmod to parse all modules declared in configuration files. If executed without arguments, depmod defaults to -a targeting the currently running kernel release.

To inspect the generated plain-text dependency file for verification:

head -n 20 /lib/modules/$(uname -r)/modules.dep

Each entry shows the relative path of a module followed by a colon and a space-separated list of required dependency paths:

kernel/drivers/net/ethernet/intel/e1000e/e1000e.ko.zst: kernel/drivers/ptp/ptp.ko.zst

Targeting Specific or Alternative Kernel Versions

When upgrading kernels, maintaining chroot repair environments, or building custom kernel packages, you frequently need to rebuild dependencies for a kernel release other than the one currently booted.

Pass the explicit kernel version string as an argument:

sudo depmod -a 6.8.0-45-generic

If you are operating on a staging directory or building an image root filesystem mounted under /mnt/sysimage, pass the -b (basedir) parameter:

sudo depmod -b /mnt/sysimage -a 6.8.0-45-generic

This syntax redirects depmod to parse modules under /mnt/sysimage/lib/modules/6.8.0-45-generic/ without modifying the host system’s live kernel tables.

Diagnosing Missing Symbols and Unresolved Dependencies

If a newly installed third-party or DKMS kernel module fails to load with a Unknown symbol in module error in dmesg, depmod can perform static analysis to identify unresolved symbol references.

Run depmod with verbose (-v) and unresolved symbol warning (-e) flags enabled:

sudo depmod -ae -v | grep -i "unresolved"

The tool audits all exported symbols against System.map. If a module requires a kernel function that was disabled in your kernel configuration or renamed across kernel ABI revisions, depmod explicitly reports the missing symbol name and the offending module file.

Dry-Run Inspection Without Modifying Disk Files

To verify module dependencies without writing changes to the live /lib/modules/ directory, use the -n (dry-run) switch:

sudo depmod -n

The command outputs the calculated dependency graph directly to the standard output terminal, allowing systems engineers to audit dependency hierarchies safely during automated build pipelines.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.