Gentoo Logo

1.  Installing the Sources

Choosing a Kernel

The core around which all distributions are built is the Linux kernel. It is the layer between the user programs and your system hardware. Gentoo provides its users several possible kernel sources. A full listing with description is available at the Gentoo Kernel Guide.

MIPS-based systems have just the one kernel tree to choose from, mips-sources. This patchset differs from the ones available for other architectures, in that it has lots of patches specific to the MIPS architecture.

Code Listing 1.1: Merging kernel sources...

# emerge mips-sources

Important: On the Origin 200/2000, Indigo2 Impact (R10000), Octane/Octane2 and O2, a 64-bit kernel is required to boot these systems. For these machines, you should emerge kgcc64 to create a cross-compiler for building 64-bit kernels.

Code Listing 1.1: Installing kgcc64

# emerge kgcc64

When you take a look in /usr/src you should see a symlink called linux pointing to your kernel source. In this case, the installed kernel source points to mips-sources-${kernel-version}. Your version may be different, so keep this in mind.

Code Listing 1.1: Viewing the kernel source symlink

# ls -l /usr/src/linux
lrwxrwxrwx    1 root     root           12 Oct 13 11:04 /usr/src/linux -> linux-${kernel-version}

Now it is time to configure and compile your kernel source.

1.  Kernel Compilation & Installation

Introduction

Previously, we went through the manual configuration of how to set up the kernel sources. This has become impractical with the number of systems we now support. This section details various sources for sample kernel configurations.

Using sample configurations in the kernel source

Many of the systems supported have sample .configs hiding in amongst the kernel source. Not all systems have configs distributed in this way. Those that do, can be configured using the commands mentioned in the table below.

System Configure command
Cobalt Servers make cobalt_defconfig
Indy, Indigo2 (R4k), Challenge S make ip22_defconfig
Origin 200/2000 make ip27_defconfig
Indigo2 Impact (R10k) make ip28_defconfig
O2 make ip32_defconfig

Using the running kernel config from the installation media

All of the Gentoo installation images provide a kernel config option as part of the image itself, accessible as /proc/config.gz. This may be used in many cases. It is best though if your kernel source matches closely, the kernel that is currently running. To extract it, simply run it through zcat as shown below.

Code Listing 1.1: Extracting .config from /proc/config.gz

# zcat /proc/config.gz > .config

Important: This kernel config is set up for a netboot image. That is, it will expect to find a root filesystem image somewhere nearby, either as a directory for initramfs, or a loopback device for initrd. When you run make menuconfig below, don't forget to go into General Setup and disable the options for initramfs.

The Hardware Compatibility Database

As an aid to users in finding working settings, a hardware compatibility database was set up. This database lists the support for various MIPS devices, and allows users to contribute kernel configurations that are known to work. The address for this site is http://stuartl.longlandclan.hopto.org/gentoo/mips.

If you find this service useful, you're welcome to contribute your notes and .config files so that others may benefit from your experience. It should be noted however that there is no guarantee that any of the configuration files downloaded from this site will work.

Customising the configuration for your needs

Once you have found a configuration, download it into your kernel source directory, and rename it to .config. From there, you can run make oldconfig to bring everything up to date, and allow you to customise the configuration before compiling.

Code Listing 1.1: Configuring the kernel

# cd /usr/src/linux
# cp /path/to/example-config .config
# make oldconfig
(Just press ENTER at each prompt to accept the defaults... we'll customise later)
# make menuconfig

Important: In the Kernel Hacking section, there is an option named "Are You Using A Cross Compiler?". This tells the kernel Makefiles to prepend "mips-linux-" (or mipsel-linux ... etc) to gcc and as commands when compiling the kernel. This should be turned off, even if cross-compiling. Instead, if you do need to call a cross-compiler, specify the prefix using the CROSS_COMPILE variable as shown in the next section.

Important: There is a known issue with JFS and ALSA on Octane systems where the ALSA fails to work. Given the experimental nature of JFS on MIPS, it is recommended that people avoid using JFS for the time being.

Compiling and Installing

Now that your kernel is configured, it is time to compile and install it. Exit the configuration and start the compilation process:

Note: On 64-bit machines, you need to specify CROSS_COMPILE=mips64-unknown-linux-gnu- (or mips64el-... if on a little-endian system) to use the 64-bit compiler.

Code Listing 1.1: Compiling the kernel

(Compiling natively)
# make vmlinux modules modules_install

(Cross-compiling on target machine)
(Adjust the mips64-unknown-linux-gnu- accordingly)
# make vmlinux modules modules_install CROSS_COMPILE=mips64-unknown-linux-gnu-

(When compiling on another machine, such as an x86 box, use the)
(following commands to compile the kernel & install modules into)
(a specific directory to be transferred to the target machine.)
# make vmlinux modules CROSS_COMPILE=mips64-unknown-linux-gnu-
# make modules_install INSTALL_MOD_PATH=/somewhere

Important: When compiling a 64-bit kernel for the Indy, Indigo2 (R4k), Challenge S and O2, use the vmlinux.32 target instead of vmlinux. Otherwise, your machine will not be able to boot. This is to work around the PROM not understanding the ELF64 format.

Code Listing 1.1: Using the vmlinux.32 target

# make vmlinux.32
(This will create vmlinux.32 -- which is your final kernel)

When the kernel has finished compiling, copy the kernel image to /boot.

Note: On Cobalt servers, the bootloader will expect to see a compressed kernel image. Remember to gzip -9 the file once it is in /boot.

Code Listing 1.1: Installing the kernel

# cp vmlinux /boot/kernel-${kernel-version}

(Cobalt Servers -- Compressing the kernel image)
# gzip -9v /boot/kernel-${kernel-version}

1.  Kernel Modules

Configuring the Modules

You should list the modules you want automatically loaded in /etc/conf.d/modules. You can add extra options to the modules too if you want.

To view all available modules, run the following find command. Don't forget to substitute "<kernel version>" with the version of the kernel you just compiled:

Code Listing 1.1: Viewing all available modules

# find /lib/modules/<kernel version>/ -type f -iname '*.o' -or -iname '*.ko' | less

For instance, to automatically load the 3c59x.ko module (which is the driver for a specific 3Com network card family), edit the /etc/conf.d/modules file and enter the module name in it.

Code Listing 1.1: Editing /etc/conf.d/modules

# nano -w /etc/conf.d/modules
modules_2_6="3c59x"

Continue the installation with (Configuring your System).

Page updated December 17, 2013

Summary: The Linux kernel is the core of every distribution. This chapter explains how to configure your kernel.

Donate to support our development efforts.

Copyright 2001-2014 Gentoo Foundation, Inc. Questions, Comments? Contact us.