rmmod Command in Linux: Syntax, Options & Practical Examples

rmmod removes loadable kernel modules from a running Linux kernel. Use it to unload drivers you loaded for testing; modprobe -r is the higher-level alternative that handles dependencies.

Published

Updated

Read time 7 min read

Reviewed byDeepak Prasad

rmmod Command in Linux: Syntax, Options & Practical Examples
About rmmod removes loadable kernel modules from a running Linux kernel. Use it to unload drivers you loaded for testing; modprobe -r is the higher-level alternative that handles dependencies.
Tested on Ubuntu 25.04 (Plucky Puffin); kmod 33; kernel 7.0.0-27-generic
Package kmod
Man page rmmod(8)
Privilege root / sudo
Distros

All distros with loadable kernel modules (systemd/kmod).

Prefer modprobe -r when dependencies matter — same kmod package family.

rmmod — quick reference

Unload modules

Remove one or more modules from the running kernel by name.

When to use Command
Unload a module that is not in use sudo rmmod module_name
Unload several modules in one command sudo rmmod mod1 mod2
Force unload even if the module is busy (dangerous) sudo rmmod -f module_name

Diagnostics

When to use Command
Print extra kernel messages while unloading sudo rmmod -v module_name
Log to syslog instead of stderr sudo rmmod -s module_name

Help and version

When to use Command
Show built-in usage text rmmod --help
Show kmod version rmmod -V

rmmod — command syntax

Synopsis from rmmod --help on Ubuntu 25.04 (kmod 33):

text
Usage:
	rmmod [options] modulename ...

rmmod talks to the running kernel through /sys/module/. You need sudo for module removal on typical systems.


rmmod — command examples

Essential List loaded modules before you unload

You can only remove modules that are actually loaded. lsmod shows name, size, and who is using the module.

Run the command:

bash
lsmod | head -8

Sample output:

text
Module                  Size  Used by
ib_core               552960  0
isofs                  61440  1
snd_seq_dummy          12288  0
snd_hrtimer            12288  1
snd_seq               126976  9 snd_seq_midi,snd_seq_midi_event,snd_seq_dummy
snd_seq_device         16384  2 snd_seq_midi,snd_seq
snd_timer              53248  3 snd_seq,snd_hrtimer,snd_pcm

The Used by column shows dependent module names. If it is non-zero, rmmod refuses to unload until those users go away.

Essential Load and unload the dummy network module

The dummy module is a safe lab choice: load it with modprobe, confirm with lsmod, then remove it with rmmod.

Load the module:

bash
sudo modprobe dummy
lsmod | grep -w dummy

Sample output:

text
dummy                  16384  0

Unload it:

bash
sudo rmmod dummy
lsmod | grep -w dummy || echo 'dummy removed'

Sample output:

text
dummy removed

Successful rmmod prints nothing — silence means the kernel accepted the unload.

Essential Module in use — expected rmmod error

When another module or process still references the driver, the kernel blocks removal.

Try to remove a module that is busy (example: snd_seq_dummy while audio stack is loaded):

bash
sudo rmmod snd_seq_dummy 2>&1 || true

Sample output:

text
rmmod: ERROR: Module snd_seq_dummy is in use

Unload dependent modules first, stop the service using the driver, or use modprobe -r which can remove a stack in dependency order.

Common Read module metadata with modinfo

Before removing an unfamiliar module, check its description and file path.

Run the command:

bash
modinfo dummy | head -10

Sample output:

text
filename:       /lib/modules/7.0.0-27-generic/kernel/drivers/net/dummy.ko.zst
alias:          rtnl-link-dummy
description:    Dummy netdevice driver which discards all packets sent to it
license:        GPL
srcversion:     27A9731F61246064F319D6A
depends:        
intree:         Y
name:           dummy

The depends line lists modules that must be present — unload order matters when dependencies exist.

Common Verbose unload with -v

Use -v when you want the kernel to print extra detail during removal.

Run the commands:

bash
sudo modprobe dummy
sudo rmmod -v dummy

On success rmmod may still be quiet apart from kernel log lines — check dmesg | tail if you need confirmation.

Common Prefer modprobe -r for dependency-aware removal

modprobe -r asks the kernel to remove a module and its unused dependents — often easier than calling rmmod repeatedly.

Run the command:

bash
sudo modprobe dummy
sudo modprobe -r dummy
lsmod | grep -w dummy || echo 'removed via modprobe'

Sample output:

text
removed via modprobe

Use rmmod when you want the thinnest possible call (scripts, embedded systems) or when you are unloading a specific leaf module you already verified is unused.

