This is Gentoo's testing wiki. It is a non-operational environment and its textual content is outdated.

Please visit our production wiki at https://wiki.gentoo.org

User:Maffblaster/Drafts/Kernel hacking

From Gentoo Wiki (test)
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 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,

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 -
  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 git:

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:

Configuration

Selecting a version

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 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 .config file from the /usr/src/linux directory to the directory containing the newly kernel sources:

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

Removal

Kernel sources

Stable

user $rm -rf ~/linux-stable

Release canidate

user $rm -rf ~/linux

References