Linux lsmod Command with Practical Examples

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn about the Linux lsmod command and its practical applications. The lab covers the purpose of the lsmod command, which is used to display information about the kernel modules currently loaded on the system. You will explore the output of the lsmod command and understand how to interpret the information it provides, such as the name, size, and usage of the loaded kernel modules. Additionally, you will learn how to load and unload kernel modules as needed. This lab is designed to help you better manage and troubleshoot the kernel modules on your Linux system.

Linux Commands Cheat Sheet


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/TextProcessingGroup(["`Text Processing`"]) linux/TextProcessingGroup -.-> linux/grep("`Pattern Searching`") subgraph Lab Skills linux/grep -.-> lab-422780{{"`Linux lsmod Command with Practical Examples`"}} end

Understand the Purpose of lsmod Command

In this step, you will learn about the purpose of the lsmod command in Linux. The lsmod command is used to display information about the kernel modules that are currently loaded on the system.

Kernel modules are pieces of code that can be loaded and unloaded into the kernel as needed, providing additional functionality to the operating system. The lsmod command allows you to see which kernel modules are currently active and in use.

To run the lsmod command, simply execute the following in your terminal:

$ sudo lsmod

Example output:

Module                  Size  Used by
vboxguest              453376  0
vboxsf                  86016  1

The output shows the name of each loaded kernel module, the size of the module in bytes, and the number of other modules that are using this module.

In the example output, we can see that the vboxguest and vboxsf modules are currently loaded. These modules are likely related to the VirtualBox guest additions, which provide additional functionality for a VirtualBox virtual machine.

By understanding the purpose of the lsmod command, you can better manage and troubleshoot the kernel modules on your Linux system.

Explore the Output of lsmod Command

In this step, you will learn how to interpret the output of the lsmod command and understand the information it provides about the loaded kernel modules.

Let's start by running the lsmod command again:

$ sudo lsmod

Example output:

Module                  Size  Used by
vboxguest              453376  0
vboxsf                  86016  1

The output of the lsmod command consists of three columns:

  1. Module: The name of the kernel module.
  2. Size: The size of the kernel module in bytes.
  3. Used by: The number of other kernel modules that are using this module.

In the example output, we can see that the vboxguest and vboxsf modules are loaded. The vboxguest module has a size of 453,376 bytes and is not being used by any other modules. The vboxsf module has a size of 86,016 bytes and is being used by 1 other module.

The "Used by" column can help you understand the dependencies between different kernel modules. If a module has a non-zero value in the "Used by" column, it means that other modules are relying on the functionality provided by this module.

Understanding the output of the lsmod command can be helpful when troubleshooting issues related to kernel modules or when trying to optimize the performance of your Linux system.

Load and Unload Kernel Modules

In this step, you will learn how to manually load and unload kernel modules on your Linux system.

Loading a Kernel Module

To load a kernel module, you can use the modprobe command. Let's try loading the vboxguest module, which we saw in the previous steps:

$ sudo modprobe vboxguest

After running this command, you can verify that the vboxguest module is now loaded by running the lsmod command:

$ sudo lsmod | grep vboxguest
vboxguest              453376  0

Unloading a Kernel Module

To unload a kernel module, you can use the modprobe -r command. Let's try unloading the vboxguest module:

$ sudo modprobe -r vboxguest

Now, if you run the lsmod command again, you should no longer see the vboxguest module in the output.

$ sudo lsmod | grep vboxguest
## (no output)

By using the modprobe and modprobe -r commands, you can manually load and unload kernel modules as needed, depending on the requirements of your system.

Summary

In this lab, you first learned about the purpose of the lsmod command, which is used to display information about the kernel modules currently loaded on the system. You then explored the output of the lsmod command, understanding that it provides the name, size, and usage information for each loaded kernel module. Finally, you covered the process of loading and unloading kernel modules using the modprobe and rmmod commands.

Linux Commands Cheat Sheet

Other Linux Tutorials you may like