Introduction
Before we discuss rmmod command in Linux, let's first understand Rmmod Command ?
The rmmod
command in Linux is used to remove (unload) dynamically loaded kernel modules. Kernel modules are pieces of code that can be dynamically loaded or unloaded into the running Linux kernel to provide additional functionality or device drivers.
The Linux kernel is the foundation of every Linux operating system. It maintains the system's resources and serves as a link between the hardware and software on the computer.
In this tutorial, you will remove modules from the Linux kernel using the rmmod
command. We will also address a few FAQs on rmmod command in Linux.
rmmod
Command
The rmmod
(remove module) command has the following general syntax:
rmmod [OPTIONS] MODULE_NAME...
rmmod
is part of kmod
, a binary that provides numerous applications for managing Linux kernel modules on current Linux systems.
Modules can only be removed by users with administrator privileges.
The lsmod
command prints a list of all modules loaded on your system. The Kernel modules are located in the /lib/modules/<kernel_version>
folder.
It's easy to remove a module with the rmmod
command, simply type the command followed by the module name:
rmmod module_name
Only if something goes wrong, the command prints a message. If the module is used by another module, the command will print something like this:
Use the -v
(--verbose
) option to see more information about what the command is doing.
If you want to delete a module that is currently in use or was not intended to be removed, use the -f
(--verbose
) option. Using this option is extremely risky, as it may result in a system crash.
Multiple modules can be passed to rmmod
as arguments:
rmmod module_name1 module_name2
Stop a Kernel Module from Loading During Boot
When you use the rmmod
command to delete a module, it remains unloaded until the system is rebooted. The uninstalled module will be loaded on the next system startup.
Create a .conf
file with any name inside the /etc/modprobe.d
directory to permanently prevent a Kernel module from loading at boot time. The syntax is as follows:
blacklist module_name
If you wish to add more modules to the blacklist, put them to a new line or create a new .conf
file.
FAQs on Rmmod Command in Linux
How does the rmmod
command work in Linux?
When executed, rmmod
first checks if the specified module is currently in use. If not, it unloads the module by removing it from the kernel, freeing up system resources.
How do I use the rmmod
command to remove a kernel module?
To remove a kernel module, use the rmmod
command followed by the module name. For example, rmmod module_name
.
Can I remove multiple modules simultaneously using the rmmod
command?
Yes, you can remove multiple modules simultaneously by specifying the module names separated by spaces. For example, rmmod module1 module2 module3
.
What happens if I try to remove a module that is currently in use?
If you attempt to remove a module that is currently in use, the rmmod
command will display an error message indicating that the module is in use and cannot be unloaded.
How can I check if a module is currently in use before removing it?
To check if a module is currently in use, you can use the lsmod
command, which lists the currently loaded modules. If the module appears in the list, it is in use and cannot be removed with rmmod
.
Is it possible to force the removal of a module using rmmod
?
Yes, you can force the removal of a module by using the --force
or -f
option with the rmmod
command. However, it is generally not recommended to force removal unless you understand the potential consequences.
Can I use rmmod
to remove a module permanently?
No, the rmmod
command removes a module temporarily from the current running kernel session. To permanently remove a module, you may need to update boot configurations or blacklist the module.
Conclusion
The rmmod
command is used to delete Linux kernel modules. Most Linux users prefer the modprobe -r
command over rmmod
.
If you have any queries, please leave a comment below and we’ll be happy to respond to them.