Introduction to rmmod Command in Linux
This lab provides a comprehensive guide to the Linux rmmod
command, a vital tool for system administration. The rmmod
command is used to dynamically remove kernel modules from a running Linux system. Kernel modules are essentially code extensions that add functionality to the kernel on demand. This tutorial will cover understanding the function of the rmmod
command, demonstrating how to use rmmod
to remove a kernel module, and exploring practical, real-world systemadmin scenarios. We'll begin by listing currently loaded kernel modules using lsmod
before detailing module removal using rmmod
.
Understanding the Purpose of the rmmod Command
This section details the purpose and mechanics of the rmmod
command within the Linux environment. As a systemadmin, you'll find rmmod
essential for managing kernel modules and system resources. The core function of the rmmod
command is to unload a specific kernel module from the active system.
Kernel modules are designed to be loaded and unloaded without requiring a full system reboot. This dynamic functionality is key for extending kernel capabilities to support varied hardware, file systems, advanced networking, and more.
The rmmod
command is particularly useful when a module's features are no longer needed or when you're upgrading to a newer version of the module. It's a cornerstone tool in a systemadmin's arsenal.
First, let's view a list of the currently active kernel modules using the lsmod
command:
sudo lsmod
Example output:
Module Size Used by
vboxsf 106496 1
vboxguest 454656 0
snd_hda_codec_realtek 114688 1
snd_hda_codec_generic 86016 1 snd_hda_codec_realtek
snd_hda_intel 53248 0
snd_hda_codec 135168 3 snd_hda_codec_generic,snd_hda_codec_realtek,snd_hda_intel
snd_hda_core 90112 5 snd_hda_codec_generic,snd_hda_codec_realtek,snd_hda_intel,snd_hda_codec
snd_hwdep 16384 1 snd_hda_codec
snd_pcm 106496 4 snd_hda_intel,snd_hda_codec
snd_timer 32768 1 snd_pcm
snd 98304 21 snd_hda_codec_generic,snd_hda_codec_realtek,snd_hda_intel,snd_hda_codec,snd_hwdep,snd_pcm,snd_timer
soundcore 16384 1 snd
The output displays the currently loaded kernel modules. To remove a specific module, enter the rmmod
command followed by the module's name. For example, to remove the vboxsf
module:
sudo rmmod vboxsf
After executing the command, verify the module is removed by running lsmod
again:
sudo lsmod
Example output:
Module Size Used by
vboxguest 454656 0
snd_hda_codec_realtek 114688 1
snd_hda_codec_generic 86016 1 snd_hda_codec_realtek
snd_hda_intel 53248 0
snd_hda_codec 135168 3 snd_hda_codec_generic,snd_hda_codec_realtek,snd_hda_intel
snd_hda_core 90112 5 snd_hda_codec_generic,snd_hda_codec_realtek,snd_hda_intel,snd_hda_codec
snd_hwdep 16384 1 snd_hda_codec
snd_pcm 106496 4 snd_hda_intel,snd_hda_codec
snd_timer 32768 1 snd_pcm
snd 98304 21 snd_hda_codec_generic,snd_hda_codec_realtek,snd_hda_intel,snd_hda_codec,snd_hwdep,snd_pcm,snd_timer
soundcore 16384 1 snd
Notice the vboxsf
module is no longer listed, confirming successful removal.
How to Remove a Kernel Module Using rmmod
This section guides you on how to correctly utilize the rmmod
command to remove a kernel module, a necessary skill for Linux systemadmin tasks.
First, begin by listing the currently loaded modules with the lsmod
command:
sudo lsmod
Example output:
Module Size Used by
vboxguest 454656 0
snd_hda_codec_realtek 114688 1
snd_hda_codec_generic 86016 1 snd_hda_codec_realtek
snd_hda_intel 53248 0
snd_hda_codec 135168 3 snd_hda_codec_generic,snd_hda_codec_realtek,snd_hda_intel
snd_hda_core 90112 5 snd_hda_codec_generic,snd_hda_codec_realtek,snd_hda_intel,snd_hda_codec
snd_hwdep 16384 1 snd_hda_codec
snd_pcm 106496 4 snd_hda_intel,snd_hda_codec
snd_timer 32768 1 snd_pcm
snd 98304 21 snd_hda_codec_generic,snd_hda_codec_realtek,snd_hda_intel,snd_hda_codec,snd_hwdep,snd_pcm,snd_timer
soundcore 16384 1 snd
Assume we wish to remove the vboxguest
module. The rmmod
command is used as follows:
sudo rmmod vboxguest
After executing, confirm the removal of the module by running lsmod
again:
sudo lsmod
Example output:
Module Size Used by
snd_hda_codec_realtek 114688 1
snd_hda_codec_generic 86016 1 snd_hda_codec_realtek
snd_hda_intel 53248 0
snd_hda_codec 135168 3 snd_hda_codec_generic,snd_hda_codec_realtek,snd_hda_intel
snd_hda_core 90112 5 snd_hda_codec_generic,snd_hda_codec_realtek,snd_hda_intel,snd_hda_codec
snd_hwdep 16384 1 snd_hda_codec
snd_pcm 106496 4 snd_hda_intel,snd_hda_codec
snd_timer 32768 1 snd_pcm
snd 98304 21 snd_hda_codec_generic,snd_hda_codec_realtek,snd_hda_intel,snd_hda_codec,snd_hwdep,snd_pcm,snd_timer
soundcore 16384 1 snd
The vboxguest
module is now absent from the list, verifying its successful removal.
Exploring Practical Systemadmin Scenarios for Using rmmod
This section explores practical scenarios for the rmmod
command within systemadmin workflows.
A common scenario is updating kernel modules. For instance, replacing an old graphics driver with a newer one involves removing the old driver using rmmod
.
First, view the list of loaded kernel modules:
sudo lsmod
Example output:
Module Size Used by
nvidia_drm 106496 0
nvidia_modeset 1028096 0
nvidia 28540928 1 nvidia_modeset
drm_kms_helper 184320 1 nvidia_drm
drm 516096 4 nvidia_drm,drm_kms_helper
Here, the nvidia
module is loaded. Remove it with the rmmod
command:
sudo rmmod nvidia
Confirm module removal:
sudo lsmod
Example output:
Module Size Used by
nvidia_drm 106496 0
nvidia_modeset 1028096 0
drm_kms_helper 184320 1 nvidia_drm
drm 516096 4 nvidia_drm,drm_kms_helper
You can now install the new graphics driver module.
Troubleshooting system issues is another scenario. If a specific kernel module is suspected of causing problems, removing it with rmmod
can help isolate the issue.
For example, network connectivity issues might be resolved by removing the network driver module:
sudo rmmod e1000e
After removal, test network connectivity to see if the issue is resolved.
When removing modules, ensure it's not in use and its removal won't cause critical system failures. When in doubt, consult documentation or experienced system administrators and Linux experts.
Summary
This lab covered the purpose and use of the rmmod
command in Linux. We learned that kernel modules extend kernel functionality and rmmod
removes modules from a running system. We practiced using lsmod
to list loaded modules and removing the vboxsf
module with rmmod
. This facilitates kernel functionality management by adding or removing modules.