Linux Commands

Linux Kmod Command

The kmod is a set of Linux programs for inserting, loading, and removing the kernel modules. When using it and it happens that the kernel is trying to access a specific resource that it finds unavailable, it makes a request to the kmod rather than returning an error. When invoked, the kmod attempts to fetch the needed resource, make it available, and resumes the operations. If the kmod can’t locate the modules, it returns an error.

This guide covers the basic usage of the kmod tool from the installation to the available options.

Installing the Kmod Package

The latest Linux systems come with the pre-installed kmod package. Nonetheless, if you need to install the package, you can use the apt or apt-get commands.

To install kmod using the apt-get, run the following commands:

$ sudo apt-get update
$ sudo apt-get install -y kmod

The previous commands update the apt database and install the kmod package.

To install kmod using apt, run the following commands:

$ sudo apt update
$ sudo apt install -y kmod

Similarly, you can uninstall kmod using either of the following commands:

To only remove the package, use this command:

$ sudo apt-get remove kmod

To uninstall kmod and its dependencies, use this command:

$ sudo apt-get -y autoremove kmod

If you need to remove kmod and its configurations and data, use this command:

$ sudo apt-get -y purge kmod

Alternatively, the following command uninstalls kmod and all its configurations, data, and dependencies:

$ sudo apt-get -y autoremove --purge kmod

How to Use the Kmod Linux Package

The kmod has only a few commands and options.

Its basic syntax is:

$ kmod [OPTIONS] [COMMAND] [COMMAND_OPTIONS]

There are two options available:

1. To get the help message, use the –help or -h option.

$ kmod --help

2. To check the version of kmod, use the -V or –version.

$ kmod --version

Kmod implements the programs that control the Linux kernel modules and uses two commands listed in the following examples:

1. List
To view all the modules currently loaded in the system.

From the previous output you can note the different modules loaded. On the right side, it lists the module name followed by the size of the module. Next, it shows the name of the process using the specific module.

You can search for a specific module from the list using the commands like grep. For instance, to search a module named kvm, we can use the following command:

$ kmod list | grep “kvm”

In the following output, you will note that we filtered the output using grep.

You can also combine the other commands to save the output on a file using the cat command as shown in the following. Here, our output file is output1.txt:

$ kmod list | grep “kvm” | cat > output1.txt

The output displays the contents of the output file created while using the kmod command and filtering the specific modules.

2. Static-Modules
It lists the information of static device nodes provided by the running kernel version’s modules.

Your output may differ from the previous example depending on your modules. Similar to the first command, you may combine it with the other commands to achieve the different functionalities. For instance, you can save the output in a file to analyze later.

For this, use the cat command as shown in the following:

$ kmod list | cat > output2.txt

Conclusion

We covered about the Linux kmod command and how to use it to achieve the different functionalities. Besides, we’ve seen its various options and commands and how to combine them with the other options using the different examples. You now have a solid understanding of the kmod Linux command.

About the author

Denis Kariuki

Denis is a Computer Scientist with a passion for Networking and Cyber Security. I love the terminal, and using Linux is a hobby. I am passionate about sharing tips and ideas about Linux and computing.