List and Inspect Kernel Modules with lsmod and modinfo
In this step, you will learn how to list the currently loaded kernel modules and inspect their details. The Linux kernel is modular, meaning parts of its functionality can be loaded or unloaded on demand. These dynamically loadable parts are called kernel modules, and they often correspond to device drivers, filesystem drivers, or system calls.
First, let's view the status of all kernel modules currently loaded into your system's kernel. The lsmod command provides a clean and readable list. Since the list can be quite long, we will pipe its output to the less utility for easy navigation.
Execute the following command in your terminal:
lsmod | less
You will see a list of modules. The output is organized into three columns: Module, Size, and Used by.
- Module: The name of the kernel module.
- Size: The size of the module in bytes.
- Used by: The number of other modules or processes currently using this module, followed by a list of the dependent modules.
Your output will look similar to this:
Module Size Used by
nls_iso8859_1 16384 1
nls_cp437 20480 1
vfat 20480 1
fat 69632 1 vfat
...
You can scroll through the list using the arrow keys. Press q to exit the less viewer and return to the command prompt.
Now that you know how to list modules, let's get detailed information about a specific one. The modinfo command displays various details about a kernel module, such as its filename, license, description, author, and dependencies.
Let's inspect the parport module, which is related to the parallel port.
modinfo parport
The command will display detailed information about the parport module.
filename: /lib/modules/x.x.x-xx-generic/kernel/drivers/parport/parport.ko
license: GPL
description: Parallel port driver
author: Philip Blundell, Tim Waugh, Grant Grundler
srcversion: <some_version_string>
depends:
retpoline: Y
intree: Y
vermagic: x.x.x-xx-generic SMP mod_unload
sig_id: ...
signer: ...
sig_key: ...
sig_hashalgo: ...
signature: ...
This output tells you the exact location of the module file (.ko file), its license, a brief description, and more. Notice the depends field is empty, indicating this module has no dependencies.
Modules often rely on other modules. The depmod command creates a list of module dependencies by analyzing the modules in /lib/modules/$(uname -r). This allows the system to automatically load required modules. Let's generate this dependency file. This command requires root privileges, so we'll use sudo.
sudo depmod
This command typically produces no output upon successful completion. It creates or updates a file named modules.dep in the kernel's module directory. The $(uname -r) part of the path is a command substitution that inserts your current kernel's release version.
Now, let's view the dependency file you just built.
less /lib/modules/$(uname -r)/modules.dep
This file contains a list of modules and their dependencies, which is used by tools that manage modules automatically. You can press q to exit less.