Pages

Linux Kernel Modules

Linux kernel modules are pieces of code that can be loaded and unloaded from kernel on demand.

Kernel modules offers an easy way to extend the functionality of the base kernel without having to rebuild or recompile the kernel again. Most of the drivers are implemented as a Linux kernel modules. When those drivers are not needed, we can unload only that specific driver, which will reduce the kernel image size.

Kernel modules will have extension .koKernel modules will operate on kernel space.All Drivers are modules. Not all modules are drivers.

Kernel Modules Commands:lsmod: To see list of modules that already loaded on systeminsmod: To insert modules into kernelmodinfo: To display modules informationrmmod: To remove modules from kernelHow to Write Kernel Modules:
module.c

When a module is inserted into the kernel, the module_init macro will be invoked, which will call the function hello_init. Similarly, when the module is removed with rmmod, module_exit macro will be invoked, which will call the hello_exit. Using dmesg command, we can see the output from the sample Kernel module.