lsmod Command in Linux: List and Inspect Kernel Modules
Learn lsmod command in linux with syntax, essential flags, practical terminal examples, real-world sysadmin workflows, security tips, and troubleshooting.
10 min read
Learn lsmod command in linux with syntax, essential flags, practical terminal examples, real-world sysadmin workflows, security tips, and troubleshooting.
- What lsmod Does and When to Use It
- Availability and Installation Across Linux Distributions
- Command Syntax, Arguments, and Exit Status Codes
The lsmod command in linux is the fundamental administrative utility for inspecting loaded kernel drivers and dynamically attached operating system extensions. The Linux kernel uses a modular architecture: rather than compiling every conceivable hardware driver, filesystem, cryptographic cipher, and network protocol directly into a massive monolithic kernel image (vmlinuz), the kernel dynamically loads Loadable Kernel Modules (LKMs) into memory on demand.
The lsmod command in Linux formats and displays the currently loaded Loadable Kernel Modules (LKMs) from the /proc/modules virtual file. It outputs a three-column table detailing each active module name, its memory footprint in bytes, its active usage reference count, and a list of dependent kernel modules or processes utilizing it.
Maintained within the essential kmod package, lsmod provides a clean, human-readable summary of the kernel's active module table. It queries the kernel virtual filesystem at /proc/modules and prints a structured listing showing the module name, the memory size allocated to the module's code and data segments, and the dependency reference count indicating which other kernel modules depend on it.
Whether you are verifying whether an NVIDIA or AMD GPU driver initialized properly, checking if wireguard or iptables network filtering modules are active, auditing device drivers on a cloud server, or troubleshooting why a storage driver refuses to unload, lsmod is the starting point for kernel-level driver diagnostics.
What lsmod Does and When to Use It
At the kernel level, Loadable Kernel Modules execute directly in Ring 0 (supervisor execution space) alongside core kernel subsystems. When a hardware device is plugged in or a specialized networking feature is activated, udevd or modprobe invokes the finit_module(2) or init_module(2) system calls to load the compiled ELF object (typically with a .ko or .ko.zst extension from /lib/modules/$(uname -r)/) into kernel memory space.
The kernel maintains an internal linked list of all loaded modules represented by struct module. Each module structure contains an atomic reference counter (refcnt) tracking how many sub-modules or active kernel subsystems hold open handles to it. The virtual file /proc/modules exposes this internal list in real time. The lsmod binary simply opens /proc/modules, reads the raw whitespace-delimited fields, and formats them into an aligned three-column table without requiring any additional kernel context switches.
Under the hood, lsmod gathers runtime telemetry or dispatches control signals by reading virtual filesystems mounted at /proc and /sys, or by communicating with PID 1 (systemd) over D-Bus. Using flags such as lsmod, modinfo <mod>, modprobe <mod>, modprobe -r <mod> turns raw process and service tables into actionable diagnostics during incident response.
Availability and Installation Across Linux Distributions
The lsmod utility is packaged in kmod across mainstream Linux distributions. It is pre-installed on standard Ubuntu, Debian, RHEL, Rocky Linux, AlmaLinux, Fedora, and Arch Linux systems, while minimal container images may require manual installation:
Before running administrative tasks or automation scripts, verify whether lsmod is installed and inspect which binary path and version your shell resolves:
type -a lsmod
lsmod --version 2>/dev/null || man -f lsmod
# Illustrative output (reviewed against documentation)
lsmod is /usr/bin/lsmod
lsmod (kmod)
# Debian / Ubuntu
sudo apt-get update && sudo apt-get install -y kmod
# RHEL / Rocky / AlmaLinux / Fedora
sudo dnf install -y kmod
# Arch Linux
sudo pacman -S --noconfirm kmod
# Alpine Linux
sudo apk add --no-cache kmod
Command Syntax, Arguments, and Exit Status Codes
lsmod
The syntax for lsmod is remarkably simple: lsmod takes no mandatory flags or complex parameters. Because its sole responsibility is to format and display the active module table from /proc/modules, administrators typically pipe its standard output into standard text processing utilities like grep, awk, sort, or combine it with companion tools such as modinfo.
The output table produced by lsmod consists of three standardized columns: Module (the registered kernel symbol name), Size (the size in bytes occupied in kernel RAM), and Used by (the integer usage reference count, followed by a comma-separated list of dependent module names, or [unsafe] / [permanent] flags indicating unloading constraints).
0— Successful execution; the module table was read and formatted to stdout.1— Operational failure, such as inability to open or read/proc/modules(e.g. inside a severely restricted container).2— Invalid command-line switch passed to the utility.
Important Options and Flags Reference
| Option / Flag | Long Form / Argument | Technical Behavior and Purpose |
|---|---|---|
lsmod | kmod lsmod | Displays the formatted table of all currently loaded Linux kernel modules. |
modinfo <mod> | kmod modinfo | Displays detailed metadata for a module, including author, license, version, and parameters. |
modprobe <mod> | kmod modprobe | Loads a kernel module along with all its declared dependencies from modules.dep. |
modprobe -r <mod> | --remove | Safely unloads a kernel module and any unused dependent modules from memory. |
insmod <file.ko> | kmod insmod | Directly inserts a raw kernel module object file into kernel memory without resolving dependencies. |
rmmod <mod> | kmod rmmod | Unconditionally removes a loaded kernel module from memory if reference count is zero. |
depmod -a | kmod depmod | Scans /lib/modules/$(uname -r) and regenerates modules.dep dependency indexes. |
/proc/modules | Virtual file | The underlying kernel procfs interface that provides raw module telemetry to lsmod. |
Because lsmod is a single-purpose inspection command without operational switches, mastering it involves knowing how to combine it with the rest of the kmod ecosystem. While lsmod tells you what is loaded, modinfo <module> tells you where the module lives on disk, what parameters it accepts, what hardware PCI/USB vendor IDs it binds to, and its open source license.
Similarly, while rmmod attempts to remove a module directly, modprobe -r is the preferred administrative tool because it checks the 'Used by' dependencies displayed in lsmod and cleanly unloads unneeded dependency chains in reverse order.
When combining short flags on the command line, POSIX and GNU utilities allow clustering boolean flags behind a single hyphen, provided any option taking an argument appears last. In automated shell scripts, using long-form GNU options where portable makes self-documenting code that is easier to audit during peer review.
Practical Basic and Advanced Usage Examples
1. List All Loaded Kernel Modules on the System
Execute lsmod to display the formatted table of all active kernel modules currently running in memory.
lsmod | head -n 10
# Illustrative output (reviewed against documentation)
Module Size Used by
overlay 155648 12
ext4 999424 1
crc16 16384 1 ext4
mbcache 16384 1 ext4
jbd2 163840 1 ext4
wireguard 98304 0
ip6_udp_tunnel 16384 1 wireguard
udp_tunnel 20480 1 wireguard
e1000e 311296 0
nvme 53248 3
lsmod lists active modules, their RAM footprint (e.g. ext4 is ~999 KB), and dependencies (ext4 depends on crc16, mbcache, jbd2).
2. Search for a Specific Driver or Subsystem Module
Pipe lsmod output to grep to check if a specific driver (such as KVM virtualization or WireGuard) is loaded.
lsmod | grep -E '^kvm|^wireguard'
# Illustrative output (reviewed against documentation)
kvm_intel 376832 0
kvm 1105920 1 kvm_intel
wireguard 98304 0
The output confirms kvm and kvm_intel are loaded, indicating hardware virtualization acceleration is active for virtual machines.
3. Sort Kernel Modules by Memory Footprint
Use awk and sort to list the top 5 largest kernel modules consuming RAM on the host.
lsmod | awk 'NR>1 {print $2, $1}' | sort -nr | head -n 5
# Illustrative output (reviewed against documentation)
12845056 nvidia
2416640 xfs
1105920 kvm
999424 ext4
843776 btrfs
Extracting the second column (Size in bytes) and sorting numerically highlights which drivers (such as NVIDIA or XFS) occupy the most kernel memory.
4. Inspect Module Metadata and Parameters with modinfo
Use modinfo on a module identified via lsmod to inspect its file location, author, license, and configurable module parameters.
modinfo wireguard
# Illustrative output (reviewed against documentation)
filename: /lib/modules/6.8.0-45-generic/kernel/drivers/net/wireguard.ko.zst
alias: net-pf-16-proto-16-family-wireguard
alias: rtnl-link-wireguard
version: 1.0.0
description: WireGuard secure network tunnel
author: Jason A. Donenfeld <[email protected]>
license: GPL v2
srcversion: 5C1B92D08E20C24B14981C0
depends: udp_tunnel,ip6_udp_tunnel
retpoline: Y
intree: Y
modinfo reveals the compressed file location (.ko.zst), dependency requirements, kernel signature verification, and author credentials.
5. Verify Storage Controller Driver Binding
Check whether NVMe or SCSI storage controller modules are loaded and actively handling root filesystems.
lsmod | grep -E 'nvme|ahci|virtio_blk'
# Illustrative output (reviewed against documentation)
nvme 53248 4
nvme_core 155648 1 nvme
virtio_blk 20480 2
The reference count of 4 on nvme confirms the NVMe storage subsystem has 4 active block devices or controllers registered.
6. Read the Underlying Raw Kernel /proc/modules Interface
Inspect the raw virtual file that lsmod parses to understand the underlying kernel interface.
head -n 3 /proc/modules
# Illustrative output (reviewed against documentation)
overlay 155648 12 - Live 0xffffffffc0850000
ext4 999424 1 - Live 0xffffffffc06a0000
jbd2 163840 1 ext4, Live 0xffffffffc0660000
/proc/modules shows the module name, size, refcount, dependents, module state (Live), and the internal kernel memory address pointer.
Real-World Workflows, Pipelines, and Shell Automation
Auditing Hardware Drivers and Virtualization Modules on Cloud/Bare-Metal Instances
Perform an automated audit of loaded kernel modules during server provisioning to verify security compliance and eliminate unnecessary attack surface.
#!/usr/bin/env bash
set -euo pipefail
echo "=== 1. Kernel Version and Architecture ==="
uname -r -m
echo "=== 2. Auditing Hardware Acceleration and Virtualization ==="
if lsmod | grep -q 'kvm'; then
echo "KVM hardware virtualization modules: LOADED"
else
echo "KVM virtualization modules: NOT LOADED"
fi
echo "=== 3. Auditing Legacy/Vulnerable Filesystem Drivers ==="
RISKY_FS=("cramfs" "freevxfs" "jffs2" "hfs" "hfsplus" "squashfs" "udf")
for FS in "${RISKY_FS[@]}"; do
if lsmod | grep -q "^${FS}"; then
echo "[WARNING] Unnecessary filesystem module loaded: ${FS}"
fi
done
echo "=== 4. Checking Total Number of Loaded LKMs ==="
MODULE_COUNT=$(lsmod | wc -l)
echo "Total active kernel modules: $((MODULE_COUNT - 1))"
# Illustrative output (reviewed against documentation)
=== 1. Kernel Version and Architecture ===
6.8.0-45-generic x86_64
=== 2. Auditing Hardware Acceleration and Virtualization ===
KVM hardware virtualization modules: LOADED
=== 3. Auditing Legacy/Vulnerable Filesystem Drivers ===
=== 4. Checking Total Number of Loaded LKMs ===
Total active kernel modules: 142
Auditing lsmod output against security baselines (such as CIS benchmarks) helps detect unnecessary filesystem drivers that should be blacklisted.
Diagnosing Kernel Module Dependency Locks Preventing Driver Unload
Investigate why a kernel module fails to unload by tracing its dependency graph from lsmod and safely unloading dependent consumers.
#!/usr/bin/env bash
set -euo pipefail
TARGET="br_netfilter"
echo "Checking module status for ${TARGET}..."
LINE=$(lsmod | grep "^${TARGET}" || true)
if [ -z "${LINE}" ]; then
echo "Module ${TARGET} is not currently loaded."
exit 0
fi
REFCOUNT=$(echo "${LINE}" | awk '{print $3}')
DEPENDENTS=$(echo "${LINE}" | awk '{print $4}')
echo "Module: ${TARGET}"
echo "Reference Count: ${REFCOUNT}"
echo "Used by: ${DEPENDENTS:-None}"
if [ "${REFCOUNT}" -gt 0 ]; then
echo "Module is in use. Cannot unload directly. Unload dependents first: ${DEPENDENTS}"
else
echo "Reference count is 0. Attempting safe unload via modprobe -r..."
sudo modprobe -r "${TARGET}"
echo "Successfully unloaded ${TARGET}."
fi
# Illustrative output (reviewed against documentation)
Checking module status for br_netfilter...
Module: br_netfilter
Reference Count: 0
Used by: None
Reference count is 0. Attempting safe unload via modprobe -r...
Successfully unloaded br_netfilter.
Parsing the third and fourth columns of lsmod prevents administrators from blindly running rmmod on modules that still hold active reference locks.
Pipelines, Redirection, Quoting, and Shell Expansion
When embedding lsmod inside shell pipelines (|), conditional chains (&& and ||), or command substitutions ($(...)), the calling shell performs tilde expansion, variable interpolation, and globbing before invoking the binary. Always wrap paths, patterns, and variables in quotes so whitespace and wildcard characters (*, ?) are not expanded prematurely, and use set -euo pipefail in unattended scripts.
Permissions, Security Implications, and Safe Execution
While lsmod is entirely read-only and safe to execute at any time, attempting to unload modules identified in lsmod (using rmmod or modprobe -r) while storage, network, or cryptographic subsystems are active can trigger an immediate kernel panic, system freeze, or network disconnection.
Viewing loaded kernel modules via lsmod can typically be executed by unprivileged users because /proc/modules permissions default to 0444 (readable by all). However, modifying the loaded module set (via modprobe, insmod, or rmmod) requires root credentials and the CAP_SYS_MODULE Linux capability.
On hardened production systems, administrators can prevent unauthorized kernel module loading—a common rootkit persistence technique—by enabling Linux Kernel Lockdown mode (kernel.lockdown=confidentiality) or by permanently disabling module loading after boot by setting the sysctl flag: sudo sysctl kernel.modules_disabled=1. Once set, any attempt to load or unload modules will be rejected by the kernel until the next physical reboot.
GNU/Linux, BSD, and BusyBox Implementation Differences
lsmod is standard across all Linux distributions, provided either by the modern kmod package (in Debian, Ubuntu, RHEL, Fedora, Arch) or as an applet in BusyBox (in Alpine Linux and embedded routers). The output format is identical across all Linux implementations because both read /proc/modules.
Non-Linux Unix platforms manage kernel extensions differently: FreeBSD uses kldstat to list kernel link-state drivers, macOS uses kmutil or kextstat, and Solaris uses modinfo.
Troubleshooting Common Errors and Diagnostics
lsmod: command not found
Root Cause: The kmod package is missing, or /sbin and /usr/sbin are not included in the current user's PATH environment variable.
Resolution: Run /sbin/lsmod with absolute path, export PATH, or install the kmod package.
export PATH=$PATH:/usr/sbin:/sbin
which lsmod || sudo apt-get install -y kmod
rmmod: ERROR: Module is in use by: ...
Root Cause: Attempting to unload a module whose 'Used by' column in lsmod has a reference count greater than 0.
Resolution: Check the dependent modules listed in the third column and unload them first, or stop the services holding open devices.
lsmod | grep <MODULE_NAME>
sudo modprobe -r <DEPENDENT_MODULE>
sudo modprobe -r <MODULE_NAME>
lsmod outputs empty list inside a Docker container
Root Cause: The container is running in an isolated namespace without access to host kernel modules, or /proc/modules is masked by the container security profile.
Resolution: Kernel modules belong to the host kernel; inspect modules on the host node or run the container with privileged flags if driver inspection is required.
# Inspect from host node directly:
ssh user@host 'lsmod'
Alternatives, Related Commands, and Related Tutorials
- How to Create a systemd Service in Linux: Unit File Tutorial — Practical syntax, flags, and examples for
systemd. - List Linux Services with systemctl: Status, Units, and States — Practical syntax, flags, and examples for
systemctl. - systemctl Command in Linux: Start, Stop, Enable, and Manage Services — Practical syntax, flags, and examples for
systemctl. - btop Command in Linux: Modern Terminal Resource Monitor — Practical syntax, flags, and examples for
btop. - 25 Best Linux Commands Every Sysadmin Should Know — Core command-line utilities for daily Linux server administration.
- How to Find a File in Linux from the Command Line — Practical file search patterns across Linux directories.
- Linux Commands Knowledge Hub (#linux-commands) — Browse all Linux command-line tutorials and system administration references.
Authoritative References and Official Documentation

The Linux Command Line, 2nd Edition: A Complete Introduction
Frequently Asked Questions
Quick answers to common questions and configurations
/proc/modules maintained dynamically by the Linux kernel. It simply formats the raw text of /proc/modules into an aligned, human-readable table./etc/modprobe.d/ (e.g. /etc/modprobe.d/blacklist.conf) and add the directive 'blacklist <module_name>' or 'install <module_name> /bin/true'.Editorial Disclosure: Website Vidya is supported by our readers. When you purchase hosting, tools, or software through our verified partner links, we may earn an affiliate commission at no extra cost to you. We only recommend solutions we trust and rigorously verify.
Rajesh Ray
I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.
Most Read Guides
TrendingUbuntu Server Not Booting? 10 Simple Steps to Fix It Fast
How to Create a 3D Button in HTML and CSS: Easy Steps
How to Install Python and Pip on Ubuntu 24.04 LTS
How to Install Nginx on Ubuntu 24.04
How to Install Python on Ubuntu 24.04 LTS
Related Technical Guides
Tested runbooks, server administration walkthroughs, and troubleshooting guides

Join the Conversation & Perspective
Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.
No comments on this guide yet. Be the first to share your thoughts or ask a question!