rmmod Command: Tutorial & Examples
Removing Linux Kernel Modules
The rmmod command is used to remove a module from the Linux Kernel. A module is a piece of
code that can be added or removed from the kernel on-the-fly without rebooting the system.
Removing unnecessary modules can help in freeing up the system resources and keeping the kernel lean and efficient. This is particularly useful in a server environment where performance and resource utilization are of paramount importance.
How does rmmod work?
rmmod works by taking the name of the module as an argument and removing it from the kernel. However, it can only
remove a module if it's not being used, or if no other modules depend on it.
The command interacts with the /proc filesystem, specifically with
the /proc/modules file which contains a list of all currently loaded modules.
Why is rmmod important?
The rmmod command is a critical tool in the arsenal of a Linux server administrator. It can help in troubleshooting
issues related to kernel modules, and it gives the administrator fine control over the modules loaded in the kernel.
In some cases, a misbehaving or unnecessary module can cause issues like high load
or network failure. In such cases, rmmod can be used to remove the offending module
and resolve the problem.
Examples of rmmod
Here are some examples of how to use the rmmod command:
To remove a module named
modulename, you would use:sudo rmmod modulenameNote that you need to have root privileges to use
rmmod.If you are unsure whether a module is in use or not, you can use the
lsmodcommand to see the status of all loaded modules. Here's how you do it:lsmodThis will give you output like below:
Module Size Used by modulename 16384 0 ...The 'Used by' column shows how many times the module is being used. If it is '0', you can safely remove the module.
To remove a module and all its dependent modules, you can use the
modprobecommand with the-r(or--remove) option:sudo modprobe -r modulenameThis will remove the module
modulenameand all modules that depend on it.
Common difficulties with rmmod
While rmmod is a powerful tool, it should be used with caution. Removing a critical module can render the system
unstable or even unusable. Always make sure you understand what a module does before removing it.
Another common issue is that rmmod can only remove a module if it's not being used, and if no other modules depend on
it. If you try to remove a module which is in use or has dependents, rmmod would fail with an error message.
Remember, rmmod and other such commands give you a lot of power over your system, but with great power comes great
responsibility. Always exercise caution when dealing with kernel modules and always have a backup of your data.
Further Reading
- Understanding the Linux Kernel by Daniel P. Bovet, Marco Cesati (partner link)
- Linux Kernel Programming by Kaiwan N. Billimoria (partner link)
- The Linux Programming Interface by Michael Kerrisk (partner link)
- Linux Kernel Development by Robert Love (partner link)
- Linux for System Administrators by Viorel Rudareanu, Daniil Baturin (partner link)
As an Amazon Associate, I earn from qualifying purchases.