Linux modprobe command with Useful Examples

Channel: Linux
Abstract: $ sudo modprobe [options] [Module Name] modprobe command to add Kernel Module Kernel modules are located in the subdirectories located at /lib/modules

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.

How To Install Mods in Minecraft fo...

To view this video please enable JavaScript, and consider upgrading to a web browser that supports HTML5 video

How To Install Mods in Minecraft for iPhone & iPad 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

Output:

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.

OptionsDescription-a
-allRemove or add multiple modules at once--remove
-rRemove the module, also applies for --remove-dependencies--remove-dependenciesRemove dependency modules--resolve-alias
-RIdentify and print the name matching an alias--first-timePrint error for added or removed modules--ignore-install
--ignore-remove
-iIgnore the install or remove commands written in the module when inserting or removing the module--use-blacklist
-bBlacklist resolved alias--force
-fWhen 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.

OptionsDescription--show-depends
-DIf there are any modules with dependency files, it displays that module--showconfig
--show-config
-cDisplay the current configuration and exits--show-modversions
--dump-modversionsShow module version dependenciesQuery Options of modprobe command

General Options

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

OptionsDescription--dry-run
--show
-nPrint the output but do not add or remove anything.--config=[Filename]
-COverrides the default configuration dependency i.e. /etc/modprobe.d with the [Filename]--dirname=[Directory]
-dFor /lib/modules use [Directory] as the filesystem root--set-version=[version]
-SInstead of specified kernel uname, use the [version] kernel --syslog
-sDisplays error message through Syslog--quiet
-qDo not display error messages--verbose
-vEnables more messages to show--version
-VDisplay version of modprobe--help
-hDisplay help message along with commands General Options of modprobe command Conclusion

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.

Ref From: linoxide

Related articles