How to blacklist kernel modules?

  • LnxSlck

    LnxSlck Correct answer

    8 years ago

    Note: blacklisting will not work for modules which are built into the kernel image (i.e. not loaded via a separate .ko file. The only way to disable such modules is via a kernel parameter (if available) or by recompiling the kernel.

    Just open your /etc/modprobe.d/blacklist file and add drivername using following syntax:

    blacklist driver-name
    

    EDIT: In later versions since 12.10 (12.04?) the file is /etc/modprobe.d/blacklist.conf

    Reboot your box and use lsmod command to show the status of modules in the Linux Kernel

    Note: here driver-name is the name of your desired blacklist driver. For example, If you wanted to disable the NIC card driver, you can find the name of kernel driver for your LAN card by using the command lspci -v command in a terminal.
    For Example my output was :

    ........
    ........ 
    6:00.0 Ethernet controller: Broadcom Corporation NetLink BCM5906M Fast Ethernet PCI Express (rev 02)
        Subsystem: Lenovo Device 3861
        Flags: bus master, fast devsel, latency 0, IRQ 46
        Memory at b8000000 (64-bit, non-prefetchable) [size=64K]
        Expansion ROM at  [disabled]
        Capabilities: 
        Kernel driver in use: tg3
        Kernel modules: tg3
    ........
    ........
    

    Here, I see the driver is tg3. so you need to write tg3(or your driver) in the place of driver-name.

    Plenty of info can be found here.

    in my case (`Lubuntu 12.10`), there is not a `/etc/modprobe.d/blacklist` file. There is a `/etc/modprobe.d/blacklist.conf` file

    It is better to keep modules blacklisted by a user in a separate file in order to avoid conflicts during upgrade (see this comment at serverfault).

    The `blacklist.conf` file doesn't need to exist. You could put a file called `my-mom-is-awesome` there and it would work. Make up whatever name you like if you want to make a specific file just to blacklist a specific thing, like `blacklist-nouveau` or whatever.

    @doug65536 this question was posted 7 years ago, of course things will change. Just create a new question with the Ubuntu version you have, so people can help you

    @LnxSlck I was addressing confusion voiced in previous comments. I did not want help. What is with the obsession with not posting to older content? Just leave it to rot? People still find this and others will have the same questions I addressed.

  • You can also temporarily blacklist them on the grub command line (linux line) when you boot with the syntax

    module_to_blacklist.blacklist=yes
    

    How long is this "temporary"? Until next boot?

    Seth, it is temporary for just the single boot if you edited during boot. If you edit using /etc/grub.d/ scripts or /etc/default/grub, then it is permanent.

    Apparently this does not work for i915: `i915: unknown parameter 'blacklist' ignored`.

    @RafałCieślak - if you need assistance, ask a question. Be sure to specify your video card, describe your problem, and what your tried to solve the problem.

    @bodhi.zazen - thanks, but I do not have any problem - I have just noted that this may not work for some particular modules :)

    is there other way to disable a module from grub during boot ?

    Same syntax, edit the grub boot line and add it in

    What is the difference between this and `modprobe.blacklist=module_to_blacklist`?

    Same effect (blacklist modules) I am going to guess the syntax may vary between kernels, but I am not sure

    or use the kernel parameter `modprobe.blacklist=module_to_blacklist` (see `man modprobe` for details)

    I'm on Grub 2 booting via UEFI, I don't see any kind of kernel command line. The GRUB asks me to hit `e`, and I hit `e`, and I see this editing panel, but there's no obvious location to add any kind of `modprobe` syntax in. I don't even know what the format of this file should be?

    @CMCDragonkai use the arrow keys on the keyboard to navigate. Manually type in the options you want at the end of the kernel line (starts with linux). Type ctrl-x to boot

  • Another way to blacklist modules in at least Ubuntu 16.04 LTS is by adding the following line to the kernel command line:

    modprobe.blacklist=MODULE_NAME
    

    Using the /etc/modprobe system is the best way, but this is an alternative that can be used in a pinch by editing your GRUB command line at boot.

    This can also be made permanent by editing /etc/default/grub and adding to the GRUB_CMDLINE_LINUX_DEFAULT variable. For example, in my /etc/default/grub I have:

    GRUB_CMDLINE_LINUX_DEFAULT="quiet splash modprobe.blacklist=nouveau"
    

    Then I run update-grub2, then update-initramfs -u. After a reboot, you'll be free of the module, so long as nothing loads it after boot.

    This method also works in EL variants (RHEL, CentOS, SciLinux), but you'll have to use that distro's methods to update grub and the initrd.

    (Note to those trying to blacklist nouveau: Make sure to not load X by running systemctl set-default multi-user.target, otherwise when X starts it'll load nouveau again!)

  • In more recent releases, you need to use the install directive in your blacklist file

    install modulename /bin/false
    

    Replace "modulename" above with the name of the module. This will forcibly prevent its loading.

    You can find more info about the install directive in the manual for modprobe.conf

    man modprobe.conf
    

    This is very helpful. It turns out even with a blacklist entry in `/etc/modprobe/blacklist.conf`, the module can still be loaded manually with `modprobe `. Using the `install /bin/false` method makes this fail as desired.

  • None of these solutions worked on 16.04 LTS for i915.ko.

    The (dirty) solution I found was to rename

    /lib/modules/4.4.0-22-generic/kernel/drivers/gpu/drm/i915/i915.ko
    /usr/lib/xorg/modules/drivers/modesetting_drv.so
    /usr/lib/xorg/modules/drivers/intel_drv.so
    

    Unfortunately, external VGA screen is not recognised anymore :{

    All you need is `sudo update-initramfs -u` after modifying /etc/modeprobe.d/ files

License under CC-BY-SA with attribution


Content dated before 6/26/2020 9:53 AM