There are modules for your graphics hardware (GPU), different filesystems (such as ext4, zfs, btrfs), network hardwares, display, keyboard and different input devices and many more.
In this article, I am going to show you how to use modprobe to manage kernel modules on Debian GNU/Linux distribution. I am going to use Debian 9 Stretch for the demonstration. But it should work on any version of Debian GNU/Linux. So let’s get started.
The Default Modules Directory:
All the modules in Debian is stored is the /lib/modules/$(uname -r) directory.
The kernel modules are stored in a sub directory kernel/. The kernel modules are stored in a modular hierarchical order as you can see in the screenshot below.
Listing All the Available Kernel Modules:
You can list all the kernel modules in a nicely formatted tree structure with the following command:
NOTE: The tree command is not installed by default. You will have to install it manually with sudo apt install tree
As you can see, the directories and kernel modules are listed as a tree.
It’s a very long list. You can also pass it to a pager such as less as follows to make navigation through the list easier:
Now you can press the <Up> and <Down> arrow keys to navigate through the list.
You can search for modules in the less pager. Just press / and type in your search keyword.
Now press <Enter> and your search result should be displayed as you can see in the marked section of the screenshot below.
You can also press n and p to go to the next result or previous result respectively.
To exit the pager, press q.
Listing All the Loaded Kernel Modules:
You can list all the kernel modules that are used by your Debian operating system with the following command:
It’s a long list. On the Module column (1), you can see the kernel module name, on the Size column (2), you can see the kernel module size in bytes.
The Used by column (3) is interesting. This column starts with a number and optionally a comma separated list of module names.
The number determines how many modules depend on this module. If it is 0, then it means, no other modules depend on this module. For example, the pppdev module is not used by any other module. So you can safely remove or add pppdev kernel module anytime.
If it’s something other than 0, then many other modules depend on this module. For example, 2 other modules depend on snd_pcm module as you can see in the marked section of the screenshot below. So you can’t remove snd_pcm module unless you remove the modules that depend on this module. In this case, the snd_ac97_codec and snd_ens1371 modules must be removed in order to remove snd_pcm module.
Getting Information About Specific Kernel Module:
Now that you know how to list all the available kernel modules and the loaded kernel modules. In this section, I am going to show you how to get information about any kernel module.
On Debian, you can use the modinfo command to get information about any module.
For example, to get information about the snd_pcm module we saw earlier, run the following command:
As you can see, the module file path, license, a short description about the module snd_pcm, the modules snd_pcm depends on and some other information is listed.
These are essential bits of information you need to know in order to work with modules on Deban. For example, if you want to enable snd_pcm module, then you must also enable to snd and snd-timer modules before you do so. As snd_pcm depends on snd and snd-timer. Otherwise, it won’t work.
Loading New Kernel Module Using modprobe:
You can load new kernel modules using the modprobe command. For example, let’s say, you want to enable the btrfs filesystem kernel module.
First check what modules the btrfs kernel modules depends on with modinfo as follows:
As you can see, the btrfs kernel module depends on raid6_pg and xor kernel modules.
Let’s check whether they are enabled as follows:
$ lsmod | grep xor
As you can see, none of the modules are loaded.
Now run the following commands to load raid6_pq and xor kernel modules:
$ sudo modprobe xor
Now let’s check whether the dependency kernel modules are loaded again:
$ lsmod | grep xor
As you can see, the kernel modules are loaded.
Now you can load the btrfs kernel module with the following command:
Now let’s verify whether the btrfs kernel module is loaded with the following command:
As you can see, the btrfs kernel module is loaded and it depends on the raid6_pq and the xor kernel modules.
Most of the time modprobe command will resolve dependencies for you automatically. But I showed you how to do it manually because at times you may need to do it this way. It’s best to know how to solve a problem as you may have to deal with it someday.
Removing Modules with modprobe:
You can also remove modules with modprobe command. If no other modules depend on the module that you want to remove, then the process is straightforward.
For example, to remove the btrfs module I loaded earlier, run the following command:
The module should be removed.
If other modules depend on the module you want to remove, then you will have to remove these modules first before you can remove your desired module.
That’s basically all you need to know about managing kernel modules on Debian. Thanks for reading this article.