Linux kernel is the most fascinating thing for Linux geeks. It is the kernel we call Linux, nothing else. Therefore, everyone wants to know what the kernel is and how it works. Apart from that, there are other geeks who want to change the kernel, patch the kernel, or simply contribute for kernel development. If you are such a brave person who wants to start Linux kernel programming, letâ€™s explore a way of doing it.
If you do not know C programming language, you will have to learn it. The Linux kernel is written in C. Therefore, you cannot go anywhere with kernel programming if you do not know some intermediate C. In order to learn C, you can take programming courses offered by many institutions. In addition, you can buy some good books written in C programming through Amazon or just borrow a few books from your local library.
Although almost all the C programming is the same for any platform, there are a few differences as well. Therefore, it is always a good idea to practice your C exercises in a Linux environment.
Read the Source
Before you go on programming the kernel, you need to understand the kernel in detail. The kernel is a vast area for one to understand. Therefore, you can select a section of the kernel that you are most interested in and start reading the kernel source of the same section. When the kernel source is read, you will find many obstacles in understanding C functions as well as some programming algorithms. In such cases, you can simply look for online help or just talk to an experienced kernel programmer. It is always a good idea to have an experienced kernel programmer as your mentor in your quest of kernel programming.
Books play a great role in kernel programming. Although the Internet has most of the information you require, books offer you a great deal of information and methodology. There are hundreds of books written about Linux kernel programming, so it is just a matter of reading a number of reviews in order to find what best for you. Personally, I use â€˜Linux Kernel Programmingâ€™ by Michael Beck and others. This is a great source in understanding the kernel.
Setting up a Test Environment
In order to experiment with the kernel, you need to setup a test environment. If you attend to experiment in the Linux environment you use for day-to-day work, you will easily end-up crashing your Linux system. Therefore, setup a dedicated test environment for the kernel play. The easiest way of doing this is setting up a virtual environment using VirtualBox or VMware. Once installed and properly configured, you can back-up an image of your system, so that can be restored with in a matter of minutes if something goes wrong. Trust me, there will be many things going wrong when you start playing with the kernel.
Start with the System Environment, then the Kernel
Before getting into the core kernel functionality, start with the system calls and the environment. See how the system calls enter into the kernel space from the user space. This is supposed to be the most recommended entry point for new kernel programmers. Once this concept and related technical details are understood, you can move onto more complex areas of the Linux kernel.
As a last point, remember that you are going to do kernel programming for your own satisfaction and contribute back to the Linux and open source community. If you do it for you, you will excel in what you do within a matter of months. Unfortunately, some people attend kernel programming simply to impress others and eventually fail miserably.