Kernel Modules

Kernel modules are object files that contain code to extend the kernel of an operating system. Kernel modules are used to add support for new hardware and/or filesystems, or for adding system calls. Modules can be built into the kernel or compiled as loadable kernel modules.

Compile-in-kernel modules vs Loadable kernel modules (LKMs)
This page is meant to help picking between compile-in-kernel and compile-as-module  when configuring a kernel.

Advantages
A module:


 * Is loadable without reboot (at least most of them).
 * Results in smaller kernel memory footprint (when the module is not loaded).
 * Can be loaded on demand by udev (for example DVB drivers for a DVB stick).
 * Allows easy reloading of kernel drivers in case of module crash.
 * Allows setting module-specific parameters in

Drawbacks
Using a module:


 * May require an update of the initramfs for modules needed early in the boot process (i.e. filesystem drivers).
 * May result in performance losses due to the addition of an API layer and slightly more memory usage.

Also:
 * Beware of file system module X located on a partition formatted with X (unbootable system at worst).

Automatic loading
Loadable modules can be defined in files in the  directory in order to load them during the init portion of the system boot process. Each module is listed one per-line. For example:

Blacklist
To avoid a module from loading, add it by name to a file in and precede each module name with the   keyword:

More information on module blacklisting via modprobe.d can be found by reading the modprobe.d(5) man page:

Alternatively, kernel modules can be blacklisted from the secondary bootloader (see GRUB, systemd-boot, etc.) via parameters passed to the kernel from the kernel command-line. For example, to blacklist the evbug.ko, nvidiafb.ko, and nvidia.ko kernel modules using command-line parameters:

module_blacklist=evbug,nvidiafb,nvidia

More details on backlisting via kernel command-line parameters can be found in the upstream kernel documentation (search for module_blacklist).

Manual loading
A module can be loaded or unloaded manually by the command. For example, to unload the  module and load the   module, run:

To list currently loaded modules, run.

Going completely module-less
If, for some reason, there is a desire to have a completely module-less system, disable loadable module support in the kernel configuration (making sure to build-in any required drivers/features, of course). Setting  will disable loadable module support:

With a module-less kernel, it is possible to dispense with the userspace programs that manage loadable modules (e.g., , etc). To do this, remove kmod support from packages that use it, and also remove and the virtual  package(s). Because is part of the system set, it first must be removed from the set before it can be unmerged.

First, add  to the system's USE flags in.

Next, rebuild installed packages without kmod support:

Follow any special instructions given by rebuilt packages (for example, if udev was rebuilt, then restart it according to the instructions in the output).

Now add  to  (create the  directory and  file if they don't exist). This removes the virtual package from the system set.

Then remove and  packages:

If the above command only removes modutils, then some package still depends on kmod even with the  USE flag set. Run to find out which package still depends on kmod.

If a kernel was installed with modules, then also remove the directory. Since the kernel was built without any loadable modules, there won't be anything useful in there anymore.

When using a generated initramfs, it may be necessary to add   to the kernel command line in the system's bootloader (e.g. GRUB) configuration so that the initramfs does not waste any time looking for modules to load.