Do you need to compile a kernel module?
Compiling Kernel Modules Kernel modules need to be compiled a bit differently from regular userspace apps. Former kernel versions required us to care much about these settings, which are usually stored in Makefiles.
How to make a Makefile for a module?
So, let’s look at a simple Makefile for compiling a module named hello-1.c: Example 2-2. Makefile for a basic kernel module From a technical point of view just the first line is really necessary, the “all” and “clean” targets were added for pure convenience. Now you can compile the module by issuing the command make .
How to remove a module from the Linux kernel?
Congratulations, you are now the author of Linux kernel code! When the novelty wears off, remove your module from the kernel by using rmmod hello-1. Take a look at /var/log/messages just to see that it got logged to your system logfile. Here’s another exercise for the reader.
How to build a kernel module for Raspberry Pi 2?
The first few lines are from http://lostindetails.com/blog/post/Compiling-a-kernel-module-for-the-raspberry-pi-2 The rest I wrote to automate more of the process. Once all of that runs successfully, I have the source that should exactly match the running kernel, the configuration to match and a symlink.
Where are the modules in the Linux kernel?
All modules loaded into the kernel are listed in /proc/modules. Go ahead and cat that file to see that your module is really a part of the kernel. Congratulations, you are now the author of Linux kernel code!
How to find the version of a compiled kernel?
Tested with this setup on kernel 4.9.6. version is set by the MODULE_VERSION macro. The file does not exist if the MODULE_VERSION macro is not used in the module. srcversion is an MD4 hash of the source code used to compile the kernel module.
How to display messages in a kernel module?
To display kernel messages, you can use the dmesg command or inspect the logs: Compiling a kernel module differs from compiling an user program. First, other headers should be used. Also, the module should not be linked to libraries.