Kernel Modules
What is a kernel module?
A kernel module is essentially a piece of code that can be loaded into the operating system's kernel on demand. Think of it like an extension for the kernel, providing additional functionality without requiring a complete system restart. In other systems, modules are known as drivers.
For clarification, Kernel modules are not the only method that the kernel can be altered. You can also directly edit GRUB to pass additional commands during boot, or alter the kernel manually.
Why do we need kernel modules?
The Linux Kernel is 'monolithic', this means that it's a single file containing every aspect of that particular kernel. In order to change this, we would have to alter and recompile the kernel manually - which is lots of work. Alternatively, we can use pre-built kernel modules to add additional functionality to the Linux Kernel.
About Kernel Modules
Kernel Modules are typically stored in /lib/modules.
Typically, this directory will contain various modules that come pre-installed with the OS, note that these won't all be active.
List active kernel modules (lsmod):
lsmod
View Module Information
Display information about a particular kernel module:
modinfo modulename
Enable a kernel module (insmod)
Firstly, identify the module file path (within /lib/modules). This will have a .ko file extension.
sudo insmod /lib/modules/path/to/ko/file
NOTE: The preferred method of activating modules is via modprobe
Disable a kernel module (rmmod)
sudo rmmod modulename
NOTE: The preferred method of activating modules is via modprobe
modprobe
Modprobe is the preferred command for interacting with kernel module configuration due to its ability to handle module dependencies.
This is worth doing if you're adding a new kernel module to a system:
sudo modprobe -option modulename
| Option | Function |
| -a modulename | Add a module |
| -r modulename | Remove a module |
| -f | Forve a module to be inserted or removed. |
depmod
modprobe keeps a database of module dependencies
No Comments