Kernel Modules

Kernel modules are object files that contain code to extend the kernel of 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 DVB stick).
 * Allows easy reloading of kernel drivers in case of module crash.
 * Allows specifying 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).

Loadable Kernel Modules
Loadable modules can be defined in the file in order to load modules to the kernel during the init process.

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

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:

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 kmod</tt> and the virtual modutils</tt> packages. Because modutils</tt> is part of the @system</tt> set, you'll need to remove it from the @system</tt> set before it can be unmerged.

First, add -kmod</tt> to your USE flags in.

Next, rebuild installed packages without kmod</tt> support:

Follow any special instructions given by rebuilt packages (for example, if udev</tt> was rebuilt, then you'll want to restart it according to the instructions in the emerge</tt> output).

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

Then unmerge modutils</tt> and kmod</tt> packages:

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

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