Kernel Modules
Kernel modules are pieces of code that can be dynamically loaded and unloaded into the
Linux kernel at runtime. They extend the functionality of the kernel without requiring a
system reboot. Here are some key points about kernel modules:
1. Purpose:
o Kernel modules allow the kernel to be extended with additional features, such
as device drivers, filesystem drivers, and system calls.
o They help keep the base kernel small and efficient by loading only the
necessary modules when needed.
2. Types:
o Built-in Modules: These are compiled directly into the kernel and are always
available.
o Loadable Kernel Modules (LKMs): These can be loaded and unloaded
dynamically as needed.
3. Loading and Unloading:
o Modules can be loaded using the insmod or modprobe commands and
unloaded using the rmmod command.
o The modprobe command is more versatile as it handles module dependencies
automatically.
4. Configuration:
o Modules can be configured to load at boot time by adding their names to
configuration files in /etc/modules-load.d/.
o Module parameters can be passed during loading to customize their behavior.
5. Advantages:
o Flexibility: Modules can be added or removed without rebooting the system,
making it easier to update or add new features.
o Efficiency: Only the necessary modules are loaded, saving memory and
resources.
o Debugging: Issues with modules can be isolated and fixed without affecting
the entire kernel.
6. Example:
o A simple “Hello World” kernel module can be written to print messages when
loaded and unloaded. This is a common starting point for learning kernel
module programming.