User:Maffblaster/Drafts/Kernel hacking

From Gentoo Wiki
Jump to:navigation Jump to:search

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,

Installation

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:

root #emerge --ask --update sys-libs/ncurses sys-devel/gcc sys-devel/make dev-vcs/git dev-util/ctags sys-devel/bc

Kernel sources

As explained on Kernel.org[1], 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 git:

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:

Configuration

Selecting a version

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

Linux kernel developers use a feature in git 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:

user $git tag -l

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

Check out version 4.2:

user $git checkout -b stable v4.2

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

user $git log -n 1
commit 64291f7db5bd8150a74ad2036f1037e6a0428df2
Author: Linus Torvalds <torvalds@linux-foundation.org>
Date:   Sun Aug 30 11:34:09 2015 -0700

    Linux 4.2

It is possible to see the commit id: 64291f7db5bd8150a74ad2036f1037e6a0428df2. 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 .config file from the /usr/src/linux directory to the directory containing the newly kernel sources:

user $cp /usr/src/linux/.config ~/linux-stable

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.

Removal

Kernel sources

Stable

user $rm -rf ~/linux-stable

Release candidate

user $rm -rf ~/linux

References