Oct 23, 2023 3 min read

Modprobe Command in Linux

Use modprobe command in Linux with our step-by-step tutorial. The modprobe command adds or removes kernel modules dynamically.

Modprobe Command in Linux
Table of Contents

Introduction

Before we discuss modprobe command in Linux, let's first understand-What is modprobe Command ?

The modprobe command in Linux is used for adding and removing kernel modules (device drivers) dynamically. It is responsible for loading modules into the kernel, managing dependencies, and setting up the required configurations. modprobe simplifies the process of adding and configuring modules, making it an essential tool for managing hardware and extending the functionality of the Linux kernel.

In this tutorial, you will use modprobe to add and delete modules from the Linux kernel in this post. modprobe is a component of kmod, a binary that contains several tools for managing Linux kernel modules. We will also address a few FAQs on modprobe command in Linux.

Adding Kernel Modules

The Kernel modules are located in the /lib/modules/kernel <version> folder. The uname -r command can be used to determine the current kernel version.

Kernel modules can only be managed by users with administrative privileges.

To load a module, type modprobe followed by the name of the module:

modprobe module_name

The modprobe command loads the specified module as well as any module dependencies. At the command line, only one module can be supplied.

Confirm that the module is loaded with the lsmod command:

lsmod | grep module_name

Use the parameter=value syntax to load a module with additional parameters:

modprobe module_name parameter=value

Multiple parameter=value pairs separated by a space are accepted by the command.

In most cases, you'll need to load the module during system startup. You can achieve this by putting the module name and parameters in a file in the /etc/modules-load.d directory. The name of the file must end in.conf, and it can be anything:

option module_name parameter=value

The settings in these files are read by udev, which uses modprobe to load the modules during system startup.

Remove Kernel Modules

Invoke the modprobe command with the -r option followed by the module name to remove it:

modprobe -r module_name

modprobe will also delete any module dependencies that are no longer in use.

The command supports several modules as arguments when executed with -r:

modprobe -r module_name1 module_name2
💡
The rmmod command can also be used to remove a module from the Linux kernel.

Create a .conf file with any name inside the /etc/modprobe.d directory if you wish to block a Kernel module from loading at boot time. The syntax is as follows:

blacklist module_name

If you wish to add more modules to the blacklist, put them on a new line or create a new.conf file.

FAQs on Modprobe Command in Linux

How does the modprobe command work?

modprobe interacts with the kernel to load the specified module. It resolves dependencies by loading required modules and can also apply relevant configurations defined in the module configuration files.

How do I use the modprobe command to load a module?

To load a module using modprobe, execute the command modprobe module_name, where module_name is the name of the module you want to load.

Can modprobe automatically load module dependencies?

Yes, modprobe automatically loads dependencies required by a module, ensuring that all necessary modules are loaded in the correct order.

How can I remove a loaded module using modprobe?

To remove a loaded module using modprobe, execute the command modprobe -r module_name. This command unloads the specified module and any modules that depend on it.

Can I list the currently loaded modules using modprobe?

No, modprobe does not provide a direct way to list the currently loaded modules. For that, you can use commands such as lsmod, cat /proc/modules, or tools like lsmod and modinfo.

Can I prevent certain modules from being loaded using modprobe?

Yes, you can prevent specific modules from being loaded by modprobe using the /etc/modprobe.d/blacklist.conf file. This file allows you to blacklist modules so that they are not loaded when modprobe is invoked.

Can modprobe be used to automatically load modules at system startup?

Yes, modprobe can be configured to load modules automatically at system startup. This can be achieved by adding the module names to the /etc/modules file or by creating module-specific configuration files in the /etc/modprobe.d/ directory.

Conclusion

You can use the modprobe command to add and delete Linux kernel modules.

If you have any queries, please leave a comment below and we’ll be happy to respond to them.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Tutorials - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.