How to disable a kernel module on Linux?

0
54
Disable a kernel module
Disable a kernel module

A long time ago, Linux had a lot of hardware problems. Nowadays, they have not disappeared completely but it is fair to say that practically everything is supported. Precisely that is the reason why many times the Linux kernel has incorporated many modules for hardware that we do not use. Then, with some knowledge, we will be able to disable a kernel module on Linux.

What is a kernel Module?

First of all, it is harassing to know what a Kernel module is. A kernel module is a fragment of the object code that is incorporated into the kernel to extend its functionality. Generally, modules are integrated into the kernel to support a new hardware or file system. It is even possible to find modules that add other capabilities to the kernel such as improvements in the data processing.

Therefore, for each piece or component of hardware that we own, it is necessary that there is a module in the kernel that recognizes it. The problem, sometimes, is that the Linux kernel has loaded modules that we will probably never use. So, in some cases, it’s a good idea to disable them.

Note: Be careful disabling kernel modules. A bad decision could cause problems in your system.

It is possible to disable a kernel module permanently or temporarily. All this, according to our needs.

Permanently disable a kernel module

For this post, I will pose the following situation. There is a kernel module called floppy that manages a floppy disk drive. Currently, practically no equipment uses floppy disks, so loading that module is unnecessary. In addition, it slows down the system startup and consumes resource. So, let’s disable it.

To do this, you need to create a blacklist file and add that module.

:~$ su
:~# nano /etc/modprobe.d/local-blacklist.conf
blacklist floppy

Then, save the file and then close it.

However, if the module is dependent on another module, it will be loaded even though it has been blacklisted. Therefore, it is necessary to add one more parameter.

install floppy /bin/false

If the kernel module is part of initramfs (boot configuration), the initramfs must be regenerated.

:~# dracut -f

After that, reboot the system.

:~# reboot

On the other hand, before performing this process verify that the module is not in /etc/modprobe.conf, /etc/modprobe.d/, /etc/rc.modules or /etc/sysconfig/modules/.

Disable a kernel module temporarily

Now. It is possible to disable a kernel module temporarily. Useful in certain cases to test a specific function. To do this, simply run the following command:

:~# modprobe -r floppy

And that’s it. That way you can disable it. If you want to reverse this, you can enable it again.

:~# modprobe floppy

Finally, if you want to list all enabled modules

:~# lsmod

So, that’s it.

Conclusion

Disabling even a kernel module is a delicate thing but it can help us to have more control over our Linux distribution. In addition to this, it is time to improve system performance.

Please share this post with your friends.

LEAVE A REPLY

Please enter your comment!
Please enter your name here