How to Unload or Blacklist Module in Linux

How to Unload or Blacklist Module in Linux

   

This post was last updated on January 22nd, 2019 at 11:06 am

Sometimes you need to unload a kernel module to load your own written code or you want to replace an out-of-box stock module to a vendor provided kernel module. So here you go. This guide tells you how to unload a module in linux. This guide will work in any Linux OS distro.

First you need to see if the module is really loaded or not and other modules those are dependent on the corresponding module that you want to unload.

You need the below two commands but I will guide you with an example too:

lsmod – lists all modules
rmmod – removes a module from the kernel

Follow the below command in a console to get the particular module details:

$ lsmod | grep <kernel_module_name_to_be_unloaded>

If the above command just returns without any output on the console then understand that the module is not at all loaded. There could be possible that either the module is already unloaded or the device for that particular module is not there in your system.

For example if you want to unload megaraid_sas LSI HBA controller driver from Linux kernel then follow as below:

$ lsmod | grep megaraid_sas

If you won’t find any output on the kernel then either the module is already unloaded or the LSI HBA controller is not at all present on your system.
megaraid_sas is the module name for LSI MegaRAID HBA controller driver.
After executing the above command you will see the details of the megaraid_sas module and other modules those are dependent on megaraid_sas. To unload the megaraid_sas module you need to unload the other modules too by executing the following command:

$ rmmod megaraid_sas

If it says ERROR: Module megaraid_sas is in use by xxx, zzz then unload the xxx and zzz modules first and then unload the megaraid_sas. In place of xxx and zzz there will be some real names.

I hope the above explanation just explains neatly how to unload a module in Linux.
When I say Linux I mean almost every Linux distro like Ubuntu, SLES, RHEL variants and all other possible Linux OS distro out there will follw the same procedure.

But here you have to remember one thing that this modification is not permanent and you will again see the megaraid_sas module loaded in the kernel the next time you will boot.
I have taken megaraid_sas module as an example to explain what are the possible things that must be considered while unloading a kernel module.

Now to permanently restrict a kernel module to load you have to make changes to the Grub config file or to the /etc/modeprobe.d/blacklist.conf file.
For example in Ubuntu you have to edit the command line parameters of the default OS in /boot/grub/grub.cfg grub configuration file.
Just add the following line in the command line parameter:

module_to_blacklist.blacklist=yes
e.g: megaraid_sas.blacklist=yes

or
Add the follwing line at the end of /etc/modprobe.d/blacklist.conf file:

blacklist module_name_to_blacklist
e.g: blacklist megaraid_sas

Previous How to setup a network bridge in Ubuntu Linux
Next [How to solve] Could not load host key: /etc/ssh/ssh_host_rsa_key issue in FreeBSD or Linux

About author

Sibananda Sahu
Sibananda Sahu 138 posts

A Linux Kernel Developer and a Firmware Developer by profession. Have worked with few big companies: BROADCOM Corporation, Cypress Semiconductor, LSI Corporation, TOSHIBA Corporation, Western Digital; on various cutting edge technologies and product lines, such as: RAID storage Driver, SSD Firmware, WLAN Firmware etc. Having more than 9 years of experience in Software Engineering domain. Now, took a pledge to educate all aspirant students to teach about Linux Kernel Development.

View all posts by this author →

You might also like

Linux Topics 0 Comments

How to Configure vncserver in Fedora Linux

This post was last updated on November 6th, 2016 at 12:32 amVnc server and vnc viewer is used to Remote Access in most of the Linux machines like Fedora, RHEL,

Linux Topics 1Comments

[How to solve] Could not load host key: /etc/ssh/ssh_host_rsa_key issue in FreeBSD or Linux

This post was last updated on May 1st, 2020 at 01:28 pmSometimes while starting the sshd service you may face some issues like the following: Could not load host key:

Linux Topics 0 Comments

How To Connect A Remote Linux Server Using SSH?

Contents1 SSH(Secure Shell)2 How Does It Work?3 Installing OpenSSH Client4 Installing OpenSSH Server5 How To Connect Via SSH6 SSH Public Key Authentication6.1 Setup public key authentication using ssh on Linux-

0 Comments

No Comments Yet!

You can be first to comment this post!

Leave a Reply