Linux 101 : An overview of kernel modules - insmod, lsmod, depmod, rmmod and modprobe -
Modules are small programs that can be used to add functionalities to the Linux kernel.
They could be loaded while the system is running.
The kernel loads modules automatically, but if we need for a particular reason to manually load a module, we put it in the "/etc/modules" file.
The system will load that module and all its dependencies.
Blacklisting a module:
We could also blacklist modules that we don't want the kernel to load. For example, an old device driver or a module that has a bug in it.
In the "/etc/modeprobe.d/blakclist.conf" file, we mention the module that we want to blacklist, so that he kernel doesn't automatically load it.
The syntax is as follows:
In Linux, only the needed modules are loaded.
We could use the "insmod" utility to load modules into the kernel, but "insmod" doesn't perform dependency checks on the module.
Also when loading a module with "insmod", we need to specify the whole path for the module, we can't reference the module by name alone.
Then we could check if our "tap.ko" module was loaded using the below command:
We could remove the module using the below command:
With "modprobe" we don't have to give the full path of the module we want to load in the kernel, we just give its name as an argument to "modprobe".
"modprobe" loads modules by name, we don't need to specify the full path of the module. It also loads all the dependencies of the module.
The "modprobe" utility uses "insmod" in the background.
The depmod utility:
"depmod" creates a map for a module and its dependencies, this helps the "modprobe" utility to find all the dependencies for a modules it loads.
We run "depmod" each time we add a new module with its dependencies.
We get an error trying to load a "veth.ko" module for the virtual ethernet:
The "rmmod" utility removes modules.
If the module we want to remove is used by another module, "rmmod" will exit with an error, giving us the names of all the modules that are using the one we want to remove.