A Linux kernel module is a piece of object code that can be loaded into the kernel at run-time, without recompiling the kernel.
Loadable kernel modules provide a mechanism for extending the functionality of the kernel without the need to recompile the kernel or reboot the system.
Kernel modules can be used to add device drivers, file systems, and other functionality to the kernel.
There are two types of kernel modules:
Loadable kernel modules have a number of advantages over statically compiled kernel modules:
Loadable kernel modules have a number of disadvantages over statically compiled kernel modules:
A kernel module can be loaded into the kernel using the insmod
command and unloaded from the kernel using the rmmod
command.
The insmod
command takes the name of the kernel module as an argument and loads it into the kernel. The rmmod
command takes the name of the kernel module as an argument and removes it from the kernel.
A kernel module is a piece of object code that can be loaded into the kernel at run-time, without recompiling the kernel. Kernel modules are typically written in the C programming language.
Kernel modules must be compiled with the -DMODULE
compiler flag. This flag tells the compiler that the code is being compiled as a kernel module.
Kernel modules must also be compiled with the -fPIC
compiler flag. This flag tells the compiler to generate position-independent code. Position-independent code can be loaded into memory at any address and executed.
The -DMODULE
and -fPIC
compiler flags can be passed to the compiler using the CFLAGS
environment variable.
$ export CFLAGS=-DMODULE -fPIC
Once the CFLAGS
environment variable has been set, the kernel module can be compiled using the make
command.
$ make
A kernel module can be loaded into the kernel using the insmod
command. The insmod
command takes the name of the kernel module as an argument and loads it into the kernel.
$ insmod hello.ko
A kernel module can be unloaded from the kernel using the rmmod
command. The rmmod
command takes the name of the kernel module as an argument and removes it from the kernel.
$ rmmod hello
https://www.kernel.org/doc/Documentation/kmod/modules.txt
https://www.ibm.com/support/knowledgecenter/ssw_aix_71/com.ibm.aix.kernel/loadable_kernel_modules.htm
https://www.ibm.com/support/knowledgecenter/ssw_aix_71/com.ibm.aix.kernel/creating_kernel_modules.htm
https://www.ibm.com/support/knowledgecenter/ssw_aix_71/com.ibm.aix.kernel/loading_unloading_kernel_modules.htm