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):
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:
lsmod | head -8Sample output:
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_pcmThe 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:
sudo modprobe dummy
lsmod | grep -w dummySample output:
dummy 16384 0Unload it:
sudo rmmod dummy
lsmod | grep -w dummy || echo 'dummy removed'Sample output:
dummy removedSuccessful 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):
sudo rmmod snd_seq_dummy 2>&1 || trueSample output:
rmmod: ERROR: Module snd_seq_dummy is in useUnload 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:
modinfo dummy | head -10Sample output:
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: dummyThe 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:
sudo modprobe dummy
sudo rmmod -v dummyOn 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:
sudo modprobe dummy
sudo modprobe -r dummy
lsmod | grep -w dummy || echo 'removed via modprobe'Sample output:
removed via modprobeUse 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.
sudo rmmod -f module_nameIf 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):
echo 'blacklist pcspkr' | sudo tee /etc/modprobe.d/local-blacklist.confVerify the file:
cat /etc/modprobe.d/local-blacklist.confRemove 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 |
|---|---|
|
|
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.
Related commands
| 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 |

