Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between .o and .ko file

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?

like image 538
beparas Avatar asked May 07 '12 05:05

beparas


People also ask

What are .KO files?

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.

How do I read a .KO file in Linux?

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.

What is the difference between modprobe and insmod?

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.

What does insmod do in Linux?

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.


1 Answers

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.

like image 187
gby Avatar answered Sep 27 '22 19:09

gby