lsmod
The lsmod
command in Linux is used to display information about all the currently loaded kernel modules. Kernel modules are pieces of code that can be loaded and unloaded into the kernel upon demand, allowing the kernel to extend its capabilities without the need to reboot the system.
Understanding lsmod
lsmod
The lsmod
command provides a snapshot of the status of modules in the Linux kernel. It formats the contents of /proc/modules
, which is the file that contains information about the modules that are currently loaded into the kernel.
Basic Usage
To display the currently loaded kernel modules, simply run:
The output typically includes three columns:
Module: The name of the loaded module.
Size: The size of the module in bytes.
Used by: The number of instances that refer to this module and a list of referring modules.
Example Output
Here’s an example of what the lsmod
command might return:
Explanation of the Output
Module: The name of the module. For example,
nf_conntrack_netbios_ns
.Size: The size of the module. For example,
16384
bytes.Used by: The number of instances using this module and other modules dependent on it. For example,
nf_conntrack_broadcast
usesnf_conntrack_netbios_ns
.
Practical Examples
List All Loaded Modules:
This command lists all the currently loaded modules with their size and dependencies.
Check if a Specific Module is Loaded: If you want to check if a specific module, say
ext4
, is loaded, you can filter the output:If the module is loaded, you will see an output line corresponding to it. If not, there will be no output.
Interpreting Dependencies: To understand which modules depend on another module, look at the
Used by
column. For example:This shows that
nf_nat_ftp
is used bynf_nat
.
Related Commands
modprobe: Used to add or remove modules from the Linux kernel.
To load a module:
To remove a module:
insmod: Used to insert a module into the kernel.
rmmod: Used to remove a module from the kernel.
modinfo: Displays information about a kernel module.
Conclusion
The lsmod
command is a powerful tool for viewing the status of kernel modules in your system. It is essential for troubleshooting and managing the kernel’s functionality. Understanding how to use lsmod
along with related commands like modprobe
, insmod
, and rmmod
allows you to effectively manage kernel modules and optimize your Linux system.
Feel free to ask for more details or examples about other Linux commands or concepts!
Last updated