Kernel modules are object files (Documentation Index
Fetch the complete documentation index at: https://mintlify.com/DeelerDev/linux/llms.txt
Use this file to discover all available pages before exploring further.
.ko) that extend the kernel’s functionality without requiring a recompile or reboot. Drivers for hardware, network protocols, and filesystem types are common examples. When the kernel encounters hardware that needs a driver, or when userspace mounts a filesystem, the kernel can load the required module on demand using the modprobe infrastructure.
Built-in vs. modules
When you configure the kernel, each feature can be set toy (built-in), m (module), or n (disabled). Built-in code is always present in the kernel image and has zero load overhead. Modules are compiled into separate .ko files under /lib/modules/<kernel-version>/ and are loaded as needed.
Use built-in (y) for:
- Core subsystems that are always required (scheduler, memory management, virtual filesystem layer)
- Security modules that must be active before userspace starts (SELinux, AppArmor)
- Boot-critical drivers when you are not using an initramfs
m) for:
- Hardware drivers that may not be present on all systems
- Network protocols needed only occasionally
- Filesystems mounted after the root filesystem is up
Listing loaded modules
lsmod reads /proc/modules and displays all currently loaded modules along with their size and reference count:
Used by column shows which other modules depend on a given module. A module with a non-zero Used by count cannot be removed until its dependents are removed first.
Loading modules
modprobe (recommended)
modprobe is the standard tool for loading modules. It reads dependency information from /lib/modules/<version>/modules.dep and automatically loads any prerequisites:
insmod (low-level)
insmod loads a .ko file directly from a path. Unlike modprobe, it does not resolve dependencies automatically:
Prefer
modprobe over insmod for normal use. insmod is mainly useful when testing a module you just compiled before installing it.Removing modules
modprobe -r
modprobe -r removes a module and any modules it loaded that are no longer needed:
rmmod
rmmod removes a single module by name. It will fail if other modules depend on it or if the module’s reference count is greater than zero:
Inspecting module information
modinfo shows metadata embedded in a .ko file:
parm lines list configurable module parameters with their types and descriptions.
Module parameters
Parameters let you configure a module’s behavior when loading it. They can be passed on themodprobe command line or set permanently in a configuration file.
Passing parameters at load time
Setting parameters permanently
Create a file under/etc/modprobe.d/ with an options directive:
options line in /etc/modprobe.d/*.conf is applied automatically whenever the named module is loaded.
Viewing parameters at runtime
After a module is loaded, its parameters appear as files under/sys/module/<name>/parameters/:
Automatic loading at boot
/etc/modules-load.d/
To load a module at every boot, create a.conf file in /etc/modules-load.d/ containing the module name:
systemd-modules-load.service processes these files during early boot before most services start.
Aliases and automatic loading
The kernel uses aliases in/lib/modules/<version>/modules.alias to map hardware IDs to module names. When the kernel detects hardware (via PCI, USB, or other buses), it generates a modalias string and passes it to udevd, which calls modprobe automatically.
You can check what module a device needs:
Module signing for Secure Boot
Systems with Secure Boot enforce that only signed kernel modules can load. The kernel optionCONFIG_MODULE_SIG enables signature verification; CONFIG_MODULE_SIG_FORCE makes it mandatory (unsigned modules are rejected).
For distribution kernels, check your distro’s documentation. Debian, Ubuntu, and Fedora each have their own module signing workflows integrated with DKMS.
Building out-of-tree modules
Out-of-tree (external) modules are built against the headers of an installed kernel without needing the full source tree. This is how third-party drivers (GPU drivers, VirtualBox additions, DKMS packages) work.Basic out-of-tree build
You need aKbuild or Makefile that declares the module:
-f option:
