The Linux kernel is the main component of every Linux operating system (OS). It is responsible for managing the system’s resources and the core interface between the computer’s software and hardware.
The Linux kernel is named as such because of its similarities to seed inside a hard shell. The kernel exists within the OS and controls all the primary functions of the hardware, whether it’s a laptop, phone, server, or any other kind of computer.
Linux kernel is software that has a modular design. The kernel module, often called a driver, is a set of code that expands the kernel’s functionality. This module can either be integrated into the kernel or compiled as a loadable module.
There are multiple ways to remove a module, and using the
rmmod command is one of them.
Using rmmod Command
rmmod is a simple program that is utilized to remove or unload a module from a kernel. This command is simple to use. The syntax for
rmmod command is the following.
rmmod [-f] [-w] [-s] [-v] [modulename]
You only need the module name you wanted to unload, and
rmmod will remove it. However, it would be a problem if you don’t know the module’s name to remove or unload. Fortunately, there is a solution to this problem. Use the lsmod command to print out all the modules loaded in your system.
After finding out the module’s name you wanted to unload, you can pass it to
rmmod. Moreover, only users with administrative privileges can remove the modules, so use sudo. For example:
sudo rmmod i915
There won’t be any confirmation message after performing the command. However, you can run
lsmod again to check if the module is gone.
The command will only print a message if there’s something wrong. For instance, if there is another module that is currently using the module you want to unload. It will then display this message:
rmmod: ERROR: Module [modulename] is in use by: [modulename2]
rmmod also accepts multiple modules as arguments. It will remove the modules in their given order.
rmmod [modulename1] [modulename2]
When this option is specified, it will tag the unused modules as “to be cleaned” and subsequently remove the previously tagged modules. The modules will stay tagged if they are still unused from the last auto clean.
Saves the persistent data for the named module, even without unloading the module. If there’s no module name specified, this option will save the persistent data for all the modules.
However, you can only save the data when both the
modutils and kernel support persistent data. In addition, the
/proc/ksyms should also contain an entry
Force the operation to happen. This option can be tremendously dangerous, so proceed with caution. If specified, this option will remove the currently used module, is marked as unsafe, or is not designed to be removed.
This option will only take effect if you set
CONFIG_MODULE_FORCE_UNLOAD when the kernel has complied.
Help option prints out the syntax of rmmod command in Linux. In addition, it also displays the different options that you can use, along with a brief and concise description of each option.
Remove a module stack.
syslog option sends the errors to the
syslog instead of standard error.
Displays messages regarding what the program is doing. Usually, if this option is not specified,
rmmod only displays a message if something is wrong.
When used, this option shows the rmmod’s version information and then exit.
rmmod will not unload modules that are currently in use. However, if you specify this option and then attempt to remove a module in use,
rmmod will isolate the module and wait until it is no longer in use. Afterward, nothing new can use the isolated module.
Stop a Kernel Module from Loading While Booting
When you remove a kernel through the rmmod command in Linux, the module will remain unloaded until your system will reboot again. You can then load the module you remove on your next system reboot.
You can permanently stop a kernel module from loading during booting by creating a .conf file within the /etc/modprobe.d. Moreover, you can label the file with any name of your choosing. The general syntax is as follows:
/etc/modprobe.d/blacklist.conf blacklist module_name
In addition, you can blacklist another module by either specifying the module on a new line or creating another .conf file.
Note: When removing your kernel modules, we extremely recommend using
modprob –r, rather than rmmod. This is to guarantee that the removal of the module does not break any dependencies.
The rmmod command in Linux is used to remove the kernel modules. However, general Linux users are utilizing modprobe with the -r option instead of rmmod.
If this guide helped you, please share it. ?