Skip to main content
Engineering LibreTexts

06-B.5.2: Kernel Module Management - modprobe/depmod Command

  • Page ID
  • \( \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}}\)

    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).


    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.


    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 Supplied with the 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

    06-B.5.2: Kernel Module Management - modprobe/depmod Command is shared under a CC BY-SA 4.0 license and was authored, remixed, and/or curated by LibreTexts.

    • Was this article helpful?