2.6 Kernels and "koutput" Peter Johanson This guide covers how to use Gentoo's new "koutput" method to handle 2.6 kernels and kernel modules. 1.0 March 14, 2004 Overview

The 2.6 kernel, among other things, provides many enhancements to the kernel build infrastructure, or "kbuild system." Among the features that have been added, the 2.6 kernel now allows all of the files created by the kernel to be output to a arbitrary seperate location. This has several advantages over the old method:

  1. Arbitrary users can all use the same sources to build kernels, outputting to some location in their home directory.
  2. Kernels can be built for multiple target architectures, and the generated files for each architecture won't be lost.
  3. /usr can be mounted read-only and still allow kernels to be generated, reconfigured, etc
  4. External modules can be built without requiring write access to /usr/src/linux

This last fact is important, as previously portage would need to be given temporary write access to a directory on the live filesystem in order to compile external modules against a 2.6 kernel source tree. If you chose not to use koutput for 2.6 kernels, most kernel modules will fail, due to this restriction. To allow portage to write to /usr/src/linux during kernel module emerges, you can use config-kernel:

Not all of config-kernel's features are discussed in this guide. For the rest of the information see man config-kernel
# config-kernel --allow-writable yes

At any later time you can revert this decision by using config-kernel again.

# config-kernel --allow-writable no
Enabling koutput

2.6 kernels determine where to output their files based on two environmental variables, KBUILD_OUTPUT and O. KBUILD_OUTPUT should be set environmentally, and can then be overriden on the command line by specifying a new O value. e.g.:

# cd /usr/src/linux>
# export KBUILD_OUTPUT="/var/tmp/kernel-output/2.6.4"
# mkdir /var/tmp/kernel-output/2.6.4
Set our output location, and make sure that directory exists
# make menuconfig
The generated .config ends up in
/var/tmp/kernel-output/2.6.4
# make O=/home/joe/kernels/2.6.4 menuconfig
The generated .config now ends up in
/home/joe/kernels/2.6.4

Gentoo's tool config-kernel provides a mechanism for automating some of this processes. Using config-kernel, you can define a prefix for where kernels that get installed by portage will output their files to.

# config-kernel --output-dir=/home/joe/kernels

The above command will make all new kernels installed send their output by default to /home/joe/kernels/KV where KV is the kernel version. To set the output path to the Gentoo default, which is /var/tmp/kernel-output/, you can do:

# config-kernel --output-dir=default

User can also convert already installed 2.6 kernels to the new method using config-kernel. Beware that this will cause all your previously generated files to be erased, since make mrproper must be run during this process.

# config-kernel --make-koutput=/usr/src/linux-2.6.3

The above command converts the kernel found in /usr/src/linux-2.6.3 to outputting to a different directory. If the output directory has been set previously with --output-dir=foo, then that prefix will be used. Otherwise, the Gentoo default of /var/tmp/kernel-output/KV will be used.

Repercussions

After configuring a kernel to use a different output directory, the changes go largly unnoticed when configuring and isntalling a kernel. A few key files change locations that you should be aware of though. The main files to be concered with are .config, and the generated bzImage after compiling a kernel. Below is a table showing the original and new locations for some key files. We assume the kernel is a 2.6.4 kernel outputting to the Gentoo default of /var/tmp/kernel-output/2.6.4.

/usr/src/linux/.config/var/tmp/kernel-output/2.6.4/.config/usr/src/linux/arch/i386/boot/bzImage/var/tmp/kernel-output/2.6.4/arch/i386/boot/bzImage
Old file location New file location