Gentoo Logo

[ << ] [ < ] [ Home ] [ > ] [ >> ]


7. Configuring the Kernel

Content:

7.a. 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.

For AMD64-based systems we have gentoo-sources (kernel source patched for extra features).

Choose your kernel source and install it using emerge.

Code Listing 1.1: Installing a kernel source

# emerge gentoo-sources

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 gentoo-sources-3.4.9. Your version may be different, so keep this in mind.

Code Listing 1.2: Viewing the kernel source symlink

# ls -l /usr/src/linux
lrwxrwxrwx    1 root   root    12 Oct 13 11:04 /usr/src/linux -> linux-3.4.9

Now it is time to configure and compile your kernel source. You can use genkernel for this, which will build a generic kernel as used by the Installation CD. We explain the "manual" configuration first though, as it is the best way to optimize your environment.

If you want to manually configure your kernel, continue now with Default: Manual Configuration. If you want to use genkernel you should read Alternative: Using genkernel instead.

7.b. Default: Manual Configuration

Introduction

Manually configuring a kernel is often seen as the most difficult procedure a Linux user ever has to perform. Nothing is less true -- after configuring a couple of kernels you don't even remember that it was difficult ;)

However, one thing is true: you must know your system when you start configuring a kernel manually. Most information can be gathered by emerging pciutils (emerge pciutils) which contains lspci. You will now be able to use lspci within the chrooted environment. You may safely ignore any pcilib warnings (like pcilib: cannot open /sys/bus/pci/devices) that lspci throws out. Alternatively, you can run lspci from a non-chrooted environment. The results are the same. You can also run lsmod to see what kernel modules the Installation CD uses (it might provide you with a nice hint on what to enable).

Now go to your kernel source directory and execute make menuconfig. This will fire up an ncurses-based configuration menu.

Code Listing 2.1: Invoking menuconfig

# cd /usr/src/linux
# make menuconfig

You will be greeted with several configuration sections. We'll first list some options you must activate (otherwise Gentoo will not function, or not function properly without additional tweaks).

Activating Required Options

Make sure that every driver that is vital to the booting of your system (such as SCSI controller, ...) is compiled in the kernel and not as a module, otherwise your system will not be able to boot completely.

We shall then select the exact processor type. The x86_64 kernel maintainer strongly recommends users enable MCE features so that they are able to be notified of any hardware problems. On x86_64, these errors are not printed to dmesg like on other architectures, but to /dev/mcelog. This requires the app-admin/mcelog package. Make sure you select IA32 Emulation if you want to be able to run 32-bit programs. Gentoo will install a multilib system (mixed 32-bit/64-bit computing) by default, so this option is required.

Note: If you plan to use a non-multilib profile (for a pure 64-bit system), then you don't have to select IA32 Emulation support. However, you'll also need to follow the instructions for switching to a non-multilib profile, as well as choosing the correct bootloader.

Code Listing 2.2: Selecting processor type and features

Processor type and features  --->
   [ ] Machine Check / overheating reporting 
   [ ]   Intel MCE Features
   [ ]   AMD MCE Features
  Processor family (AMD-Opteron/Athlon64)  --->
    ( ) Opteron/Athlon64/Hammer/K8
    ( ) Intel P4 / older Netburst based Xeon
    ( ) Core 2/newer Xeon
    ( ) Intel Atom
    ( ) Generic-x86-64
Executable file formats / Emulations  --->
   [*] IA32 Emulation

Next select Maintain a devtmpfs file system to mount at /dev so that critical device files are already available early in the boot process.

Code Listing 2.3: Enabling devtmpfs support

Device Drivers --->
  Generic Driver Options --->
    [*] Maintain a devtmpfs filesystem to mount at /dev
    [ ]   Automount devtmpfs at /dev, after the kernel mounted the rootfs

Now go to File Systems and select support for the filesystems you use. Don't compile the file system you use for the root filesystem as module, otherwise your Gentoo system will not be able to mount your partition. Also select Virtual memory and /proc file system.

Code Listing 2.4: Selecting necessary file systems

File systems --->
(Select one or more of the following options as needed by your system)
  <*> Second extended fs support
  <*> Ext3 journalling file system support
  <*> The Extended 4 (ext4) filesystem
  <*> Reiserfs support
  <*> JFS filesystem support
  <*> XFS filesystem support
  ...
  Pseudo Filesystems --->
    [*] /proc file system support
    [*] Virtual memory file system support (former shm fs)

(Enable GPT partition label support if you used that previously)
-*- Enable the block layer --->
    ...
    Partition Types --->
    [*] Advanced partition selection
      ...
      [*] EFI GUID Partition support

If you are using PPPoE to connect to the Internet or you are using a dial-up modem, you will need the following options in the kernel:

Code Listing 2.5: Selecting PPPoE necessary drivers

Device Drivers --->
  Network device support --->
    <*> PPP (point-to-point protocol) support
    <*>   PPP support for async serial ports
    <*>   PPP support for sync tty ports

The two compression options won't harm but are not definitely needed, neither does the PPP over Ethernet option, that might only be used by ppp when configured to do kernel mode PPPoE.

If you require it, don't forget to include support in the kernel for your ethernet card.

If you have a multi-CPU Opteron or a multi-core (e.g. AMD64 X2) system, you should activate "Symmetric multi-processing support":

