User:SwifT/Complete Handbook/Building the Linux kernel

Introduction
The Linux kernel is the core of the Linux operating system. It takes care of resource management (processes, memory, ...), hardware support, networking, file systems, ... and is therefore one of the most vital parts of the system.

Gentoo offers various kernel sources. Each source is based on the vanilla kernel source (the one developed by the main kernel developers) and adds in additional features, hardware support, experimental features, etc. You can pick whatever kernel source you like for your system (as long as your profile allows it of course).

When the source code is installed on your system, you still need to configure and build the kernel before you can use it. The kernel configuration is the trickiest part since a mistake can lead to an unusable kernel, but trying to build in too much leads to irrelevant code in your kernel which you'll never use, take space and might even cause troubles later when there is a kernel bug in that code.

Luckily, Gentoo offers a tool called which configures, builds and installs a kernel automatically. This might be of interest to you if you have no idea about configuring kernels, you want a basic kernel configuration for all your systems, or you require a kernel that can deal with a majority of hardware.

After configuring the kernel, it is built into an image which your computer loads in memory when you boot the system.

Picking a kernel source
Gentoo maintains a list of Gentoo kernel packages which contains a small introduction about the kernel tree.

You can make your choice from this guide, although you can very well pick a fairly generic one right now and use a different kernel later on - the kernel is completely interchangeable on a Linux environment so you don't have to decide on the kernel right here, right now.

The most default, generic kernel source is the vanilla-sources. This kernel tree is the one released by the Linux Kernel Developers, unmodified. Gentoo offers a patched version itself called gentoo-sources. Using these sources has the advantage that Gentoo can release a new kernel tree whenever it deems it necessary.

If you have made your choice, install the kernel sources using. Just add the kernel source name as an argument to and it will download and extract the kernel sources on your system:

Automated build process
If you don't want all the hassle surrounding the kernel installation, you can install and then have  configure, build, and install the Linux kernel for you. This process is quite simple:

However, is a lot more powerful than this. With this tool, you can maintain your personal kernel configuration and let the tool rebuild newer kernel versions with your settings. You can enable specific features (like bootsplash, lvm2, evms2, raid, ...) and tweak the compiler settings used during the kernel build process (which differs from the settings placed in !).

For more information on, please read the Genkernel guide.

Manual build process
The manual build process consists out of three steps:


 * Configuring the kernel.
 * Building the kernel.
 * Installing the kernel.

To configure the kernel, go to and run. You will get a dialog-based interface where you can configure your kernel.

Configuring a kernel isn't hard if you know what hardware you have and what features you want - but then again, if all this is new to you, finding out what features you want or need can be time consuming.

The kernel configuration dialogs has a good Help built-in which even includes search functionality (very useful if you want to search for the location of that network card you have but can't seem to place in the configuration structure).

It is not our intention to describe the kernel configuration process for you - there are several guides about this topic on the Internet and if you really aren't able to successfully configure a kernel, use for the time being.

When you're finished with the configuration part, build the kernel by running (hold on, we'll do this together with the next step). is a tool that reads in a script called in the directory you are in. s are very powerful when used for building software since they are able to only (re)build those parts that need to be (re)build instead of building the entire software over and over again.

To finish the kernel build process, you need to copy over the resulting kernel image to the boot partition and install the kernel modules you have selected. The location of the kernel image depends on the architecture you're using. The following table gives an overview of possible kernel images with the commands needed to build and install the kernel:

The build command is divided in two parts - the instruction we've discussed before and a specific instruction to finish off with some additional steps. The separation is made with the string. This is a specific operator to the shell, telling the system to continue with the next command if the previous one didn't fail. A similar operator is which tells the system to execute the next command if the previous one did fail.

Now, execute the build command to create the kernel image. When the process has finished, copy over the file to. It is wise to give the kernel image file a good name in so that you can distinguish one kernel from another. A common used naming scheme is. The next example copies over an kernel image to :