
- What is the Linux kernel?
- What is a kernel module?
- What is the modprobe command?
- Options for the modprobe command
- How to install a single module using the modprobe command in Linux
- How to install multiple modules using the modprobe command
- How to remove modules the modprobe command
- How to list loaded kernel modules in Linux
- How to blacklist modules using modprobe
- How to check the modprobe version in Linux
- Conclusion
What is the Linux kernel?
The kernel is the “brain” and core piece of the Linux operating system and the kernel’s functionality is to serve as an interface for interaction between system software and hardware.
Linux kernel updates are released periodically to improve security, fix issues discovered in a previous release, provide new features, and add compatibility for newer hardware.
What is a kernel module?
A kernel module is an object/file that contains code which overall extends the functionality of the kernel.
Adding kernel modules can provide compatibility for new hardware, expand on current system security and so on.
These modules can be loaded and unloaded with the use of modprobe so that a reboot of the system is not required during those tasks. This makes adding new temporary modules easy to add and remove as needed.
What is the modprobe command?
The modprobe command in Linux works with the kernel and is available by default in most all Linux distributions.
Linux users utilize the modprobe command to manage modules when removing a module or loading a module into the kernel.
With the modprobe command we are able to load modules into the kernel and it will automatically install needed module version dependencies or dependent modules.
Within this article we will use the modprobe command to show its basic usage and help you get started.
Options for the modprobe command
Below is a list of common usage options for modprobe that can be utilized when managing kernel modules.
Each of the following options can be included in a modprobe command to suite your specific task.
- -a (this is used when you need to insert or removal more than one module within a command)
- -r (this is used to remove a module)
- –remove-dependencies (this will remove dependencies for a module)
- -R (this is used to review all matching module names of an alias )
- –first-time (this outputs information on if a module has been inserted or removed)
- -i (this is used to ignore any install or remove commands written for a module when you are inserting or removing a module)
- -b (you can create a blacklist for modules which should not be auto-loaded and this flag uses that list)
- -f (forces removal or insert of a module when there is a version error)
- –dry-run (runs the command as a test and provides output to help with debugging modules)
- -q (turns off error messages for a command)
- -V (this will show the mobprobe version)
- -h (used to display the help message to show command options)
How to install a single module using the modprobe command in Linux
Note: In all of these below command examples we’ll be using ‘sudo modprobe’ as we’re assuming these are being executed as a sudo privileged user.
If you are running any of the below command as ‘root’ you will not need to add ‘sudo’ into the beginning of the command.
#1. Install a Linux kernel module with modprobe
In the below example we’ll use the modprobe command with the following syntax on the command line interface to install one specific module:
(replace module_name with the desired module you wish to load into the kernel)
$ sudo modprobe module_name

From the above example the modprobe command adds the new module and it is automatically loaded into the kernel.
#2. Confirm if the Linux kernel module has been installed
Now lets confirm we successfully loaded the module into the kernel with the same modprobe command but using –first-time at the end as an option:
$ sudo modprobe module_name --first-time

Running the above modprobe command will show an error message such as in the following to let you know the kernel module is already loaded:

As we see from above the “module already in kernel” error message indicates this has been installed/loaded into the kernel already so we’re all set.
How to install multiple modules using the modprobe command
#1. Install multiple modules using the modprobe command
Lets say you have a list of different modules you’d like load into the Linux kernel.
To add multiple modules with modprobe we would utilize the -a flag while separating each module with a space.
The general syntax of adding multiple modules is as follows:
(replace module_name with the desired module you wish to load into the kernel)
$ sudo modprobe -a module_name1 module_name2

#2. Verify the kernel modules have been installed
Whenever you’re installing or removing modules it is always suggested to check your work and confirm.
We’ll just use the –first-time option once more in the same command to verify:
$ sudo modprobe -a module_name1 module_name2 --first-time

How to remove modules the modprobe command
#1. Remove a kernel module with modprobe
To remove modules from the Linux kernel we’ll utilize the ‘sudo modprobe -r’ command such as in the following example:
(replace module_name with the desired module you wish to uninstall/remove from the kernel)
$ sudo modprobe -r module_name

#2. Confirm the module has been removed
To confirm you have removed/unloaded a module from the Linux kernel you would run the same ‘sudo modprobe -r’ command again but add in the –first-time option:
$ sudo modprobe -r module_name --first-time
Just like within the installation section where we ran –first-time you’ll receive an error message which indicates the module is not installed.
If the output of the above shows “the module is not in the kernel” you should be all set and the module has been removed successfully.
How to list loaded kernel modules in Linux
When using modprobe to add/remove modules you may need to know the list of loaded modules which already exist.
Linux kernel module locations on the file system are set to /lib/modules or /usr/lib/modules and there are a couple of ways to view loaded modules.
List loaded kernel modules with lsmod
One way to list all loadable kernel modules in the module directory is to use the following command:
$ lsmod
You could also grep for a specific module to see if it is loaded into the kernel:
$ lsmod | grep module_name
Using the find command to list loaded kernel modules
Alternatively you can also use the ‘find’ command on the module directory to locate all of your installed kernel modules such as with the following:
$ find /lib/modules/$(uname -r) -type f -name '*.ko*'
This may be a long list so you could also pipe ‘less’ into the command such as in this example:
$ find /lib/modules/$(uname -r) -type f -name '*.ko*' | less
By using ‘less’ within the command you can scroll through the results with your middle mouse button or the space bar.
How to blacklist modules using modprobe
At times it may be needed to block a module from being used by the systems kernel and with modprobe we’re able prevent certain kernel modules from automatically loading into the kernel or prevent them from loading at all.
In order to add a module into a blacklist you’ll need to manually add the following into the current configuration within the following file path:
/etc/modprobe.d/
Within this location you will want to create a new conf file named after the module you would like to blacklist such as with the following example:
$ echo "blacklist module_name" > /etc/modprobe.d/module_name.conf
Or you could also blacklist it from becoming a loaded module by creating the file with vim:
vim /etc/modprobe.d/module_name.conf
And add in the following to the file:
blacklist module_name
In the above example you would need to replace ‘module_name’ with the module you wish to blacklist.
How to check the modprobe version in Linux
To simply check the version of modprobe on the Linux command line interface you would just run the following command:
$ sudo modprobe -V
You can also use the –version within the modprobe command to achieve the same results:
$ sudo modprobe --version
Output from either of the above would show similar to the following:

Conclusion
The kernel is the most important component of a Linux operating system and you may find yourself needing to install new modules for the kernel to extend compatibility with new hardware or improve security.
In this article we went over the basic usage of the modprobe command which can be used to manage kernel modules such as loading modules, removing modules and how to obtain an active module loaded list.
Leave a Reply