How to Compile the Linux Kernel?

You may have been a regular user of Linux for some time and may have heard of compiling the Linux kernel. Your friends who are more tech savvy may have boasted about compiling Linux kernel and you might have wondered whether you will be able to do it by yourself. If this is the case, or you are keen on learning how to compile the kernel, this article is for you.

Why Compile?

The kernel is the heart of any Linux system. The kernel does all core functions such as talking to the hardware devices and getting your work done through them. When you first install your Linux operating system, a default, all-purpose kernel is installed with most common options. Such kernels are not finely customized for your computer in most of the time. As an example, you may install a Linux flavor which installs a kernel which supports PCMCIA cards. But in reality, your computer may not have any PCMCIA card. So, you have a kernel which is fat with unnecessary parts. This means, if you can get rid of these unnecessary modules, your kernel will run faster and will eventually give you a better computing experience when it comes to performance.

In addition, you may be running an old version of the kernel and may require you to install a newer version as hardware and software demand. In such case, you can obtain a newer version of the kernel and install it in your system after the compilation.

Therefore, customizing the kernel is required when you look for advantages such as above.

Let’s start with the process of compiling the kernel and installing it.

Getting the Kernel Source

The Linux kernel is maintained by the Linus Torvalds, the author of Linux is the one who personally maintains the kernel up to now. You can go to and get the latest kernel source from this site. Usually, this site is mirrored worldwide and you may be able to find a server located near you.

Once you download the latest kernel source, copy that to /etc/src.

Now issue the following command to unpack the source.

# tar zxf linux-<kernel_version>.tar

Configuring the Kernel

Go to /etc/src/Linux directory and issue the following command.

# make menuconfig

Then you will see a configuration window like below.

Compile the linux kernel

This is where you configure your kernel as you wish. You can remove all unnecessary modules and parts of the kernel and include all necessary things. As an example, you may have a newer video card where the kernel does not add the support by default. In such case, you can configure your kernel to support the video card you have.

Once you are done configuring, save the configurations and exit.

Then, issue the following command.

# make dep; make clean

The first part of the above command will build the dependencies of the kernel, based on your configuration. The second part of the command will clean the kernel source for the unwanted kernel configurations, such as leftovers from the previous kernel builds.


To compile the new kernel, issue the following command.

# make zImage

If you have a slower computer which falls under Pentium category, this is a good time for you to have a cup of tea or read a chapter of the book you read at present. The compilation process takes a lot of time and the time it takes depends on the speed of the computer. Once compilation is done, issue the following command to build modules.

# make modules

This step of the process will not take as much time as the previous step.

Installing the Kernel

Once the new kernel is compiled and built, the kernel should be properly installed. Issue the following commands to install the kernel.

# cp /usr/Linux/src/arch/i386/boot/zImage /boot/new_kernel

Then issue the following command.

# make modules_install

Now you have successfully installed your new Linux kernel.

Now go to the configuration file of your boot-loader and change it appropriately to get the new kernel loaded when the system boots.



Leave a Reply