A kernel module is a piece of object code that can be loaded into and unloaded from the running Linux kernel on demand, extending its functionality without recompiling the kernel or rebooting the system. Also called a loadable kernel module (LKM), it typically provides a device driver, a file system, a network protocol or a security feature, and it executes in kernel space with full privileges.
Modules are one of the core ideas in Linux fundamentals because they explain how a single generic kernel shipped by a distribution can support thousands of different hardware combinations. The kernel image stays relatively small, and only the code a machine actually needs is loaded, either automatically at boot or manually by an administrator.
How a kernel module is loaded and linked
A kernel module is loaded by linking a relocatable ELF object with the .ko extension into the address space of the running kernel. The init_module or finit_module system call passes the file to the kernel, which resolves the module’s unresolved symbols against the exported kernel symbol table, allocates memory, applies relocations and then calls the module’s initialization function.
Every module declares an entry point with module_init() and an exit point with module_exit(). The init function registers the services the module offers, for example a driver for a PCI device ID, and the exit function unregisters everything and frees resources before removal. If initialization returns an error, the kernel discards the module immediately.
Modules can only call kernel functions that are explicitly exported with EXPORT_SYMBOL or EXPORT_SYMBOL_GPL. The second form restricts a symbol to modules that declare a GPL-compatible license, which is how the kernel separates its stable internal interfaces from code that proprietary modules may use.
The following table summarizes the main stages of a module’s lifetime and the components involved in each one.
| Stage | What happens | Main component |
|---|---|---|
| Build | Source compiled against kernel headers into a .ko file | Kbuild and kernel headers |
| Discovery | Device or alias triggers a module request | udev and modalias strings |
| Dependency resolution | Required modules are loaded first | modprobe and modules.dep |
| Load and link | Symbols resolved, relocations applied | finit_module system call |
| Initialization | Driver or feature registered | module_init function |
| Removal | Resources released, code unmapped | module_exit and delete_module |
Tools for managing kernel modules
Administrators manage modules with the kmod utility suite, which replaced the older module-init-tools package. The most important command is modprobe, because it reads the dependency map in modules.dep and loads or removes a module together with everything it requires, whereas insmod and rmmod act on a single file without any dependency handling.
The table below compares the standard commands and the situations in which each is appropriate.
| Command | Purpose | Typical use |
|---|---|---|
| lsmod | Lists loaded modules and use counts | Checking which drivers are active |
| modinfo | Shows license, parameters and aliases | Inspecting a module before loading |
| modprobe | Loads a module with its dependencies | Normal loading by administrators |
| modprobe -r | Removes a module and unused dependencies | Unloading a driver safely |
| insmod | Loads one file by path, no dependencies | Testing a freshly built module |
| rmmod | Removes one module by name | Development and debugging |
| depmod | Rebuilds modules.dep and alias maps | After installing new modules |
Persistent behavior is configured through files rather than commands. Entries in /etc/modprobe.d/ set module parameters, define aliases or block a module with a blacklist line, and files in /etc/modules-load.d/ list modules that systemd loads at every boot. Loaded modules and their parameters appear under /sys/module/, which is the authoritative runtime view of the module state.
Kernel modules compared with built-in code
A feature in the Linux kernel can be compiled either as a module or directly into the kernel image, and the choice is made per option in the kernel configuration, where m means module and y means built in. Functionally the code is the same; the difference lies in when it becomes available and how flexibly it can be managed.
The comparison below shows why distributions build most drivers as modules while keeping a small core built in.
| Property | Loadable module | Built-in code |
|---|---|---|
| Availability | After the module is loaded | From the first moment of boot |
| Memory use | Only when needed | Always resident |
| Updating | Replace and reload without reboot in many cases | Requires a new kernel and reboot |
| Parameters | Set at load time or via sysfs | Set on the kernel command line |
| Root file system support | Needs an initramfs | Works without an initramfs |
| Attack surface | Can grow at runtime | Fixed at build time |
Drivers for the storage controller and root file system are the classic dilemma. If they are modules, the bootloader must also load an initramfs that contains them, because the kernel cannot read modules from a disk it cannot yet access.
Versioning, signing and security
A kernel module is tied to the exact kernel version it was built for. Each module carries a vermagic string, and with CONFIG_MODVERSIONS enabled it also stores CRC checksums of every symbol it uses, so the loader refuses a module whose interface assumptions no longer match. Linux deliberately offers no stable in-kernel ABI, which is why out-of-tree modules must be rebuilt for every kernel update.
Frameworks such as DKMS (Dynamic Kernel Module Support) automate that rebuild by compiling registered module sources whenever a new kernel is installed. This is the usual delivery method for third-party graphics drivers, virtualization guest additions and some file system drivers.
Because module code runs with unrestricted kernel privileges, loading one is equivalent to granting full control of the machine. Module signature verification with CONFIG_MODULE_SIG lets the kernel reject unsigned modules, and on systems with UEFI Secure Boot many distributions enforce it through kernel lockdown. Setting kernel.modules_disabled to 1 prevents any further loading until the next reboot, which is a useful hardening step on servers with a fixed hardware profile.
Loading a module with a non-GPL license or without a valid signature sets a taint flag visible in /proc/sys/kernel/tainted. Kernel developers usually decline to debug crashes on a tainted kernel, because the proprietary code cannot be inspected.
Common problems and how to resolve them
Most module failures trace back to version mismatches, missing dependencies or policy restrictions, and the kernel log shown by dmesg or journalctl -k usually names the cause precisely. The table lists frequent symptoms with their typical causes and remedies.
| Symptom | Likely cause | Remedy |
|---|---|---|
| Invalid module format | Built for a different kernel version | Rebuild against current headers |
| Unknown symbol in module | Dependency not loaded or symbol not exported | Use modprobe, check license |
| Key was rejected by service | Unsigned module under Secure Boot | Sign the module or enroll a key |
| Module is in use | Nonzero reference count | Stop the dependent service first |
| Device works after manual load only | Missing alias or blacklisted | Review modprobe.d configuration |
| Boot fails after update | Storage driver absent from initramfs | Regenerate the initramfs |
A frequent misconception is that removing a module is always safe. A bug in module code can crash the entire system with a kernel panic or corrupt memory silently, since there is no isolation between modules and the rest of the kernel. For that reason, production systems should load only vendor-supported or well-audited modules.
Put simply
Think of the Linux kernel as the engine of the operating system. A kernel module is an add-on part that can be attached to the engine while it is running. When a new printer, network card or disk format appears, the system attaches the matching part, and when it is no longer needed, the part can be removed.
This keeps the core small and adaptable. The trade-off is trust: an add-on part works inside the engine itself, so a faulty or malicious module can break the whole system, which is why modern systems often accept only signed modules.
In practice
A systems administrator runs a fleet of virtualization hosts on a long-term-support Linux distribution and needs a third-party network driver for new 25 GbE adapters that the stock kernel does not support well. The vendor ships the driver as source code registered with DKMS, so each kernel update triggers an automatic rebuild of the .ko file.
Because the hosts use UEFI Secure Boot, the administrator generates a signing key, enrolls it with the machine owner key utility and configures DKMS to sign every rebuilt module. A file in /etc/modprobe.d/ blacklists the older in-tree driver, and the initramfs is regenerated so the correct module loads at boot.
After a staged rollout across 40 hosts, every server boots with the signed driver loaded automatically, lsmod confirms the expected module, and later kernel updates proceed without manual rebuilding or network outages.