There may be a time when you need to disable some kernel modules from being loaded during your Linux system's boot time. In this guide, we will discuss a few different ways to blacklist a module, including its dependencies, on Ubuntu and any other Debian based distros. This will effectively permanently disable a module from loading during the boot time.

In this tutorial you will learn:
  • How to blacklist a kernel module on Ubuntu/Debian-based Linux distros
Blacklisting a kernel module on Ubuntu Linux
Blacklisting a kernel module on Ubuntu Linux
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Debian-based distros
Software N/A
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ - requires given linux commands to be executed as a regular non-privileged user

Blacklist module from loading


SUBSCRIBE TO NEWSLETTER
Subscribe to our NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.


Follow along with the steps below to see how to blacklist a kernel module from loading on your system.

  1. Let's start by listing all modules currently loaded by your Linux system:
    $ lsmod
    ....
    ehci_hcd               40249  0 
    usbcore               128741  4 ehci_hcd,ohci_hcd,usbhid
    usb_common             12354  1 usbcore
    e1000                  86156  0 
    libata                140630  4 libahci,ahci,ata_piix,ata_generic
    ....
    
    The lsmod command lists all currently loaded kernel modules. The above lsmod output has been shortened.
  2. Let's say we are going to blacklist the usbcore module. Before you unload or blacklist any module it is good to see what other modules depend on it:
    $ modinfo -F depends usbcore
    usb-common
    
  3. From the above output we can see that the usb-common module depends on usbcore. To blacklist a module without dependencies, we will create a /etc/modprobe.d/blacklist.conf (if it doesn't exist already) file and add the following line to it:
    blacklist usbcore
    
  4. Once done, update initramfs and reboot your system:
    # update-initramfs -u
    # reboot
    


After rebooting, use lsmod to see whether the module is presently loaded. In case other modules are dependent on the module you are trying to blacklist, like in the above example, you will need to blacklist all dependent modules, otherwise the initial module you have blacklisted would load anyway. Fortunately, there is a trick to blacklist all modules including their dependencies.

If, for any reason, you are unable to blacklist modules and all its dependencies, make the module fail to load and thus also cause all dependent modules to keep from loading. Add the following line to your /etc/modprobe.d/blacklist.conf to completely blacklist usbcore including all its dependent modules:

install usbcore /bin/true

Then, update initramfs and reboot:

# update-initramfs -u

Just to be complete, please note that it is a good practice to create a separate module configuration file for each blacklisted module. For example if you wish to blacklist module e1000, then create a separate /etc/modprobe.d/e1000.conf file.

Closing Thoughts

In this guide, we saw how to blacklist a kernel module in Ubuntu and other Debian-based Linux systems. This is helpful when you need to prevent a module from loading, either temporarily or permanently, at boot time. The change is simple to revert by deleting the file if you need to allow the module to load once more. These instructions allow the module to remain on your system, while just preventing it from being loaded automatically.

FIND LATEST LINUX JOBS on LinuxCareers.com
Submit your RESUME, create a JOB ALERT.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.