LinuxCommandLibrary

rmmod

Remove loadable kernel modules

TLDR

Remove a module from the kernel

$ sudo rmmod [module_name]
copy

Remove a module from the kernel and display verbose information
$ sudo rmmod --verbose [module_name]
copy

Remove a module from the kernel and send errors to syslog instead of stderr
$ sudo rmmod --syslog [module_name]
copy

Display help
$ rmmod --help
copy

Display version
$ rmmod --version
copy

SYNOPSIS

rmmod [options] modulename

PARAMETERS

-f, --force
    This option can be used to force the removal of a module that is still in use. Use with extreme caution, as it can lead to system instability or crashes.

-w, --wait
    Wait until the module is no longer in use before attempting to unload it. This can prevent errors when a module is busy.

-s, --syslog
    Send error messages to syslog instead of standard error.

-v, --verbose
    Print messages about the actions being taken.

-h, --help
    Display a help message and exit.

-V, --version
    Display the version information and exit.

DESCRIPTION

rmmod is a utility used to unload (remove) a loadable module from the Linux kernel. Kernel modules are pieces of code that can be loaded and unloaded into the kernel on demand, extending its functionality without rebooting the system. This command is particularly useful for managing device drivers, filesystem modules, or other kernel extensions. Before a module can be removed, it must not be in use by any process or hardware. If the module has other modules dependent on it, rmmod will fail unless those dependent modules are also unloaded first, or if modprobe -r is used, which handles dependency resolution automatically. rmmod primarily acts as a simple wrapper around the delete_module system call. While rmmod works for simple module removal, modprobe -r is generally preferred as it is more robust, managing module dependencies and aliases, thus simplifying the process of dynamic kernel module management.

CAVEATS

Module in Use: A module cannot be unloaded if it is currently in use by any process or hardware. Attempting to do so will result in an error message like "rmmod: ERROR: Module is in use".
Dependencies: rmmod does not automatically handle module dependencies. If a module has other modules depending on it, those dependent modules must be unloaded first. For automatic dependency resolution, use modprobe -r.
System Stability: Forcing the removal of a module (-f) that is still in use can lead to system instability, crashes, or data corruption. It should be used only as a last resort and with a clear understanding of the risks.
Permissions: Removing kernel modules requires root privileges (or sudo).

PERMISSIONS

To use rmmod, you must have root privileges. Typically, this means running the command with sudo.

CHECKING MODULE USAGE

Before attempting to remove a module, you can check if it's in use using lsmod. The output will show a usage count. A count of 0 indicates the module is not currently used by other modules, but it might still be in use by processes or hardware. For persistent usage, tools like lsof or fuser might provide more details if a module is tied to a specific file or process, or checking dmesg for related messages.

UNDERLYING MECHANISM

While rmmod appears as a standalone command, in many modern Linux systems, it acts as a simple wrapper that calls modprobe -r internally. This ensures consistency with dependency handling, even if rmmod itself doesn't explicitly resolve them.

COMMON ERRORS

  • rmmod: ERROR: Module modulename is in use: The most common error, meaning the module is actively being used. You must stop whatever is using it or remove dependent modules first.
  • rmmod: ERROR: Module modulename is not loaded: The module you are trying to remove is not currently loaded in the kernel.
  • rmmod: ERROR: could not remove 'modulename': Operation not permitted: You do not have the necessary permissions (e.g., not running as root).

HISTORY

rmmod has been a fundamental part of Linux module management tools since the early days of loadable kernel modules. Historically, it was part of the modutils package, later superseded by module-init-tools and more recently by kmod. While rmmod provides a direct interface to the kernel's module removal system call, the preferred method for module removal evolved to modprobe -r. This is because modprobe intelligently handles module dependencies, aliases, and configuration, simplifying the overall module management process. In many modern Linux distributions, rmmod is often a symbolic link or a wrapper script that internally calls modprobe -r, effectively making rmmod a simpler, albeit less robust, frontend to modprobe's removal capabilities.

SEE ALSO

lsmod(8), insmod(8), modprobe(8), depmod(8), modinfo(8)

Copied to clipboard