How to Use rmmod Command in Linux

Wondering how to use the rmmod command in Linux?

Whenever we install applications in our system, various modules are installed with it. However, there are times when two or more redundant modules are installed that don’t serve any purpose. 

In such situations, the rmmod command comes into play by allowing you to remove modules from the kernel. If you’re wondering how to use the rmmod command in Linux, then you’ve come to the right place.

By the end of this guide, you’ll have a firm grasp of the proper usage of the rmmod command.

So without further ado, let’s begin!

The rmmod Command.

On Linux distributions, the “remove module” or rmmod command unloads or removes any given module(s) from the kernel.

This command is part of the modprobe program, which adds or removes a module from said kernel. Developed by Rusty Russell, most users use the modprobe with the -r option enabled, as it removes modules without affecting any dependencies.

Now that we have enough elementary knowledge of what a module does, let us dive into its operation as a command.

Here is the general syntax for the rmmod command:

$ rmmod <flags> <module name>

Here is the syntax you use if you want to remove multiple modules altogether:

$ rmmod <module1> <module2>

This is the go-to command in case we know the module we want to unload. However, knowing the multiplexing structure of an OS, we may not know the module we wish to unload or remove. In that case, we use the lsmod command to display all the modules loaded in our system.

$ lsmod
used

Once we have the desired module we want to remove, we use the rmmod command as demonstrated below:

$ sudo rmmod rapl

Where rapl is the module to unload. Once removed, we can cross-check to see if the module has been removed by using the lsmod command again.

The rmmod command dictates that this module will not be used by the system until the next bootup.

rapl

As we can see, the rapl module has been successfully unloaded.

It should be noted that the rmmod command is restricted to keep a module if it is being referred to by other modules. Attempt to remove that module, and we get an error stating the following:

Rmmod: ERROR: Module<modulename1> is in use by: <modulename2>

It is strongly advised not to remove modules that refer to other modules, as this can disrupt functionality in other unknown parts of your system.

Various Options for rmmod Command.

The rmmod command features various options which, when invoked, run the command in several ways for various tasks. These options can be explored by typing in the command.

$ rmmod --help
Rmmod Command in Linux

Other notable options are also described below with their role and application.

-f,–force.

Used to force the removal operation. It can be implemented if CONFIG_MODULE_FORCE_UNLOAD is set. This is an extremely detrimental operation for the system, and caution must be exercised before proceeding. Remember what we said about removing modules that are being referenced by other modules!

libahci

-s,–syslog.

Instead of the standard error, this option sends an error to syslog.

Rmmod Command in Linux

-v,–verbose.

Describes deets regarding what a program is doing. Rmmod will give an error in case something was done wrong.

Rmmod Command in Linux

-V,–version.

Simply displays the version of the rmmod or the loaded module.

Rmmod Command in Linux

-w,–wait.

Isolates the module under observation till it is no longer in use to remove it. After this command is issued, new files cannot use the module that was isolated.

Rmmod Command in Linux

Learning about the options is necessary to learn how to use the rmmod command in Linux. With this, you can proceed to the advanced use of the command.

To Permanently Remove Modules.

To remove a module permanently, we type in the following command:

$ sudo rmmod /libmodule / 5.11.0-25-generic/kernel/sound/libahci.ko

Here, .ko is the object file, which is the kernel provider, 5.11.0-25 is the kernel version. You can check the kernel version using the uname -r command. Finally, libahci is the module we need to unload.

We can also permanently unload a module by typing the following command:

$ /etc/modprobe.d/blacklist.conf

Followed by.

$ black-list [modulename]

This set of commands will permanently remove the libahci module from our system. As a consequence, any other modules depending on this module will cease functionality permanently.

This is why it is strongly recommended that you don’t permanently remove a module unless you are absolutely sure. Misusing this command can result in random disruption of modules, which may crash certain parts of your system.

The rmmod command unloads a module temporarily till the next bootup, but if you force the wrong module to unload, that can also cause a chain of horrendous events at the backend of your system, that’s why rmmod command is not directly permitted for use. The operation is permitted by using sudo and the administrator’s permission.

Given below are some commands related to rmmod.

  • Depmod: can generate map files and kernel dependencies.
  • Insmod: used when we need to insert modules in the kernel. Its operation can be regarded as opposite to rmmod.
  • Lsmod: shows all active modules after boot-up and their storage consumption.
  • Modinfo: displays info of kernel modules.

Like many commands, rmmod is a Linux command that facilitates the removal of modules. However, using modprobe -r is highly recommended as it will remove modules without breaking any dependencies. You can get further details regarding the functionality of rmmod command by heading to its main page.

Speaking of commands, if you wish to look into the libraries your applications use and their roles, you can look it up in our guide on how to use the LDD command on Linux.

We hope this guide helped you learn how to use the Rmmod command in Linux. If you have any questions or suggestions, feel free to let us know in the comment section below.

If this guide helped you, please share it. 🙂

Author

Leave a Reply

Your email address will not be published. Required fields are marked *