Linux Kernel Modules (LKM)
- 1. Resources
- 2. Requirements
- 3. What is kernel module?
- 4. Operations with modules
- 5. Useful header files
1. Resources
Additional resources to check out:
2. Requirements
3. What is kernel module?
Kernel module is a piece of code that extends the functionality of the kernel without the need to reboot the OS. A device driver is one type of possible kernel modules (it allows the kernel to communicate with an external hardware). Without modules, every time new driver needs to be loaded, the kernel source code needs be rebuilt.
Kernel modules are compiled into .ko
(kernel object) files. It is object code (not linked into a complete executable) that can be dynamically linked to the running kernel by the insmod
program and can be unlinked by the rmmod
program.
In kernel module there are no standard library functions available. Everything needs to be done using kernel functions. For example, you cannot use printf()
functions. There is a printk()
(linux/printk.h
) function instead. It logs output to the TTY console, so it's not visible in the GUI but it can be read using journalctl
or dmesg
commands.