Linux depmod command
On Linux operating systems, the depmod command generates a list of kernel module dependences and associated map files.
depmod analyzes your kernel modules (in the directory /lib/modules/kernel-release) and creates a list of dependencies (named modules.dep), so that when modules are added and removed with modprobe, no modules are without the other modules they require. At the same time, it creates a map correlating hardware identifiers and the modules that handle them. This mapping is used to find the correct module when a piece of hardware requests it.
The kernel relies on depmod and modprobe to pass it the raw data for its modules, in the order it needs to load them.
Linux kernel modules can provide services (called "symbols") for other modules to use (using one of the EXPORT_SYMBOL variants in the code). If a second module uses this symbol, that second module clearly depends on the first module. These dependencies can get quite complex.
depmod creates a list of module dependencies by reading each module under /lib/modules/kernel-release and determining what symbols it exports and what symbols it needs. By default, this list is written to modules.dep, and a binary hashed version named modules.dep.bin, in the same directory. If file names are given on the command line, only those modules are examined (which is rarely useful unless all modules are listed).
depmod also creates a list of symbols provided by modules in the file named modules.symbols and its binary hashed version, modules.symbols.bin.
Finally, depmod outputs a file named modules.devname if modules supply special device names (devname) that should be populated in /dev on boot (by a utility such as udev).
If a version is provided, then that kernel version's module directory is used rather than the current kernel version (as returned by uname -r).
depmod [-b basedir] [-e] [-E Module.symvers] [-F System.map] [-n] [-v] [-A] [-P prefix] [-w] [version]
depmod [-e] [-E Module.symvers] [-F System.map] [-m] [-n] [-v] [-P prefix] [-w] [version] [filename...]
|-a, --all||Probe all modules. This option is enabled by default if no file names are given in the command-line.|
|-A, --quick||This option scans to see if any modules are newer than the modules.dep file before any work is done: if not, it silently exits rather than regenerating the files.|
|If your modules are not currently in the (normal) directory /lib/modules/kernel-version, but in a staging area, you can specify a basedir that is prepended to the directory name. This basedir is stripped from the resulting modules.dep file, so it is ready to be moved into the normal location. Use this option if you are a distribution vendor who needs to pre-generate the metadata files rather than running depmod again later.|
|This option overrides the default configuration directory at /etc/depmod.d/.|
|-e, --errsyms||When combined with the -F option, this reports any symbols which a module needs that are not supplied by other modules or the kernel. Normally, any symbols not provided by modules are assumed to be provided by the kernel (which should be true in a perfect world), but this assumption can break especially when additionally updated third-party drivers are not correctly installed or were built incorrectly.|
|-E, --symvers||When combined with the -e option, this reports any symbol versions supplied by modules that do not match with the symbol versions provided by the kernel in its Module.symvers. This option is mutually incompatible with -F.|
|Supplied with the System.map produced when the kernel was built, this allows the -e option to report unresolved symbols. This option is mutually incompatible with -E.|
|-h, --help||Print the help message and exit.|
|-n, --dry-run||This sends the resulting modules.dep and the various map files to standard output rather than writing them into the module directory.|
|-P||Some architectures prefix symbols with extraneous characters. This specifies a prefix character (for example '_') to ignore.|
|-v, --verbose||Verbose mode; depmod prints to standard output all the symbols each module depends on and the module's file name which provides that symbol.|
|-V, --version||Show depmod's version and exit. See below for caveats when run on older kernels.|
|-w||Warn on duplicate dependencies, aliases, symbol versions, etc.|
The following series of commands illustrate a common way to use depmod. Each command is prefixed with sudo, since they require root permissions:
sudo ln -s /path/to/your-kernel-module.ko /lib/modules/`uname -r`
sudo depmod -a
sudo modprobe your-kernel-module
These commands perform the following operations:
- In the first command, we use ln to create a symbolic link to our module file in the directory /lib/modules/kernel-release. The command uname -r, enclosed in back quotes, is executed by the shell and translates to the appropriate string representing our kernel release version.
- In the second command, an updated dependency list is generated by depmod -a to make sure that the module we're installing is aware of all existing modules and dependencies. This dependency list will be used by modprobe when installing the module in the third command.
- modprobe installs the kernel module.
insmod — Insert a module into the Linux kernel.
lsmod — Show the status of Linux kernel modules.
modinfo — Show information about a Linux kernel module.
modprobe — Add and remove modules from the Linux kernel.
rmmod — Remove a module from the Linux kernel.