Linux can load a driver as soon as it detects a device the driver supports. On Ubuntu Server 26.04 LTS, blacklisting a kernel module stops that automatic match when an unwanted or conflicting driver keeps loading.
A blacklist tells modprobe to ignore the module's built-in device aliases. A direct request by module name or a dependency can still load it. A driver compiled into the kernel stays available regardless of the blacklist.
Drivers needed early in boot can load from the initramfs, the temporary filesystem Linux uses before mounting the root filesystem. Rebuilding that image makes the blacklist available during early boot.
Steps to blacklist a kernel module in Linux:
Run the commands over SSH or at the server console as an account that can use sudo. Start with a loadable module that loads at boot because a connected device matches one of its aliases. The server must be set to boot the same kernel on the next restart.
Blacklisting a driver can make its device unavailable or prevent the server from booting. Avoid drivers the server needs for storage, networking, or the console. Before changing any files, make sure you have a known-good way to boot without the image you are about to rebuild. For example, have console access and a previously booted kernel available under GRUB's Advanced options.
The example uses uvcvideo, the USB webcam driver. Substitute your module's name as it appears in the first column of lsmod in every check, the filename, and the blacklist rule.
- Check the Used by column for your module.
Stop if there is no row or Used by names a module that depends on yours.
$ lsmod | grep '^uvcvideo ' uvcvideo 143360 0
- Check for an explicit entry for your module in
/etc/modules.If the file exists, an entry for your module means you should stop. For names containing underscores or hyphens, check both spellings in this file and in the boot drop-ins.
$ grep -nE '^[[:space:]]*uvcvideo[[:space:]]*$' /etc/modules
- Check for an explicit entry for your module in the
.conffiles under/etc/modules-load.d.If a file lists your module, or you cannot establish that a device alias causes the load, stop before editing the blacklist.
$ grep -REn --include='*.conf' '^[[:space:]]*uvcvideo[[:space:]]*$' /etc/modules-load.d
- Record the running kernel version so you can rebuild that kernel's boot image even from a fallback kernel.
$ uname -r 7.0.0-44-generic
If the server fails to boot after the change, start the known-good kernel. From the fallback kernel, remove only your drop-in with
sudo rm /etc/modprobe.d/blacklist-uvcvideo.conf. The rebuild command issudo update-initramfs -u -k 7.0.0-44-genericwith the version recorded here. Once the rebuild succeeds, reboot into the repaired kernel. - Open an unused
.confdrop-in under/etc/modprobe.dfor your module in nano.If you choose a different filename, use that path for rollback too.
$ sudo nano /etc/modprobe.d/blacklist-uvcvideo.conf
- Enter the blacklist directive for the same module you checked as the file's only line.
blacklist uvcvideo
- Press Ctrl+O to open Write to File in nano.
- Press Enter to confirm the drop-in filename.
- Press Ctrl+X to exit nano.
- Confirm that
modprobereads the blacklist rule for your module.$ modprobe --showconfig | grep -x 'blacklist uvcvideo' blacklist uvcvideo
If the exact rule is missing, check the filename and saved line before repeating the check.
- Rebuild the initramfs for the kernel version you recorded.
$ sudo update-initramfs -u -k 7.0.0-44-generic
The
-koption selects the kernel image to update. If the rebuild reports an error, resolve it and rerun the rebuild before rebooting. - Reboot the server during a maintenance window.
The reboot interrupts running services and closes SSH sessions.
$ sudo reboot
- Check for your module in the loaded-module list from a fresh console or SSH session after the reboot.
$ lsmod | grep '^uvcvideo '
If the prompt returns with no matching row and no error, the module stayed unloaded. A matching row or an error means the check failed.