User:Maffblaster/Drafts/Kernel hacking

This guide describes some of the steps necessary to use Gentoo Linux to hack on (develop) the Linux kernel. Since Gentoo systems compile their own kernels, only a few more steps are necessary. These mainly consist of installing git (installed by default in Gentoo), cloning the Kernel sources, checking out a tag,

Emerge
Most of the needed tools are already installed on the system, however a few extras will be needed for Kernel hacking. Make sure the main Gentoo repository has been synced for the newest ebuilds, then execute the following command:

Kernel sources
As explained on Kernel.org, there are several categories of kernel releases. From fresh to stale:


 * 1) Prepatch - Also known as release candidates, prepatch kernels must be tested.
 * 2) Mainline - Official major.minor versions tagged by Linus.
 * 3) Stable - Stable sources are released mainline sources with a patch number added to the end. They are the basis for longterm releases.
 * 4) Longterm - In Longterm releases important bug fixes are applied. These sources are mainly to support systems running old kernels and are not meant for kernel development.

For the purposes of this guide stable sources will be used as the example sources.

Stable
The next step is to clone the stable kernel sources using :

The kernel sources are quite large. Depending on connection speed and computing power it could take a significant amount of time to complete a clone. Be patient, yet efficient while waiting for a clone.

Release candidate
It is also possible to use release candidate sources. As one would think, the release candidates are more volatile than the stable sources mentioned above, but they can be cloned if desired. Release candidate sources contain newer source code:

Selecting a version
Change the current working directory to the root of cloned sources location.

Linux kernel developers use a feature in called tagging in order to keep track of kernel versions. Before compiling the kernel from sources, it is necessary to select a version. For the purposes this guide we'll be selecting kernel version 4.2. To list all available from which to choose use git's tag command:

Of course the output from the command can be sorted using other command-line utilities such as  and.

Check out version 4.2:

To verify everything has gone smoothly look at the first entry in the git log:

It is possible to see the commit id:. This identifier is a permanent reference to version 4.2 of the vanilla kernel.

The .config file
As mentioned above, Gentoo-based distributions have an advantage (some might count it as a disadvantage) over other distributions: they build their kernels locally for each kernel upgrade. If the system is running simply copy the kernel's file from the  directory to the directory containing the newly kernel sources:

If the Linux kernel currently running on the system has the symbol set, then it is also possible copy the currently running kernel's configuration directly to the cloned kernel sources location.