Code Listing 2.6: Activating SMP support

Processor type and features  --->
  [*] Symmetric multi-processing support

Note: In multi-core systems, each core counts as one processor.

If you use USB Input Devices (like Keyboard or Mouse) don't forget to enable those as well:

Code Listing 2.7: Activating USB Support for Input Devices

Device Drivers --->
  [*] HID Devices  --->
    <*>   USB Human Interface Device (full HID) support

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:

Code Listing 2.8: Compiling the kernel

# make && make modules_install

When the kernel has finished compiling, copy the kernel image to /boot. Use whatever name you feel is appropriate for your kernel choice but make sure it starts with linux- or vmlinuz- so that the boot loader scripts can automatically detect the new kernels later. Remember to replace kernel-3.4.9-gentoo with the name and version of your kernel.

Code Listing 2.9: Installing the kernel

# cp arch/x86_64/boot/bzImage /boot/kernel-3.4.9-gentoo

(Optional) Building an Initramfs

If you use a specific partition layout where important file system locations (like /usr or /var) are on separate partitions, then you will need to setup an initramfs so that this partition can be mounted before it is needed.

Without an initramfs, you risk that the system will not boot up properly as the tools that are responsible for mounting the file systems need information that resides on those file systems. An initramfs will pull in the necessary files into an archive which is used right after the kernel boots, but before the control is handed over to the init tool. Scripts on the initramfs will then make sure that the partitions are properly mounted before the system continues booting.

To install an initramfs, install genkernel first, then have it generate an initramfs for you.

Code Listing 2.10: Building an initramfs

# emerge genkernel
# genkernel --install initramfs

If you need specific support in the initramfs, such as lvm or raid, add in the appropriate options to genkernel. See genkernel --help for more information, or the next example which enables support for LVM and software raid (mdadm):

Code Listing 2.11: Building an initramfs with support for LVM and software raid

# genkernel --lvm --mdadm --install initramfs

The initramfs will be stored in /boot. You can find the file by simply listing the files starting with initramfs:

Code Listing 2.12: Checking the initramfs file name

# ls /boot/initramfs*

Now continue with Kernel Modules.

7.c. Alternative: Using genkernel

If you are reading this section, you have chosen to use our genkernel script to configure your kernel for you.

Now that your kernel source tree is installed, it's now time to compile your kernel by using our genkernel script to automatically build a kernel for you. genkernel works by configuring a kernel nearly identically to the way our Installation CD kernel is configured. This means that when you use genkernel to build your kernel, your system will generally detect all your hardware at boot-time, just like our Installation CD does. Because genkernel doesn't require any manual kernel configuration, it is an ideal solution for those users who may not be comfortable compiling their own kernels.

Now, let's see how to use genkernel. First, emerge the genkernel ebuild:

Code Listing 3.1: Emerging genkernel

# emerge genkernel

Now, compile your kernel sources by running genkernel all. Be aware though, as genkernel compiles a kernel that supports almost all hardware, this compilation will take quite a while to finish!

Note that, if your boot partition doesn't use ext2 or ext3 as filesystem you might need to manually configure your kernel using genkernel --menuconfig all and add support for your filesystem in the kernel (i.e. not as a module). Users of LVM2 will probably want to add --lvm as an argument as well.

Code Listing 3.2: Running genkernel

# genkernel all

Once genkernel completes, a kernel, full set of modules and initial ram disk (initramfs) will be created. We will use the kernel and initrd when configuring a boot loader later in this document. Write down the names of the kernel and initrd as you will need it when writing the bootloader configuration file. The initrd will be started immediately after booting to perform hardware autodetection (just like on the Installation CD) before your "real" system starts up.

Code Listing 3.3: Checking the created kernel image name and initrd

# ls /boot/kernel* /boot/initramfs*

7.d. 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 4.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 4.2: Editing /etc/conf.d/modules

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

Continue the installation with Configuring your System.


[ << ] [ < ] [ Home ] [ > ] [ >> ]


Print

View all

Page updated April 12, 2014

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

Sven Vermeulen
Author

Grant Goodyear
Author

Roy Marples
Author

Daniel Robbins
Author

Chris Houser
Author

Jerry Alexandratos
Author

Seemant Kulleen
Gentoo x86 Developer

Tavis Ormandy
Gentoo Alpha Developer

Jason Huebel
Gentoo AMD64 Developer

Guy Martin
Gentoo HPPA developer

Pieter Van den Abeele
Gentoo PPC developer

Joe Kallar
Gentoo SPARC developer

John P. Davis
Editor

Pierre-Henri Jondot
Editor

Eric Stockbridge
Editor

Rajiv Manglani
Editor

Jungmin Seo
Editor

Stoyan Zhekov
Editor

Jared Hudson
Editor

Colin Morey
Editor

Jorge Paulo
Editor

Carl Anderson
Editor

Jon Portnoy
Editor

Zack Gilburd
Editor

Jack Morgan
Editor

Benny Chuang
Editor

Erwin
Editor

Joshua Kinard
Editor

Tobias Scherbaum
Editor

Xavier Neys
Editor

Joshua Saddler
Editor

Gerald J. Normandin Jr.
Reviewer

Donnie Berkholz
Reviewer

Ken Nowack
Reviewer

Lars Weiler
Contributor

Donate to support our development efforts.

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