Modprobe Command in Linux – A Beginner’s Guide

Modprobe Command In Linux

In this article, we’ll learn about the modprobe command in Linux. The Linux kernel is modular in nature which means that any end-user can remove the functionality of the kernel or add the functionality of the kernel simply by removing or adding a certain module. This is where modprobe command comes in handy which makes it easy to add or remove kernel modules.

Also read: Steps to Install Intel Graphic Drivers on Ubuntu 20.04LTS

What is a kernel module?

A kernel module is an object file that contains code that can be loaded and unloaded to the kernel as per need. When loaded, it will extend the kernel functionality without ever needing to reboot the kernel itself.

This way developers don’t have to write monolithic code for all services and functions. Think of the Linux kernel as a huge lego structure, onto which you can add another lego piece (module) without any difficulty.

Device drivers are a good example of kernel modules.

All the kernel modules on your device are stored in /lib/modules . You can list them by using the following command.

find /lib/modules/$(uname -r)/kernel/ | grep ".ko" | more 
List Kernel Modules

To see which modules are currently loaded, you can use lsmod


What is the modprobe command used for?

The modprobe command is used to load (add) and unload (remove) kernel modules. It looks for modules in /lib/module/$(uname -r)

How to load a module using modprobe?

You can load a kernel module using the following command.

sudo modprobe <kernel module name>hideep.ko

After running this command, you can verify that the module has been loaded by using

lsmod | grep <kernel module name>

If this command returns anything, that means the module has been loaded.

Loading Kernel Module

Here I have loaded the hideep module which is a device driver for touchscreens.

How to unload a module?

A kernel module can be unloaded using the -r flag in modprobe.

sudo modprobe -r <kernel module name>

Again to verify that the kernel module has been unloaded, you can run

lsmod | grep <kernel module name>

and it shouldn’t return anything.

Unload Kernel Module

Useful flags in modprobe

Just like we used the -r flag to remove modules, modprobe has many other flags for other purposes. Some of the important ones are listed below.

-a : This flag allows you to add multiple modules at once 
Load Multiple Modules At Once
--show-depends : This lists all the dependencies of a module 
Show Dependencies Of Kernel Module
-v : If you want to know about what the program is doing in every single step, you can use this command. 
Modprobe Verbose
--first-time : Usually if you try to add a module which is already loaded or remove a module which is already unloaded, modprobe will do nothing. However when we use this flag, modprobe will fail. This is good for debugging purposes and to verify wheather a module has already been loaded/unloaded.  
First Time Modprobe


Sometimes when you are searching all of the internet to try to fix that one driver issue or sound issue, many tutorials will ask you to load/unload driver modules in Linux. Well, now you know how to do it easily using modprobe. Refer here to learn more about modprobe and kernel modules. Thank you and keep exploring.