How to unload the kernel module in RHEL ?

If we want to unload the kernel module temporarily we are using “modprobe -r <module name>” to remove it like shown below.

[root@Node2 ~]# lsmod | grep -i bonding
bonding               125610  0
ipv6                  322029  156 bonding,ip6t_REJECT,nf_conntrack_ipv6,nf_defrag_ipv6

[root@Node2 ~]# modprobe -r bonding

[root@Node2 ~]# lsmod | grep -i bonding
[root@Node2 ~]#

Temporarily means it will not persist across reboots. It will load automatically after the reboot, if require.

But if we want to remove it permanently we have two options. First one is the safer one and second one is little bit dangerous.

1) Adding the below line in /etc/modprobe.d/blacklist.conf. If this file is not present we can create this file.

blacklist <module name>

If we want to remove the bonding module.

[root@Node2 ~]# cat /etc/modprobe.d/blacklist.conf | grep -i bonding
blacklist bonding

[root@Node2 ~]# modprobe bonding

[root@Node2 ~]# lsmod | grep -i bonding
bonding               125610  0
ipv6                  322029  156 bonding,ip6t_REJECT,nf_conntrack_ipv6,nf_defrag_ipv6

In this case Module can be loaded automatically if it is require by another modules. We can load the module manually as well without any warning message.
But if module is not require by any other module or manually load it will not load.

2) Adding below line in /etc/modprobe.d/blacklist.conf. If this file is not present we can create this file.

install <module name> /bin/false

If we want to remove the bonding module.

[root@Node2 ~]# cat /etc/modprobe.d/blacklist.conf | grep -i bonding
install bonding /bin/false

In this case module will not be loaded in anyway. When we are trying to load the manually we are getting the below error.

Module is already loaded.

[root@Node2 ~]# lsmod | grep bonding
bonding               125610  0
ipv6                  322029  156 bonding,ip6t_REJECT,nf_conntrack_ipv6,nf_defrag_ipv6

Lets remove the module and confirmed that it has been removed.

[root@Node2 ~]# modprobe -r bonding
[root@Node2 ~]# lsmod | grep bonding

If we are trying to load it again we are getting the error.

[root@Node2 ~]# modprobe bonding
FATAL: Error running install command for bonding

Suppose if this module require by other module then it can create problems because this can’t be loaded in anyway. Generally it is better to avoid this option.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s