Saturday, December 28, 2024
Google search engine
HomeSecurity & TestingHow To Use The Modprobe Command In Linux

How To Use The Modprobe Command In Linux

Introduction

The Linux kernel has a modular design. Functionality is extendible with modules or drivers. Use the modprobe command to add or remove modules on Linux. The command works intelligently and adds any dependent modules automatically.

The kernel uses modprobe to request modules. The modprobe command searches through the standard installed module directories to find the necessary drivers.

This article explains how to use modprobe to add or remove kernel modules.

How to Use the modprobe Command in LinuxHow to Use the modprobe Command in Linux

Prerequisites

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

modprobe Command Syntax Explained

All modprobe commands require sudo privileges. The general syntax for using modprobe is:

sudo modprobe <options> <module name>

By default, the modprobe command adds a module.

For multiple modules, expand with the option -a or -all:

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

Options for modprobe Command

The available modprobe command options are divided into categories based on their use-case.

Management Options

Management options enable different module handling situations when inserting or removing modules with the modprobe command.

--all
-a
Enables multiple modules to be inserted or removed at the same time.
--remove
-r
Remove a module. Applies --remove-dependencies as well. Useful for removing broken modules.
--remove-dependencies Removes dependency modules.
--resolve-alias
-R
Look up and print all module names matching an alias. Useful for debugging alias problems.
--first-time Prints an error for already inserted or removed modules.
--ignore-install
--ignore-remove
-i
Ignore install/remove commands written in the module when inserting/removing a module.
--use-blacklist
-b
Blacklist resolved alias. Blacklisted modules are not automatically loaded.
--force
-f
Force module insertion or removal when version errors appear. Applies both --force-modversion and --force-vermagic. Use with caution.
--force-modversion Ignore module version on insertion or removal. Use with caution.
--force-vermagic Ignore module version magic on insertion or removal. Use with caution.

Query Options

Query options for modprobe show information about configuration and dependencies.

--show-depends
-D
Lists the module with the dependency files if there are any. The dependencies that install with the module have the “install” prefix.
--showconfig
--show-config
-c
Prints current configuration and exists.
--show-modversions
--dump-modversions
Dumps module version dependencies.

General Options

General options configure modprobe output options, module locations, and versions.

--dry-run
--show
-n
Do not execute insert/remove but print the output. Used for debugging purposes.
--config=<file name>
-C
Overrides the default configuration dependency (/etc/modprobe.d) with <file name>.
--dirname=<directory>
-d
Use <directory> as filesystem root for /lib/modules.
--set-version=<version>
-S
Use specified kernel <version> instead of using uname.
--syslog
-s
Prints the error messages through syslog instead of standard error (stderr). When stderr is unavailable, errors get printed to syslog automatically.
--quiet
-q
Disables display of error messages.
--verbose
-v
Enables more messages to show, if available. modprobe only prints messages if something goes wrong.
--version
-V
Shows the modprobe version.
--help
-h
Shows the help message with all the commands listed.

Examples of modprobe Command

All kernel modules are listed in the /lib/modules directory system in .ko (kernel object) files by default.

Find all the available modules for the current kernel version with:

find /lib/modules/$(uname -r) -type f -name '*.ko*' | more
Terminal output of available modules using the find commandTerminal output of available modules using the find command

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

Adding Kernel Modules With modprobe Command

1. Add a module using the modprobe command:

sudo modprobe <module name>

For example:

sudo modprobe torture
Adding a module using the modprobe command in terminalAdding a module using the modprobe command in terminal

2. Confirm the module loaded with:

sudo modprobe <module name> --first-time

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

Terminal output of adding module with modprobe --first-time errorTerminal output of adding module with modprobe --first-time error

Alternatively, find the module in the active module loaded list with lmod:

lsmod | grep <module name>

For example:

lsmod | grep torture
Terminal output of lsmod and grep moduleTerminal output of lsmod and grep module

Removing Kernel Modules With modprobe Command

1. Remove a module using the modprobe -r command:

sudo modprobe -r <module name>

For example:

sudo modprobe -r torture

2. Confirm the module is removed by running:

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

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

Terminal output of removing module with modprobe -r --first-time errorTerminal output of removing module with modprobe -r --first-time error

Alternatively, check the active module loaded list:

lsmod | grep <module name>

The removed module is not on the module loaded list.

Conclusion

The Linux kernel is created to be modular and easily extendible. Make 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.

Was this article helpful?
YesNo

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments