In this article, we would discuss how to load and unload Linux Kernel modules. But, before that we would discuss a bit about Linux Kernel Modules itself. A Linux Kernel acts as an interface between computer’s hardware and processes in Operating System. A Kernel can perform multiple operations – manage processes and memory efficiently, interpreter for devices etc. It wouldn’t be right for us to build large Kernel images, containing every possible functionality.
Now, understand it with the help of an example. If certain drivers are not available in our Kernel image for the hardware we would want to connect. Under such a scenario, we have the option to load the relevant Kernel Module to make it work. Thus, helping us avoid the need to rebuild Kernel images. And, it also helps us in limiting the size of our Kernel image.
Therefore, we have got two options – either to build Modules inside our Kernel image itself or load them later as and when required. Most of the Kernel modules could be loaded without having to reboot our system.
Before moving ahead, we would like to clarify that you must take extreme care while performing below mentioned operations. Contact your System Administrator for assistance, in case you are not sure of what you are about to execute. Also, following operations would require you to have superuser privileges.
Load and Unload Linux Kernel Modules
Firstly, we would check for all the modules which have already been loaded in our system. Hence, open a terminal and issue the following –
It provides us the list of loaded modules and their size by getting the information from /proc/modules file.
Although there are two command-line tools – insmod (it inserts a module in Kernel) and rmmod (it removes a module from Kernel). But, we would choose to discuss modprobe command-line utility instead. It can handle module dependencies better.
To get more information about a Kernel module use the following command –
For instance, if you would like to know more about zfs module –
To load a module –
sudo modprobe <module_name>
For instance, to load ZFS module –
sudo modprobe zfs
To check if your module has successfully been loaded in Kernel image –
lsmod | grep zfs
To unload a module –
sudo modprobe -r <module_name>
For instance, unload the same module – ZFS
sudo modprobe -r zfs
To check if your module has successfully been unloaded from Kernel image –
lsmod | grep zfs
This time around, it would return with a blank output.
In conclusion, we have discussed how to load and unload Linux Kernel modules. But, there is more to it. We will discuss more about Kernel modules in coming articles.