Open In App

depmod command in Linux with examples

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.dep based on the symbols present in the set of modules. These modules are generally taken from the directories specified in the configuration file or mentioned on the command line. Then when the stack of modules are added and removed automatically with modprobe, no modules are without the other related modules they require. Simultaneously, it creates an associated map correlating the hardware identifiers and the corresponding modules that handle them for the purpose of use by the hotplug infrastructure. This specifically associated mapping is used to search for and find the correct module when a unit of hardware requests it. 

The Linux kernel relies on depmod and modprobe to send the raw facts of data for its modules, in the proper order to load them. The depmod and modprobe command utilities facilitate a Linux modular kernel manageable for all end users, distribution maintenance engineers, network and system administrators. 


Syntax: 

depmod [ -a ] [ -b basedir ] [ -e ] [ -F System.map ] [ -n ] [ -v ] [ version ] [ -A ]
       [-n] [-v] [-A] [-P prefix] [-w] [version]

depmod [-e] [-E Module.symvers] [-F System.map] [-m] [-n] [-v] [-P prefix]
       [-w] [version] [filename...]
*** QuickLaTeX cannot compile formula:
 

*** Error message:
Error: Nothing to show, formula is empty



Linux kernel modules would provide unique services called “symbols” for other modules to make use of its utilities. This could be done by using one of the EXPORT_SYMBOL variants in the code. Eventually when a second module uses this symbol, then the second module solely depends on the attributes and functions of the first module. These modular dependencies tend to look complex. 
The main objective of the depmod command is to creates a list of module dependencies by revoking each module under /lib/modules/kernel-release and finds what export symbols are used to quantify its needs. By default, this list is written to modules.dep, and also made available in binary hashed version named modules.dep.bin, in the same specific directory. 

 




Options: 





Example: The following is a series of commands that helps to illustrate a usual way to use depmod command in Linux. Each command is prefixed with sudo since each of them requires proper root permissions: 

Retrieving file from default location: 



 ln -s /path/to/your-kernel-module.ko /lib/modules/`uname -r`
/sbin/depmod -a
 modprobe your-kernel-module



Loading and Unloading a File from location other than default location: 

$ ln -s lkm.ko /lib/modules/2.6.32-21-generic/
$  depmod -a
$ modprobe lkm
$  modprobe -r lkm
lkm here refers to located or kept at any part of the memory.


Operations Explained line by line:  

$ln -s /path/to/your-kernel-module.ko /lib/modules/`uname -r`


ln is used 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. 

Note: $depmod -a is 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. 
 

Article Tags :