Advanced Force unload with -f (dangerous)

-f forces removal even when the module is in use. It can crash the running system or corrupt driver state.

Only try this in a disposable VM with kernel Forced Module Removal enabled — never on production.

bash
sudo rmmod -f module_name

If the kernel rejects forced removal you will see an error in stderr or dmesg. Treat -f as a break-glass option, not a daily flag.

Advanced Stop a module from loading after reboot

rmmod only affects the running kernel. After reboot, udev or initramfs may load the module again.

To block future loads, add a modprobe drop-in (example blocks pcspkr):

bash
echo 'blacklist pcspkr' | sudo tee /etc/modprobe.d/local-blacklist.conf

Verify the file:

bash
cat /etc/modprobe.d/local-blacklist.conf

Remove the drop-in when you no longer need the blacklist. This is policy configuration — not part of rmmod itself, but the usual follow-up when admins unload drivers permanently.


rmmod — when to use / when not

Use rmmod when Use something else when
  • You need a minimal command to drop one known-unused module
  • You are scripting module teardown and already handled dependency order
  • You are testing a driver you loaded with insmod or modprobe
  • Dependencies may still be loaded → modprobe -r module
  • You need to load a module → modprobe module or insmod
  • You want the module gone after every reboot → modprobe blacklist under /etc/modprobe.d/
  • You need hardware inventory, not kernel unload → dmidecode or lspci

rmmod vs modprobe -r

rmmod modprobe -r
Interface Direct kernel unload Higher-level kmod helper
Dependencies You handle order Can remove unused dependents
Typical use Scripts, single leaf modules Day-to-day admin

Both ship in the kmod package on modern distributions.


Command One line
rmmod Unload kernel modules (this page)
modprobe Load or unload with dependency handling
lsmod List currently loaded modules
modinfo Show module metadata
insmod Load a module by file path

Browse the full index in our Linux commands reference.


rmmod — interview corner

What does rmmod do?

rmmod removes a loadable kernel module from the running Linux kernel. Each module is a piece of driver or filesystem code that was inserted after boot.

The kernel refuses to unload a module while another module or process still depends on it — you will see Module X is in use.

A strong answer is:

"rmmod unloads a kernel module from memory. It fails if the module is still referenced — then I stop the consumer or use modprobe -r to handle dependencies."

What is the difference between rmmod and modprobe -r?

Both end up asking the kernel to remove a module. modprobe -r is smarter about dependency stacks — it can remove a module and other unused modules that were only needed for that stack.

rmmod is the thin syscall wrapper: you pass exact module names and the kernel enforces reference counts.

A strong answer is:

"modprobe -r is dependency-aware; rmmod is the low-level unload. I use modprobe -r for routine work and rmmod when I know the module is a leaf node."

Why does rmmod say a module is in use?

The kernel tracks reference counts. If the Used by column in lsmod lists other modules, or a process still has open handles (network interface, mount, device node), removal is unsafe.

Fix by stopping the service, bringing down the interface, unloading dependent modules first, or rebooting as a last resort.

A strong answer is:

"Something still references the module — another module on the lsmod stack or an open handle. I check lsmod Used by, stop the consumer, then retry or use modprobe -r."

Does rmmod persist across reboot?

No. rmmod only affects the current boot. After reboot, udev, initramfs, or /etc/modules-load.d/ may load the module again.

For a permanent block, add a blacklist file under /etc/modprobe.d/ or remove the module from auto-load configuration.

A strong answer is:

"rmmod is temporary — reboot can reload the module. For persistence I blacklist it in modprobe.d or change modules-load config."

When is rmmod -f appropriate?

Almost never on production. -f forces unload while the module is busy and can panic the kernel or leave hardware in a bad state.

It requires kernel support for forced module removal and belongs only in controlled lab recovery.

A strong answer is:

"rmmod -f is a last-resort lab tool — it can crash the box. I fix references or use modprobe -r instead of forcing removal on production systems."


Troubleshooting

Symptom Likely cause Fix
Module X is in use Dependent module or open handle lsmod; stop service; modprobe -r X
Module X is not currently loaded Typo or already removed lsmod | grep X
Operation not permitted Missing capability / not root sudo rmmod …
Module returns after reboot Auto-load policy Blacklist in /etc/modprobe.d/
-f still fails Kernel lacks forced removal Do not force; fix references
Unknown option Old kmod build rmmod --help on the host

Omer Cakmak

Linux Administrator

Highly skilled at managing Debian, Ubuntu, CentOS, Oracle Linux, and Red Hat servers. Proficient in bash scripting, Ansible, and AWX central server management, he handles server operations on …