Linux rmmod Command with Practical Examples

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, we will explore the Linux rmmod command, which is used to remove a kernel module from the running system. Kernel modules are pieces of code that can be loaded and unloaded into the kernel as needed, providing a way to extend the functionality of the kernel. The lab will cover understanding the purpose of the rmmod command, removing a kernel module using rmmod, and exploring practical scenarios for its usage. We will start by listing the currently loaded kernel modules using the lsmod command, and then demonstrate how to remove a specific module using rmmod.

Linux Commands Cheat Sheet


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/UserandGroupManagementGroup(["`User and Group Management`"]) linux/UserandGroupManagementGroup -.-> linux/sudo("`Privilege Granting`") subgraph Lab Skills linux/sudo -.-> lab-422894{{"`Linux rmmod Command with Practical Examples`"}} end

Understand the Purpose of rmmod Command

In this step, we will explore the purpose and usage of the rmmod command in the Linux operating system. The rmmod command is used to remove a kernel module from the running system.

Kernel modules are pieces of code that can be loaded and unloaded into the kernel as needed, without restarting the entire system. They provide a way to extend the functionality of the kernel, allowing you to add support for new hardware, file systems, network protocols, and more.

The rmmod command is used to remove a kernel module from the system. This can be useful when you no longer need the functionality provided by a particular module, or when you need to replace a module with a newer version.

Let's start by listing the currently loaded 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

This output shows the currently loaded kernel modules. To remove a module, you can use the rmmod command followed by the module name. For example, to remove the vboxsf module, you would run:

sudo rmmod vboxsf

After running this command, you can verify that the module has been 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

You can see that the vboxsf module is no longer listed, indicating that it has been successfully removed.

Remove a Kernel Module Using rmmod

In this step, we will learn how to remove a kernel module using the rmmod command.

First, let's list the currently loaded kernel modules using 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

Let's say we want to remove the vboxguest module. To do this, we can use the rmmod command:

sudo rmmod vboxguest

After running this command, let's verify that the module has been removed by checking the output of 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

You can see that the vboxguest module is no longer listed, indicating that it has been successfully removed.

Explore Practical Scenarios for Using rmmod

In this final step, we will explore some practical scenarios where the rmmod command can be useful.

One common scenario is when you need to update a kernel module. For example, let's say you have installed a new graphics driver and want to replace the old one. You can use the rmmod command to remove the old driver module, and then install the new one.

First, let's list the currently 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

In this example, we can see that the nvidia module is currently loaded. To remove it, we can use the rmmod command:

sudo rmmod nvidia

After running this command, we can verify that the module has been removed:

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

Now, you can proceed to install the new graphics driver module.

Another practical scenario for using rmmod is when you need to troubleshoot a system issue. If you suspect that a particular kernel module is causing problems, you can try removing it to see if the issue is resolved.

For example, if you are experiencing network connectivity issues, you can try removing the network driver module and then checking if the problem is resolved.

sudo rmmod e1000e

After removing the module, you can test the network connectivity and see if the issue has been resolved.

Remember, when removing a kernel module, you should always ensure that the module is not in use and that its removal will not cause any critical system components to stop functioning. If you are unsure, it's best to consult the documentation or seek assistance from experienced system administrators.

Summary

In this lab, we explored the purpose and usage of the rmmod command in the Linux operating system. We learned that kernel modules are pieces of code that can be loaded and unloaded into the kernel as needed, and the rmmod command is used to remove a kernel module from the running system. We also practiced using the lsmod command to list the currently loaded kernel modules, and then removing the vboxsf module using the rmmod command. This allows us to manage the functionality of the kernel by adding or removing modules as required.

Linux Commands Cheat Sheet

Other Linux Tutorials you may like