How to Manage Kernel Modules in Linux

A comprehensive beginner's guide to managing Linux kernel modules using essential commands like modprobe, rmmod, modinfo, and depmod. Covers loading, unloading, and troubleshooting kernel modules with practical examples.

How to Manage Kernel Modules in Linux

Kernel modules are pieces of code that can be loaded and unloaded into the Linux kernel at runtime, extending its functionality without requiring a reboot. Understanding how to manage these modules is essential for Linux system administration, whether you're adding hardware support, troubleshooting driver issues, or optimizing system performance.

Understanding Kernel Modules

Think of kernel modules as plugins for your Linux kernel. They allow you to add features like device drivers, filesystem support, or network protocols without rebuilding the entire kernel. This modular approach keeps the core kernel lightweight while providing flexibility to add functionality as needed.

To see currently loaded modules, use the lsmod command:

$ lsmod
Module                  Size  Used by
snd_hda_intel          49152  3
snd_intel_dspcfg       28672  1 snd_hda_intel
bluetooth             737280  31 btrtl,btmtk,btintel,btbcm,bnep,btusb,rfcomm

This shows the module name, its size in memory, and what's using it.

Essential Module Management Commands

Getting Module Information with modinfo

Before working with any module, use modinfo to gather information about it:

$ modinfo e1000e
filename:       /lib/modules/5.4.0-74-generic/kernel/drivers/net/ethernet/intel/e1000e/e1000e.ko
version:        3.2.6-k
license:        GPL
description:    Intel(R) PRO/1000 Network Driver
author:         Intel Corporation

This command shows the module's location, version, license, and description—crucial information for kernel management tasks.

Loading Modules with modprobe

The modprobe command is your primary tool to manage kernel modules. It automatically handles dependencies, making it safer than manual loading:

$ sudo modprobe bluetooth
$ lsmod | grep bluetooth
bluetooth             737280  31 btrtl,btmtk,btintel,btbcm,bnep,btusb,rfcomm

To load a module with specific parameters:

$ sudo modprobe snd-hda-intel enable=1

Removing Modules with rmmod and modprobe

You can remove modules using either rmmod or modprobe -r. The modprobe approach is generally preferred because it handles dependencies:

$ sudo modprobe -r bluetooth
$ sudo rmmod bluetooth  # Alternative, but doesn't handle dependencies

Note that rmmod will fail if other modules depend on the one you're trying to remove, while modprobe -r attempts to remove dependent modules as well.

Working with Module Dependencies

The depmod command creates a dependency database that modprobe uses to determine which modules to load:

$ sudo depmod -a

Run this command after installing new modules or updating your kernel to ensure the dependency information stays current.

Persistent Module Configuration

To automatically load modules at boot, add them to /etc/modules:

$ echo "bluetooth" | sudo tee -a /etc/modules

For modules that need specific parameters, create configuration files in /etc/modprobe.d/:

$ sudo nano /etc/modprobe.d/audio.conf
options snd-hda-intel enable=1 index=0

Troubleshooting Module Issues

If a module won't load, check the kernel log for error messages:

$ dmesg | grep -i error
$ journalctl -k | grep modulename

To temporarily blacklist problematic modules, add them to /etc/modprobe.d/blacklist.conf:

blacklist problematic_module

What's Next

Now that you understand basic kernel module management, the next step is exploring how to compile custom kernel modules and manage kernel parameters through /proc/sys and sysctl. These skills will give you deeper control over your Linux system's behavior and performance.


Linux+ study resources