Linux Modprobe Explained: How to Use and Apply Commands with Real-World Scenarios

Introduction to the Linux Modprobe command tutorial

How Linux uses Modprobe commands: The Linux kernel is modular in design. Functionality can be extended via modules or drivers. Use the modprobe command to add or remove modules on Linux. The command works intelligently and automatically adds any dependent modules.

The kernel is used for the modprobe request module. The modprobe command searches the directory of standard-installed modules for the necessary drivers.

This article explains how to add or remove kernel modules using modprobe, including some examples of Linux Modprobe command usage.

Prerequisite

  • A system running Linux
  • Access the terminal/command line
  • A user account with sudo or root privileges

Explanation of modprobe command syntax

All modprobe commands require sudo permissions. The general syntax used modprobe is:

sudo modprobe <options> <module name>

By default, the modprobe command adds a module.

For multiple modules, use option -a or extension-all:

sudo modprobe <options> -a <first module name> <second module name>

modprobe command

How Linux uses Modprobe commands: The available modprobe command options are divided into categories based on their use cases.

Management options

When inserting or removing a module using the command, the management option enables different module handling modprobes.

--all
-a
Allows multiple modules to be inserted or removed at the same time.
--remove
-r
Remove a module. Also applies --remove-dependencies. Used to remove damaged modules.
--remove-dependenciesDelete dependent modules.
--resolve-alias
-R
Find and print all module names that match the alias. Used to debug alias issues.
--first-timeErrors are printed for modules that have been inserted or removed.
--ignore-install
--ignore-remove
-i
Install/remove commands written in modules are ignored when inserting/removing modules.
--use-blacklist
-b
Blacklist resolution aliases. Blacklisted modules are not automatically loaded.
--force
-f
Force insertion or removal of modules when there is a version error. Works with --force-modversion and --force-vermagic. Use with caution.
--force-modversionIgnore module versions when inserting or removing. Use with caution.
--force-vermagicIgnore module version mana when inserting or removing. Use with caution.

Query options

Query options for modprobe to display information about configuration and dependencies.

--show-depends
-D
Lists the modules that have dependent files, if any. Dependencies installed with the module have the “install” prefix.
--showconfig
--show-config
-c
Prints the current configuration and exists.
--show-modversions
--dump-modversions
Dump module version dependencies.

General options

The general options configure the modprobe output options, module location, and version.

--dry-run
--show
-n
Don’t do an insert/delete, print it out. For debugging purposes.
--config=<file name>
-C
Override the default configuration dependencies (/etc/modprobe.d) with <file name>.
--dirname=<directory>
-d
Use <directory> as the file system root for /lib/modules.
--set-version=<version>
-S
Use the specified kernel <version> instead of using uname.
--syslog
-s
Print error messages via syslog instead of standard error (stderr). When stderr is not available, the error is automatically printed to syslog.
--quiet
-q
Disable the display of error messages.
--verbose
-v
Allow more messages to be displayed, if available. modprobe prints the message only when there is a problem.
--version
-V
Displays the modprobe version.
--help
-h
Displays help messages for all commands listed.

Example of Linux Modprobe command usage

By default, all kernel modules are listed in the /lib/modules directory system of the .ko (kernel object) file.

Linux Modprobe Command Tutorial: Use the following command to find all available modules for the current kernel version:

find /lib/modules/$(uname -r) -type f -name '*.ko*' | more

Note: Consider removing the old kernel version. Check out our guide on how to remove old kernels on Ubuntu.

How to use Modprobe commands in Linux: Use the modprobe command to add kernel modules

1. Add the module using the following modprobe command:

sudo modprobe <module name>

For example:

sudo modprobe torture

2. Confirm that the module is loaded:

sudo modprobe <module name> --first-time

The output prints an error because the module is already in the kernel.

Alternatively, use the following command to find the module lmod in the list of active module loads:

lsmod | grep <module name>

For example:

lsmod | grep torture

How does Linux use Modprobe commands? Use the modprobe command to remove the kernel module

1. Use the following modprobe -r command to delete the module:

sudo modprobe -r <module name>

For example:

sudo modprobe -r torture

2. Run the following command to confirm that the module has been removed:

sudo modprobe -r <module name> --first-time

An error message appears stating that the module is not in the kernel:

Linux Modprobe Command Tutorial

Alternatively, check the list of active module loads:

lsmod | grep <module name>

The deleted module is not in the module loading list.

Linux Modprobe command usage examples are summarized

The Linux kernel was created to be modular and easily extensible. Be sure to research the modules you want to add or remove to avoid problems with the kernel.

For further reading, follow our guide on how to build a Linux kernel from scratch.