Linux Kernel Modules: Getting started

Published 22-Feb-202120 min

About The Linux Kernel Modules Series

As part of my research I had a number of situations where the Linux Kernel's functionality was just not enough. Thankfully, the developers foresaw these situations and thus we got the chance to extend the kernel using kernel modules. Kernel modules are relatively straightforward to write once you get the hang of it. Even though the kernel writing process has barely changed since 2007 when this guide was published. The kernels have advanced a bit and I am planning to give a new, updated and summarised version of the following.

What Is a Kernel Module


Writing Your First Kernel Module

Disclaimer: When working with kernel modules (or anything kernel related in that matter) you are playing with the bare metal of your operating system! This means that every otherwise segmentation fault or stack overflow could wind up your machine in a corrupted state.
To circumvent the dangers of accidentally corrupting your main machine or so you do not have to restart it after every mistake I recommend always using a VM when doing any kernel development.


Compiling Your First Kernel Module


Using Your First Kernel Module


Final Words

That is it... Thanks for following along, and I hope I have helped you in your first kernel module writing journey. The kernel module that we did here is not particularly useful but I hope I managed to demystify the basics of the process a bit. For more advanced example, take a look at the complete tutorial here. If I can find the time: I pledge to write an advanced guide that takes a look at extending the TCP stack.