Saturday, April 13, 2019

Blacklisting modules in RHEL or CentOS 7

Blacklisting modules in RHEL or CentOS 7

You may come to a requirement where you want to "blacklist" a module. Why would you need this feature? Because sometimes a module may cause conflict with another modules, or is superseded by another module, or is otherwise undesirable.

To blacklist a module, the easiest way is to add an module entry to /etc/modprobe.d/blacklist.conf

Let's see how it can be done !

We can take "vfat" module for example, check if it is loaded:

[root@localhost ~]# lsmod | grep -i vfat
[root@localhost ~]#

If you see in below command it's allowed to load, not blacklisted:

[root@localhost ~]# modprobe --showconfig | grep vfat
alias fs_vfat vfat
[root@localhost ~]#

Now we will try to load it:

[root@localhost ~]# modprobe vfat

[root@localhost ~]# lsmod | grep -i vfat
vfat                   17461  0
fat                    65950  1 vfat

As you can see we can load this module, i will now go ahead and unload it:

[root@localhost ~]# modprobe -r vfat

[root@localhost ~]# lsmod | grep -i vfat
[root@localhost ~]#

To blacklist this "vfat" module so that it can't be loaded, we will go to "/etc/modprobe.d" directory and check if "blacklist.conf" file exists here if not we will create a one:

[root@localhost modprobe.d]# pwd
/etc/modprobe.d

[root@localhost modprobe.d]# ls
firewalld-sysctls.conf  mlx4.conf       tuned.conf
dccp-blacklist.conf  lockd.conf              truescale.conf

In my case i don't have "blacklist.conf" file in "/etc/modprobe.d" folder, create it with below 2 lines:

[root@localhost modprobe.d]# vi blacklist.conf

blacklist vfat
install vfat /bin/false


save and exit.

If you run below command you can see now it has be blacklisted:

[root@localhost modprobe.d]# modprobe --showconfig | grep vfat
blacklist vfat
install vfat /bin/false
alias fs_vfat vfat

[root@localhost modprobe.d]# lsmod | grep -i vfat
[root@localhost modprobe.d]#

To verify if you can load it or it is blacklisted:

[root@localhost modprobe.d]# modprobe vfat
modprobe: ERROR: Error running install command for vfat
modprobe: ERROR: could not insert 'vfat': Operation not permitted



No comments:

Post a Comment