Kernel modules

From Gentoo Wiki
Jump to: navigation, search
This article is a stub. You can help by expanding it.

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 (<M>) when configuring a kernel.


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 /etc/conf.d/modules


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.


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

Loadable kernel modules

Automatic loading


Loadable modules can be defined in the /etc/conf.d/modules file in order to load them during the init process.


To avoid a module from loading, add it to a file in /etc/modprobe.d/:

FILE /etc/modprobe.d/blacklist.conf
blacklist uhci_hcd
blacklist nvidia

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

user $man 5 modprobe.d


See the automatic module loading section in the systemd article for module loading when using systemd.

Also see the modules-load.d(5) man page:

user $man 5 modules-load.d

Manual loading

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

root #modprobe -r nvidia
root #modprobe nouveau

To list currently loaded modules, run lsmod.

Going completely module-less

If, for some reason, you want to have a completely module-less system, you can disable loadable module support in your kernel configuration (making sure to build-in any required drivers/features, of course). Setting CONFIG_MODULES=n will disable loadable module support:

KERNEL Disable loadable module support (CONFIG_MODULES)
[ ] Enable loadable module support  ----

With a module-less kernel, you may also wish to dispense with the userspace programs that manage loadable modules (e.g. lsmod, modprobe, etc). To do this, you'll need to remove kmod support from packages that use it, and you'll need to unmerge sys-apps/kmod and the virtual virtual/modutils package(s). Because virtual/modutils is part of the system set, it first must be removed from the set before it can be unmerged.

First, add -kmod to the system's USE flags in /etc/portage/make.conf.

Next, rebuild installed packages without kmod support:

root #emerge --ask --deep --newuse --update --verbose @world

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

Now add -*virtual/modutils to /etc/portage/profile/packages (create the profile directory and packages file if they don't exist). This removes the virtual/modutils virtual package from the system set.

Then unmerge virtual/modutils and sys-apps/kmod packages:

root #emerge -ac

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

If you previously had a kernel installed with modules, then you'll also want to remove the /lib/modules/<kernel-version> directory. Since you've built your kernel without any loadable modules, there won't be anything useful in there anymore.

When using a genkernel generated initramfs, it may be necessary to add nomodules 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.