ELS Howto: Kernel Rebuild


Synopsis

This document gives an overview of how to prepare your Elemental Linux Server (ELS) installation to be able to build a custom kernel.


Prerequisites

You will need to have the ELS 'Extra Applications' CD-ROM mounted on /media/cdrom. and access the the Linux kernel source code (either downloaded from the internet or from the ELS 'Source' CD-ROM.)


Preparation

The instructions below describe how to get the system ready to compile a new Linux kernel.

  1. Install the gcc and perl packages from the ELS CD-ROM.
  2. Choose a spacious filesystem and create a directory to hold source code.
  3. Link the newly created source code directory to the traditional /usr/src location.
  4. Unpack the Linux source code and create a symbolic link named /usr/src/linux that points to it.
  5. Extract the current Linux config file from the /proc directory to /usr/src/linux/.config.

Example

The following example shows how you would carry out the steps above using an ELS CD-ROM mounted on /media/cdrom and a source code directory of /home/joe/src.

cd /
tar -zxf /media/cdrom/extra/gcc-4.2.4.i586.tar.gz
tar -zxf /media/cdrom/extra/perl-5.10.i586.tar.gz
cd /opt/bin
ln -s ../gcc-4.2.4/bin/* .
ln -s ../perl-5.10/bin/* .
mount -o remount,rw /usr
ln -s /opt/bin/perl /usr/bin/perl
mount -o remount,ro /usr

mkdir /home/joe/src
mount -o remount,rw /usr
ln -s /home/joe/src /usr/src
mount -o remount,ro /usr

cd /usr/src
tar -zxf /media/cdrom/src/linux-2.6.25.10.tar.gz
ln -s linux-2.6.25.10 linux

cd linux
zcat /proc/config.gz > .config

Building

The following instructions give a general idea of how to build a custom kernel, but do not go into the details of what options to configure. Your system requirements are unique and so your exact kernel configuration will be unique as well.

  1. Change to the directory holding the Linux source code.
  2. Configure the kernel options.
  3. Compile the kernel and modules.
  4. Make a backup copy of the old kernel just in case things don't work out.
  5. Install the new kernel and System.map to the /boot directory.
  6. Install the kernel modules under /lib/modules.

Example

The following example shows the commands used to build a new kernel.

cd /usr/src/linux

make menuconfig

make

cp /boot/vmlinuz /boot/vmlinuz.old
cp /boot/System.map /boot/System.map.old

make install

make modules_install

Note

If you elected to build a kernel without loadable module support, you may skip the last step.


Testing

Reboot to test your new kernel. If things do not go well and the system is not bootable, you can use the vmlinuz.old kernel as a fallback.

Here's how to use the backup kernel if the new kernel makes the system unbootable:

  1. Restart the system.
  2. Interrupt the automatic boot selection by pressing the <ESC> key when the GRUB menu appears.
  3. Use the arrow keys to select the "Normal Boot" entry.
  4. Press the e key to edit the entry.
  5. Select the line that begins with the word kernel and press the e key again.
  6. Change vmlinuz to vmlinuz.old and press <Enter>.
  7. Press the b key to boot.

Additional Information

You may also wish to consult Kwan Lowe's Kernel Rebuild Guide for a more detailed tutorial on kernel building.