LinuxCommandLibrary

modprobe

Add or remove kernel modules

TLDR

Pretend to load a module into the kernel, but don't actually do it

$ sudo modprobe [[-n|--dry-run]] [module_name]
copy

Load a module into the kernel
$ sudo modprobe [module_name]
copy

Remove a module from the kernel
$ sudo modprobe [[-r|--remove]] [module_name]
copy

Remove a module and those that depend on it from the kernel
$ sudo modprobe --remove-dependencies [module_name]
copy

Show a kernel module's dependencies
$ sudo modprobe [[-D|--show-depends]] [module_name]
copy

SYNOPSIS

modprobe [options] modulename
modprobe [options] -r modulename

PARAMETERS

-r, --remove
    Remove a module. modprobe will also remove dependent modules if they are no longer in use.

-v, --verbose
    Print messages about the actions being taken, useful for debugging.

-f, --force
    Force loading or unloading, ignoring version mismatches or if a module is in use. Use with extreme caution as it can destabilize the system.

-n, --dry-run
    Don't actually insert or remove the module, just print what would happen.

-D, --show-depends
    Show the dependencies of a module without actually loading it.

-a, --all
    Load all modules matching the module name specified. Useful for loading multiple aliases.

DESCRIPTION

modprobe is a Linux command-line utility used for intelligently adding and removing modules from the Linux kernel. Unlike the lower-level insmod and rmmod commands, modprobe understands module dependencies. When asked to load a module, it automatically loads all necessary prerequisite modules first. Similarly, when removing a module, it ensures that dependent modules are also unloaded if they are no longer in use by other parts of the system.

modprobe consults configuration files located in /etc/modprobe.d/ and the module dependency database generated by depmod (typically in /lib/modules/<kernel-version>/modules.dep.bin). This intelligent dependency resolution makes modprobe the preferred tool for managing kernel modules, simplifying the process for administrators and scripts. Additionally, it supports module blacklisting, aliasing, and passing kernel module parameters, offering a comprehensive solution for dynamic kernel configuration.

CAVEATS

  • Requires root privileges to execute.
  • Using --force can lead to system instability or crashes.
  • Relies on an up-to-date module dependency file (generated by depmod); outdated files can cause incorrect behavior.
  • Module changes made by modprobe are typically not persistent across reboots unless configured via system-level configuration files.

CONFIGURATION FILES

modprobe utilizes configuration files located primarily in /etc/modprobe.d/ (and /lib/modprobe.d/). These files allow administrators to define module aliases, specify options to be passed to modules at load time, blacklist modules to prevent them from loading, and set up pre/post-install/remove commands. This mechanism provides granular control over module behavior and system-wide module policies.

MODULE SEARCH PATH AND DATABASE

By default, modprobe searches for modules within /lib/modules/$(uname -r)/kernel/, corresponding to the currently running kernel version. It heavily relies on the modules.dep.bin file, which is a binary representation of module dependencies generated by depmod, to intelligently resolve and load all necessary modules in the correct order.

HISTORY

modprobe is part of the kmod tools suite, which succeeded the older module-init-tools package. It has evolved to provide more robust and secure kernel module management, particularly in handling dependencies and aliases. Its design aims to automate and simplify the complex task of dynamically configuring the Linux kernel through module loading and unloading, integrating seamlessly with modern Linux distributions.

SEE ALSO

lsmod(8), rmmod(8), insmod(8), depmod(8), modinfo(8)

Copied to clipboard