Linux modprobe command with Useful Examples

The Linux Kernel is the core component of a Linux operating system. The Linux kernel has a modular design that allows it to be extended in terms of functionality. Modules are small pieces of code that may be loaded and unloaded by the kernel without having to restart the computer. Kernel modules can be loaded/removed manually or automatically.

When a new device such USB or PCI is connected/removed, the kernel sends uevents. The uevents contain information about the device such as vendor and model details. Udev (device manager) is listening to this uevents and passes them to modprobe. Modprobe intelligently identifies the requested driver by searching under the module directory /lib/modules/uname -r and loads the module file into the kernel. Once the module is successfully loaded, it appears in the listing from lsmod command. Additionally, modprobe is used to manually add or remove a loadable module from the kernel.

Modprobe is distributed as part of kmod package. In this tutorial, we learn how to use modprobe command to add and remove modules from the Linux kernel.

modprobe command syntax

Let's check the syntax of modprobe command:

$ sudo modprobe [options] [Module Name]

modprobe command to add Kernel Module

Kernel modules are located in the subdirectories located at /lib/modules/$(uname -r). The command uname -r can be used to determine the current kernel version.

When adding a module modprobe intelligently check the module dependency where insmod doesn't do that. The dependencies listed in the file /lib/modules/$(uname -r)/modules.dep and reference of the module name is specified in /etc/modules file.

To list the kernel module located directory, type:

$ ls /lib/modules/$(uname -r)

You can find all the device drivers in the directory /lib/modules/$(uname -r)/kernel/drivers/.

Usually, kernel module files have .ko extensions. You can list all .ko files by:

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

You can add the module to the Linux kernel using modprobe the command along with the module name.

$ sudo modprobe img_i2s_in

Once added you can confirm by lsmod command that lists currently loaded kernel modules.

$ sudo lsmod | grep img_i2s_in


img_i2s_in             16384  0

modprobe command to remove Kernel Module

To remove a module, use the modprobe command with the -r option along with the module name.

For example, to remove the module named img_i2s_in, type:

$ sudo modprobe -r img_i2s_in

modprobe Options

The modprobe command has several options, which have been divided into three categories based on their use cases.

Management Option

When using the modprobe command to add or remove modules, management parameters enable multiple module handling scenarios.

Remove or add multiple modules at once
Remove the module, also applies for --remove-dependencies
--remove-dependenciesRemove dependency modules
Identify and print the name matching an alias
--first-timePrint error for added or removed modules
Ignore the install or remove commands written in the module when inserting or removing the module
Blacklist resolved alias
When version error is displayed, force module addition or removal. This applies for both --force-modversion and --force-vermagic.
--force-modversionIgnore module version on adding or removal of the module.
--force-vermagicIgnore module version magic on adding or removal of the module.
Management Option of modprobe command

Query Options

The query option of the modprobe command gives information about configuration and dependencies.

If there are any modules with dependency files, it displays that module
Display the current configuration and exits
Show module version dependencies
Query Options of modprobe command

General Options

The general options in the modprobe command configure the output options, module locations, and versions.

Print the output but do not add or remove anything.
Overrides the default configuration dependency i.e. /etc/modprobe.d with the [Filename]
For /lib/modules use [Directory] as the filesystem root
Instead of specified kernel uname, use the [version] kernel
Displays error message through Syslog
Do not display error messages
Enables more messages to show
Display version of modprobe
Display help message along with commands
General Options of modprobe command


In this tutorial, we learned about modprobe command to add or remove modules from the Linux kernel.

Thanks for reading, please provide your feedback and suggestions.

Leave a Comment