How to Load and Remove Kernel Modules on Linux Systems

In this Linux Guide I will show you how to work with kernel modules. I wil teach you how to load and unload (remove) kernel modules, with both modprobe and insmod / rmmod tools.

The kernel modules and the configuration files are stored in your /lib/modules/$(uname -r) directory. The modprobe related configuration files are located in /etc/modprobe.conf and /etc/modprobe.d.

The Linux Operating Systems using kernel 2.6 have the kernel modules with the .ko extension, instead of .o. The *.o files are objects.

How to list modules in Linux Systems:

modprobe -l is used for displaying all the modules available (that can be loaded):

$ modprobe -l

Use less for a better output: modprobe -l | less

Display only the loaded modules in your system:

lsmod is used for displaying the loaded kernel modules:

$ lsmod
Module Size Used by
btrfs 652957 0
zlib_deflate 27139 1 btrfs
libcrc32c 12644 1 btrfs
ufs 75303 0
qnx4 17677 0
hfsplus 84867 0
hfs 54782 0
minix 36288 0
ntfs 101885 0

To find if a certain module is loaded or not, use a grep trick. I will check if my bluetooth module is loaded or not:

$ lsmod | grep -i bluetooth
bluetooth 180104 10 rfcomm,bnep

Install a new module in the system:

The kernel models can be loaded with both modprobe and insmod commands.

From the insmod manual:

Most users will want to use modprobe instead, which is more clever and can handle module dependencies.

So, lets load some modules:

1. with modprove. Syntax: modprobe module_name

Note: modprobe does not need the extension of the module.


$ sudo modprobe rfcomm

2. with insmod. Syntax insmod /path/to/module_name


$ whereis rfcomm
rfcomm: /usr/bin/rfcomm /usr/bin/X11/rfcomm /usr/share/man/man1/rfcomm.1.gz
$ sudo insmod /usr/bin/rfcomm

The difference between modprobe and insmode is that modprobe needs only the module name, but insmod needs the path to the module. Also, insmod does not load the module dependencies, but modprobe does.

I have already showed you how to check if a module is loaded or not: lsmod | grep -i bluetooth.

You can also load a kernel module with a different name, to avoid name conflicts:

Syntax: modprobe kernel_module -o the_new_name


$ sudo modprobe rfcomm -o bluetooth_module_one

How to remove (or unload) a kernel module:

To unload a kernel module, use modprobe -r or rmmod. It is the same trick, modprobe -r removes module by name and rmmod needs the path to the module.

1. with modprobe. Syntax: modprobe -r module_name

Note: modprobe does not need the extension of the module.


$ sudo modprobe -r rfcomm

2. with rmmod. Syntax: rmmod /path/to/module


$ sudo rmmod /usr/bin/rfcomm

If you don’t know why is a module needed, use modinfo to find out information about the module:

$ modinfo rfcomm
filename: /lib/modules/3.2.0-23-generic/kernel/net/bluetooth/rfcomm/rfcomm.ko
alias: bt-proto-3
license: GPL
version: 1.11
description: Bluetooth RFCOMM ver 1.11
author: Marcel Holtmann
srcversion: D86E93727B0F3DB97D632B7
depends: bluetooth
intree: Y
vermagic: 3.2.0-23-generic SMP mod_unload modversions
parm: disable_cfc:Disable credit based flow control (bool)
parm: channel_mtu:Default MTU for the RFCOMM channel (int)
parm: l2cap_mtu:Default MTU for the L2CAP connection (uint)
parm: l2cap_ertm:Use L2CAP ERTM mode for connection (bool)

Advice: use modprobe and modprobe -r instead of insmod and rmmod. To my mind, the last two tools are just for general knoledge, or to own a geek’s ass while drinking a beer in a bar.

Tagged with: , , , , , , , , , , ,
Posted in The Linux and Unix Articles!

Leave a Reply

Your email address will not be published. Required fields are marked *




Subscribe to get the latest Linux news and how to guides directly on your e-mail!