In this article, we would cover how to load or remove a kernel module in Ubuntu. Kernel modules are used to extend kernel functionality. It is not wise to configure and rebuild kernel when we have already got a kernel module which we can load or remove at an instant. Following directory contains all kernel modules available in the system –
where, linux_kernel_release is the kernel version which we can identify through –
For instance, if
uname -r returns with 5.15.0-46-generic then, all the kernel modules are in the directory –
With kernel modules available, we don’t have to put every code inside the kernel. We can load or remove a kernel module as and when necessary. This ensures things are faster and efficient.
Word of caution: We should load and remove a kernel module only when we know what we would achieve by doing that. If we happen to not know the outcome then, it is better to leave things as it is. Otherwise, it may lead to serious kernel issues. Also, following operations require superuser privileges.
Load or Remove a kernel module in Ubuntu
We can load or remove a kernel module using modprobe command-line utility. To load a kernel module, use the following code –
sudo modprobe <module_name>
On the other hand, if we want to remove a module then –
sudo modprobe -r <module_name>
For instance, if we want to load and remove a kernel module – pppoatm
Just verify first if the kernel module is already loaded or not –
lsmod | grep pppoatm
If the kernel module isn’t loaded then, it would return with nothing. Next step is to load the kernel module –
sudo modprobe pppoatm
Again, check whether its loaded or not?
lsmod | grep pppoatm
This time around the output would resemble –
pppoatm 20480 0 atm 65536 1 pppoatm
Now, to remove the loaded module – pppoatm
sudo modprobe -r pppoatm
where, -r is used to remove the module. It removes all unused and dependent modules as well. We can verify its removal through lsmod command-line utility as discussed above.
In conclusion, we have discussed how to load or remove a kernel module in Ubuntu here.