Linux/Compiling the Linux kernel

Compiling the Linux Kernel from the source code will allow you to get a great understanding of the internal workings of the kernel. Obtaining the source code, modifying, and then compiling and installing it is explained in this article. All examples are done on a Fedora 11 virtual machine.

Kernel Versions edit

The developers of the linux kernel use a numbering system to track the newest versions of the source code. The current major revision is 2.6. Numbers following this version, (example, indicate minor revisions and bug fixes. More details can be found on the Wikipedia article for the linux kernel. Linux Kernel Version numbering

Obtaining the latest Linux Kernel version edit

The latest kernel source code is always available from To start with we need to obtain the latest stable release of the Linux kernel. This should be downloaded and extracted into the right directory on our linux machine. Typically, the kernel will be kept in the /usr/src/kernels directory, so we will use this in this guide.

Assuming the kernel package has been downloaded to your Download folder, the following command will copy this to our working directory.

cp ~/home/<your system username>/Download/linux-2.6.32.tar.bz2 /usr/src/kernels/

To then extract the files we use the 'tar' program.

tar -jxvf linux-2.6.32.tar.bz2

This will leave the original compressed file in your /usr/src/kernels directory. We can delete this using the rm command, leaving just our uncompressed directory.

rm linux-2.6.32.tar.bz2

You can now browse the entire Linux source code at your leisure.

Compiling edit

The Linux Kernel is distributed with it's 'Makefile'. This file is a set of rules which simplifies the procedure of compiling the kernel. To use the Makefile to build the kernel, there are two commands.

make all
make modules_install

You can expect this to be a time consuming process. How long it will take exactly depends on your machines hardware. To install the kernel you just compiled, you can use the command,

make install

This will install the Kernel to your system and add the record to your grub loader. Once you reboot your system, make sure to select your new kernel version from the grub menu.

Modifying edit

The Makefile can also be used to modify aspects of the kernel before you compile it. To access the tool used to modify our kernel, we use

make menuconfig

This will bring up the interface used for our modifications. This requires the 'ncurses-devel' library to be installed. Use your package manager to install this if required.

The kernel can be compiled with a huge amount of different options set. Explaining each is beyond the scope of this document, but if it is not self-explanatory from the title, then an Internet search should yield enough results to help explain what that option does.

The Linux kernel is primarily written in the C language. To experiment with making modifications to the source code, you can open up the relevant .c file and make your changes. Once you wish to compile the kernel after your changes, you can run this make command, which will only compile what you have changed, saving a lot of time rather than compiling the whole kernel again.


See also edit