The Linux kernel is managing the computer resources and work as the bridge between your computer’s hardware and software. It is the core component in the Linux operating system. The Linux kernel has a modular design and need to add and remove modules. In this article, we’ll explain how to use modprobe to add and remove modules from the Linux kernel.
Kernel modules are either compiled as loadable modules or built into the kernel. Loadable modules can be loaded and unloaded in the running kernel on request, without the need to reboot the system. Generally, the modules are loaded on demand by udev
. You can manually load a module into the kernel using the modprobe
command, or automatically at boot time using /etc/modules
or /etc/modules-load.d/*.conf
files.
Add Kernel Modules
The Kernel modules are located in the /lib/modules/
directory. Find the version of running kernel using the uname -r
command.
Run the following modprobe
command followed by module name to load:
modprobe MODULE_NAME
The modprobe
command will load the given module and any additional module dependencies. Only one module can be specified at the command line.
You can confirm module by using lsmod command:
lsmod | grep MODULE_NAME
To load a module with additional parameters, use the parameter=value
syntax:
modprobe MODULE_NAME parameter=value
You can pass the multiple parameter=value
pairs separated by space with modprobe
command:
Generally, you would need to load the module during the system boot. You can do that by that by specifying the module and its parameters in a file inside the /etc/modules-load.d
directory. Files must end with .conf
and can have any name:
Commonly, it’s require to load the modules at the time of system boot. You can specify the module and its parameter in a file at /etc/modules-load.d
directory with name like /etc/modules-load.d/MODULE_NAME.conf
.
option MODULE_NAME parameter=value
The udev
(device manager) will read the settings and which loads the modules at system startup using modprobe
.
Remove Kernel Modules
It is very simple to remove the module. Run the modprobe
command with -r
option followed by the module name:
modprobe -r module_name
It will also remove the unused module dependencies.
You can also remove multiple modules in a single command by specifying multiple modules as arguments:
modprobe -r module_name1 module_name2
To prevent a Kernel module from loading at boot time, create a .conf
file with any name inside the /etc/modprobe.d
. The syntax is:
blacklist module_name
If you want to blacklist additional modules, specify the modules on a new line, or create a new .conf
file.
Conclusion
The modprobe
command is used to add and remove the Linux kernel modules on Linux systems.
If you have any questions or feedback, feel free leave a comment below.