Kernel modules:

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:


Loading modules manually:

- insmode:

In Linux, only the needed modules are loaded.
We could use the "insmod" utility to load modules into the kernel, but "insmoddoesn'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.

Example:


Then we could check if our "tap.ko" module was loaded using the below command:


We could remove the module using the below command:


- modprobe:

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".


Remark:

"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, t
his 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.

Example:

We get an error trying to load a "veth.ko" module for the virtual ethernet:


After running the below command:


We try the to load the module again using "modprobe" and we check if the module was loaded:


Removing a module:

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.

Remark:

It is better to use the below command instead of "rmmod":


Brando Sabatini and Ikbal C ©. Powered by Blogger.