The modprobe command can be used to load ad unload modules for the Linux kernel. By default the kernel modules are loaded and removed automatically by Linux. But this may not work in some cases or not suitable.
modprobe Configuration Files
Kernel modules are configured with diffrent configuration files. These configuration files used to load, blacklist or add parameters to the kernel modules.
- “/etc/modules“: This file contains the names of kernel modules that should be loaded at boot time, one per line. Lines beginning with “#” are ignored.
- “/etc/modules-load.d/“: This directory contains module-specific configuration which is applied during module load.
- Also similar to the /etc/modules file /etc/modules-load.d/modules.conf file is provided for general kernel module configuration.
Kernel Modules
Kernel modules are stored in the “/lib/modules/” directory with the related kernel version number. These versions are listed like below.
ls -l /lib/modules/
The kernel versions for kernel modules are listed like below.
drwxr-xr-x 2 root root 4096 Kas 27 06:16 5.8.0-25-generic drwxr-xr-x 2 root root 4096 Ara 6 16:16 5.8.0-26-generic drwxr-xr-x 5 root root 4096 Kas 26 20:27 5.8.0-29-generic drwxr-xr-x 5 root root 4096 Ara 4 07:42 5.8.0-31-generic drwxr-xr-x 5 root root 4096 Ara 18 09:49 5.8.0-33-generic
The content of the specific kernel package can be listed like below.
ls -l /lib/modules/5.8.0-33-generic
The output is like below.
List Modules
Modules for the Linux kernel can be listed with the lsmod command. This command lists all modules loaded or not loaded with the size and usage information.
- Module is the module name
- Size is the size of the module
- Used by is whether it is used by other modules and loaded the number show how many times it is loaded or used.
We can also list specific kernel module with the grep command. For examle the modules with the name port can be listed like below.
lsmod | grep port
Load/Add Module To Linux Kernel
A Kernel module can be loaded or added with the modprobe command by providing the kernel module name. Also loading a kernel module requires root privileges which can be provided with the sudo command. In the following example, we will load the module named psmouse.
sudo modprobe psmouse
Load/Add Module with Parameter
Modules can be configured with some parameters. These parameters can be provided via the command line with the modprobe command. The parameter name and value provided with the equal sign like below.
sudo modprobe psmouse parameter=value
Unload/Remove Module From Linux Kernel
The modprobe command can be used to remove or unload an allready loaded linux kernel. The-r option and the kernel module we want to unload or remove should be provided like below.
sudo modprobe -r psmouse