06-B.5.2: Kernel Module Management - modprobe/depmod Command
- Page ID
- 32784
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)
( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\id}{\mathrm{id}}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\kernel}{\mathrm{null}\,}\)
\( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\)
\( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\)
\( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)
\( \newcommand{\vectorA}[1]{\vec{#1}} % arrow\)
\( \newcommand{\vectorAt}[1]{\vec{\text{#1}}} % arrow\)
\( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vectorC}[1]{\textbf{#1}} \)
\( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)
\( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)
\( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\(\newcommand{\avec}{\mathbf a}\) \(\newcommand{\bvec}{\mathbf b}\) \(\newcommand{\cvec}{\mathbf c}\) \(\newcommand{\dvec}{\mathbf d}\) \(\newcommand{\dtil}{\widetilde{\mathbf d}}\) \(\newcommand{\evec}{\mathbf e}\) \(\newcommand{\fvec}{\mathbf f}\) \(\newcommand{\nvec}{\mathbf n}\) \(\newcommand{\pvec}{\mathbf p}\) \(\newcommand{\qvec}{\mathbf q}\) \(\newcommand{\svec}{\mathbf s}\) \(\newcommand{\tvec}{\mathbf t}\) \(\newcommand{\uvec}{\mathbf u}\) \(\newcommand{\vvec}{\mathbf v}\) \(\newcommand{\wvec}{\mathbf w}\) \(\newcommand{\xvec}{\mathbf x}\) \(\newcommand{\yvec}{\mathbf y}\) \(\newcommand{\zvec}{\mathbf z}\) \(\newcommand{\rvec}{\mathbf r}\) \(\newcommand{\mvec}{\mathbf m}\) \(\newcommand{\zerovec}{\mathbf 0}\) \(\newcommand{\onevec}{\mathbf 1}\) \(\newcommand{\real}{\mathbb R}\) \(\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}\) \(\newcommand{\laspan}[1]{\text{Span}\{#1\}}\) \(\newcommand{\bcal}{\cal B}\) \(\newcommand{\ccal}{\cal C}\) \(\newcommand{\scal}{\cal S}\) \(\newcommand{\wcal}{\cal W}\) \(\newcommand{\ecal}{\cal E}\) \(\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}\) \(\newcommand{\gray}[1]{\color{gray}{#1}}\) \(\newcommand{\lgray}[1]{\color{lightgray}{#1}}\) \(\newcommand{\rank}{\operatorname{rank}}\) \(\newcommand{\row}{\text{Row}}\) \(\newcommand{\col}{\text{Col}}\) \(\renewcommand{\row}{\text{Row}}\) \(\newcommand{\nul}{\text{Nul}}\) \(\newcommand{\var}{\text{Var}}\) \(\newcommand{\corr}{\text{corr}}\) \(\newcommand{\len}[1]{\left|#1\right|}\) \(\newcommand{\bbar}{\overline{\bvec}}\) \(\newcommand{\bhat}{\widehat{\bvec}}\) \(\newcommand{\bperp}{\bvec^\perp}\) \(\newcommand{\xhat}{\widehat{\xvec}}\) \(\newcommand{\vhat}{\widehat{\vvec}}\) \(\newcommand{\uhat}{\widehat{\uvec}}\) \(\newcommand{\what}{\widehat{\wvec}}\) \(\newcommand{\Sighat}{\widehat{\Sigma}}\) \(\newcommand{\lt}{<}\) \(\newcommand{\gt}{>}\) \(\newcommand{\amp}{&}\) \(\definecolor{fillinmathshade}{gray}{0.9}\)The modprobe Command
The modprobe command offers more features than the more basic insmod and rmmod utilities. modprobe intelligently adds or removes a module from the Linux kernel. Note that for convenience, there is no difference between _ and - in module names (automatic underscore conversion is performed). modprobe looks in the module directory /lib/modules/`uname -r` for all the modules and other files, except for the optional configuration files in the /etc/modprobe.d directory (some distributions use the /etc/modprobe.conf file instead).
Syntax:
modprobe [ OPTIONS ] [modulename] [module parameters...]
Command Options:
Options | Option Meaning |
---|---|
-f --force | Tries to strip any versioning information from the module which might otherwise stop it from loading. |
-n, --dry-run, --show | This option does everything but actually insert or delete the modules (or run the install or remove commands). Combined with -v, it is useful for debugging problems. |
-s --syslog | This option causes any error messages to go through the syslog mechanism (as LOG_DAEMON with level LOG_NOTICE) rather than to standard error. |
-v, --verbose | Prints messages about what the program is doing. Usually modprobe only prints messages if something goes wrong. |
-r | This option causes modprobe to remove rather than insert a module. |
With modprobe, you specify a module by its module name rather than the module filename. You can pass a few options to modify modprobe’s behavior. For example, to perform checks and all other operations except the actual module insertions, you can use the -n option. Combined with the -v (verbose) option, this option is useful for debugging problems. The --show-depends option will list ALL the modules that are dependent upon the specified module.
pbmac@pbmac-server $ modprobe --show-depends anubis
insmod /lib/modules/4.15.0-91-generic/kernel/crypto/anubis.ko
pbmac@pbmac-server $ modprobe anubis
pbmac@pbmac-server $
The depmod Command
The 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.
Syntax:
depmod [ OPTIONS ]
Command Options:
Options | Option Meaning |
---|---|
-a --all | Probes 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. |
-b basedir --basedir basedir | If your modules are not currently in the (normal) directory /lib/modules/version, but in a staging area, you can specify a basedir which 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. |
-C --config file or directory | This option overrides the default configuration file at /etc/depmod.conf (or the /etc/depmod.d/ directory if that is not found). |
-e --errsyms | When combined with the -F option, this reports any symbols which a module needs which 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). |
-F --filesyms System.map | Supplied with the System.map produced when the kernel was built, this allows the -e option to report unresolved symbols. |
-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. |
By default depmod looks for the .ko files in /lib/modules/$(uname -r), which is why in the following example a symbolic link is created. Once that file can be found the depmod will perform its work, then if necessary run the modprobe command to install the module.
pbmac@pbmac-server $ ln -s /lib/modules/4.15.0-91-generic/kernel/crypto/md4.ko /lib/modules/4.15.0-91-generic/
pbmac@pbmac-server $ depmod -a
pbmac@pbmac-server $ modprobe md4
Linux Kernel Symbols
Kernel symbols are names of functions and variables. Global symbols are those which are available outside the file they are declared in. Global symbols in the Linux kernel currently running on a system are available through `/proc/kallsyms` file. This includes symbols defined inside kernel modules currently loaded.
Global symbols are of two types: those explicitly exported through EXPORT_SYMBOL_GPL and EXPORT_SYMBOL macros, and those which are not declared with `static` C keyword, and hence visible to code which is statically linked with the kernel itself and may be available outside the kernel image.
The first type, explicitly exported ones, are denoted with a capital letter in output of `cat /proc/kallsyms` – e.g., T if the symbol is in text section, i.e. a function name. The second type are denoted with a lowercase letter – e.g., t for a function which isn’t exported via EXPORT_SYMBOL_GPL or EXPORT_SYMBOL.
Adapted from:
"depmod command in Linux with examples" by Merlyn Shelley, Geeks for Geeks is licensed under CC BY-SA 4.0