How do I prevent a redhat kernel module loading at boot time of after?



  • Caution is advised whenever making kernel changes.


    Also see: dracut(8) - low-level tool for generating an initramfs/initrd image

    This is called blacklisting. It prevents a kernel module from loading either dynamically or at boot time.

    Edit or create a file.

    $ sudo vi /etc/modprobe.d/blacklist.conf
    

    Add the lines to blacklist a kernel module. The kernel install runs /bin/false instead of loading. The blacklist command does not prevent this module loading as a dependency for other kernel modules.

    # Blacklists sierra kernel module.
    blacklist sierra
    install sierra /bin/false
    

    Make a backup of your existing initial ramdisk.

    $ sudo cp /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).bak.$(date +%m-%d-%H%M%S).img
    

    Create a new initial ramdisk.

    $ sudo dracut -f -v
    dracut: Executing: /usr/bin/dracut -f -v
    ...
    ...
    ...
    dracut: *** Including module: shutdown ***
    dracut: *** Including modules done ***
    dracut: *** Installing kernel module dependencies ***
    dracut: *** Installing kernel module dependencies done ***
    dracut: *** Resolving executable dependencies ***
    dracut: *** Resolving executable dependencies done***
    dracut: *** Hardlinking files ***
    dracut: *** Hardlinking files done ***
    dracut: Could not find 'strip'. Not stripping the initramfs.
    dracut: *** Generating early-microcode cpio image ***
    dracut: *** Constructing AuthenticAMD.bin ****
    dracut: *** Constructing GenuineIntel.bin ****
    dracut: *** Store current command line parameters ***
    dracut: *** Creating image file '/boot/initramfs-4.18.0-147.5.1.el8_1.x86_64.img' ***
     dracut: *** Creating initramfs image file '/boot/initramfs-4.18.0-147.5.1.el8_1.x86_64.img' done ***
    

    Reboot the system when ready.

    $ sudo reboot
    

    Check if kernel module status.

    $ lsmod | grep sierra
    

    Demo, what happens if the kernel module load is attempted.

    $ sudo modprobe -v sierra
    install /bin/false
    modprobe: ERROR: Error running install command for sierra
    modprobe: ERROR: could not insert 'sierra': Operation not permitted
    

Log in to reply
 

© Lightnetics 2024