I am writing simple Linux module mod.c. When I compile mod.c file, it creates two output file mod.o and mod.ko. So I just want to know, What is the difference between mod.o and mod.ko file?
ko files) are object files that are used to extend the kernel of the Linux Distribution. They are used to provide drivers for new hardware like IoT expansion cards that have not been included in the Linux Distribution.
As of Linux kernel version 2.6, KO files are used in place of . O files and contain additional information that the kernel uses to load modules. The Linux program modpost can be used to convert O files into KO files. NOTE: KO files may also be loaded by FreeBSD using the kldload program.
insmod is similar to modprobe: it can insert a module into the Linux kernel. Unlike modprobe, however, insmod does not read its modules from a set location, automatically insert them, and manage any dependencies. insmod can insert a single module from any location, and does not consider dependencies when doing so.
The insmod command is used to insert modules into the kernel. Kernel modules are usually used to add support for new hardware (as device drivers) and/or filesystems, or for adding system calls. This command inserts the kernel object file (. ko) into the kernel.
The short answer is that the .ko file is your object file linked with some kernel automatically generated data structures that are needed by the kernel.
The .o file is the object file of your module - the result of compiling your C file. The kernel build system then automatically creates another C file with some data structures describing the kernel module (named your_module_kmod.c), compile this C file into another object file and links your object file and the object file it built together to create the .ko file.
The dynamic linker in the kernel that is in charge of loading kernel modules, expects to find the data structure the kernel put in the kmod object in the .ko file and will not be able to load your kernel module without them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With