Load Linux Kernel Modules with insmod and modprobe
Learn how Linux kernel modules work, how to load them with insmod and modprobe, inspect dependencies, use parameters, verify loading, troubleshoot errors, and configure boot-time loading.
A kernel module is a loadable piece of functionality that extends the running Linux kernel without rebuilding or rebooting the kernel. Modules are commonly used for hardware drivers, filesystems, networking features, and other optional kernel capabilities. They are also called loadable kernel modules or LKMs.
Linux and its device-management services often load required modules automatically. Manual loading is mainly useful when testing a driver or filesystem, temporarily enabling a feature, troubleshooting hardware, or supporting unusual hardware and storage requirements.
Installed modules are normally organized beneath /lib/modules/$(uname -r)/, where $(uname -r) expands to the release of the currently running kernel. For related filesystem concepts, see Linux file structure.
Check the Running Kernel and Module Availability
A module must be built for, and installed for, the kernel that is currently running. First identify that kernel:
uname -r
Use modinfo when you know the logical module name:
modinfo loop
modinfo -n loop
modinfo displays metadata for an installed module. The -n option prints the associated module filename. You can also search the module tree directly:
find /lib/modules/$(uname -r) -type f -name 'loop.ko*'
A module filename commonly ends in .ko. Distribution packages may compress module files, producing names such as .ko.xz, .ko.gz, or .ko.zst. The filename is not the same thing as the logical module name supplied to modprobe: normally omit the directory and .ko suffix when using modprobe.
Load a Module with insmod
insmod is a low-level insertion command. It accepts an explicit path to a module file:
sudo insmod /path/to/module.ko
Root privileges are normally required because inserting kernel code changes the running kernel. A module can accept parameters as additional arguments:
sudo insmod /path/to/module.ko parameter=value
The parameter must actually be supported by that module. Discover supported parameters with modinfo -p MODULE_NAME.
insmod does not automatically resolve or load prerequisite modules. Consequently, insertion can fail even when the target file exists. It is most useful for direct testing or controlled, low-level workflows. Routine administration normally uses modprobe.
For example, you can obtain a path and pass it to insmod:
module_path=$(modinfo -n loop)
sudo insmod "$module_path"
This is not a useful normal workflow if loop is already loaded, and it can fail if required dependencies are not loaded. Module-management tools and distributions may also handle compressed module files differently, so prefer modprobe for installed modules.
Load a Module with modprobe
modprobe is the usual command for loading installed modules. It takes a logical module name, not a path:
sudo modprobe loop
It consults dependency metadata and modprobe configuration, then loads prerequisite modules before loading the requested module. Dependency information is maintained in files such as modules.dep. The depmod command generates or refreshes this metadata.
Module names commonly use underscores, while command-line forms often accept hyphens as equivalent. For example, a module named example_module may also be addressed as example-module. Use the name reported by modinfo when there is uncertainty.
| Command | Primary purpose | Input form | Automatically resolves dependencies | Uses modprobe configuration | Typical use |
|---|---|---|---|---|---|
insmod | Insert one module file | Explicit path | No | No | Low-level testing |
modprobe | Load or remove installed modules | Logical module name | Yes | Yes | Routine administration |
rmmod | Remove one loaded module | Logical module name | No dependency-aware cleanup | No | Low-level removal |
The relationship is:
insmodreceives a file path and attempts direct insertion.modprobereceives a module name, reads dependency and configuration metadata, and performs the required insertion actions.
Inspect Module Metadata and Dependencies
Module metadata describes the code and how it can be used:
modinfo MODULE_NAME
modinfo -p MODULE_NAME
modinfo -n MODULE_NAME
Depending on the module, modinfo can show its filename, description, license, aliases, parameters, kernel-version information, and declared dependencies. The -p option lists supported parameters.
To see the dependency-related actions that modprobe would process, use:
modprobe --show-depends overlay
This output helps explain which prerequisite modules are needed and can reveal why a module cannot be loaded. It is especially useful when comparing a direct insmod attempt with dependency-aware loading.
Use Dry-Run and Verbose Modes
A dry run simulates module handling without changing the running kernel. The -n or --dry-run option performs resolution checks without inserting modules. The -v or --verbose option displays actions taken or planned.
sudo modprobe -n -v overlay
Combining these options is a safe way to preview dependency resolution and the commands that would be used. The exact output varies by distribution and module state. --show-depends focuses on dependency actions and is useful alongside the dry run.
Verify That a Module Is Loaded
Use lsmod to list modules currently loaded into the kernel:
lsmod
lsmod | grep '^loop'
For a shell pipeline that remains successful when no match is found:
lsmod | grep '^loop' || true
The kernel exposes equivalent module state through /proc/modules:
cat /proc/modules
A successful modprobe command confirms that insertion did not report an error, but it does not prove that the expected feature works. Also verify the related device, filesystem mount, network interface, service, or application. A driver may load successfully without binding to any hardware.
Module Parameters
A module parameter is a module-specific setting supplied when the module is loaded. Names and accepted values vary by module and kernel version. Discover parameters before using them:
modinfo -p MODULE_NAME
Supply a temporary option with modprobe:
sudo modprobe MODULE_NAME parameter=value
Or pass it to insmod when inserting a file directly:
sudo insmod /path/to/MODULE_NAME.ko parameter=value
Do not assume that an illustrative name such as example_module or option_name exists on every system. Replace it with a module and parameter reported by modinfo -p. Parameters supplied on the command line are temporary: they apply to that load and normally disappear after reboot or removal.
Remove Modules Safely
Use dependency-aware removal for normal administration:
sudo modprobe -r loop
lsmod | grep '^loop' || true
modprobe -r removes the requested module and attempts to remove dependencies that are no longer needed. The lower-level alternative is:
sudo rmmod MODULE_NAME
A module cannot be removed while it is in active use, referenced by another loaded module, or marked non-unloadable. It may support a mounted filesystem, device, network interface, or service. Stop dependent services and safely detach consumers before trying again. Removing a driver can interrupt hardware access, so do not remove one from a feature that must remain available.
Load Modules Automatically at Boot
Manually loaded modules normally remain loaded only until reboot. On systems using systemd, place one module name per line in a file under /etc/modules-load.d/:
printf '%s\n' 'example_module' | sudo tee /etc/modules-load.d/example_module.conf
To persist options whenever modprobe loads the module, create a file under /etc/modprobe.d/:
printf '%s\n' 'options example_module option_name=option_value' | sudo tee /etc/modprobe.d/example_module.conf
Use actual module and parameter names from modinfo. Some distributions provide additional legacy or distribution-specific startup mechanisms. Follow the active distribution's documented method rather than adding multiple competing configurations.
Test persistence without immediately rebooting by loading the module manually, checking the configuration syntax and file contents, and reviewing kernel or service logs. A reboot or restart of the distribution's module-loading service can provide final validation when appropriate; test on systems where interrupting the feature is safe.
| Need | Temporary method | Persistent location | Notes |
|---|---|---|---|
| Load a module | sudo modprobe MODULE_NAME | /etc/modules-load.d/*.conf | One logical module name per line |
| Pass an option | sudo modprobe MODULE_NAME parameter=value | /etc/modprobe.d/*.conf | Use an options line |
| Prevent automatic loading | Remove or unload the module when safe | /etc/modprobe.d/blacklist-MODULE_NAME.conf | Use blacklist MODULE_NAME; this targets automatic discovery and is not a universal block against explicit forced loading |
Module Loading Policy and Safety
Loading kernel code affects the running kernel and requires administrative privileges. Use only trusted, compatible modules from appropriate distribution packages or a controlled build process. A faulty or malicious module can crash the system, expose data, or compromise the kernel.
Secure Boot, kernel lockdown, and module signature enforcement can reject unsigned or untrusted modules. Review the system policy before installing an external driver. If a module should not be selected automatically, a modprobe blacklist rule can help:
printf '%s\n' 'blacklist MODULE_NAME' | sudo tee /etc/modprobe.d/blacklist-MODULE_NAME.conf
Blacklisting generally prevents automatic alias-based loading; it does not necessarily prevent every explicit loading method or every distribution-specific early-boot mechanism. Review the complete boot and driver configuration when a module continues to appear.
Troubleshoot Failed Module Loads
Start with the active kernel, module metadata, dependency plan, and kernel messages:
uname -r
modinfo MODULE_NAME
sudo modprobe -n -v MODULE_NAME
sudo modprobe MODULE_NAME
dmesg | tail -n 50
journalctl -k -n 50 --no-pager
dmesg reads the kernel message buffer. journalctl -k queries kernel messages stored by the system journal. These messages often contain the specific reason hidden behind a short command-line error.
| Symptom or error | Likely cause | Verification command | Typical resolution |
|---|---|---|---|
| Module not found | Wrong name, missing package for the active kernel, or stale metadata | uname -r, modinfo MODULE_NAME, find /lib/modules/$(uname -r) | Install the matching modules package, correct the name, refresh with sudo depmod -a, or boot the intended kernel |
| Invalid module format or version mismatch | Module was built for a different kernel release or configuration | uname -r, modinfo MODULE_NAME, journalctl -k | Install or rebuild the module for the exact running kernel |
| Unknown or unresolved symbol | Missing or incompatible dependency, or incompatible external module | modprobe --show-depends MODULE_NAME, journalctl -k | Install compatible dependencies or rebuild the external module |
| Permission denied, operation not permitted, or key rejection | Insufficient privileges, Secure Boot, lockdown, or signature enforcement | Use sudo; inspect journalctl -k | Use administrative access and install or sign a trusted module according to system policy |
| Module already loaded | The requested module is already present | lsmod | grep '^MODULE_NAME' | Verify its state; unload and reload only when safe and necessary |
| Module cannot be removed | Active use, dependent modules, mounts, devices, or services | lsmod; inspect active mounts and services | Stop consumers and remove dependents first, or leave the module loaded |
| Module loads but hardware does not work | No matching device, missing firmware, competing driver, or missing userspace configuration | journalctl -k, lspci, lsusb, modinfo MODULE_NAME | Install firmware, select the correct driver, resolve conflicts, and configure userspace |
Common Command Reference
| Command or option | Meaning | Example use | Expected result |
|---|---|---|---|
modprobe MODULE | Load a module and dependencies | sudo modprobe loop | Module and prerequisites are inserted if available |
modprobe -n | Dry run | sudo modprobe -n loop | Checks actions without insertion |
modprobe -v | Verbose output | sudo modprobe -n -v loop | Shows planned or performed actions |
modprobe --show-depends | Display dependency actions | modprobe --show-depends overlay | Lists prerequisite-related operations |
modprobe -r MODULE | Dependency-aware removal | sudo modprobe -r loop | Removes the module when unused |
modinfo MODULE | Show metadata | modinfo loop | Displays filename, aliases, license, dependencies, and more |
modinfo -p MODULE | Show parameters | modinfo -p MODULE_NAME | Lists supported module settings |
lsmod | List loaded modules | lsmod | Shows loaded names, sizes, and use information |
depmod -a | Refresh dependency metadata | sudo depmod -a | Regenerates metadata for installed modules |
For broader command-line practice, see Linux command-line topics and show the full path of shell commands.