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 most Gentoo systems already compile their own kernels, only minimal steps are necessary. These mainly consist of installing git (not included by because 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 -
 * 3) Stable - Stable sources are released mainline sources.
 * 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 development.

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

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.

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

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

Selecting a version
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 number is a permanent reference to version 4.2 of the vanilla kernel.

The .config file
Gentoo-based distributions have an advantage (some might count it as a disadvantage) over other distributions: they build their kernels locally on 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: