Compiling a Linux Kernel
Using Debian's kernel-package

There are many reasons for building a custom kernel, and many things to know about the process. This document doesn't address those issues, focusing instead on a great benefit of using Debian GNU/Linux: the kernel-package package, which handles the nitpicky details of compiling a kernel and generates the new kernel image as a Debian package, complete with modules. This package gets installed and maintained like any other Debian package.

Most of the steps can be carried out as a normal, non-root user, although some require the fakeroot tool.

Begin with a terminal, local or ssh. If you wish to use the X11 configuration option (make xconfig), start the terminal from a workstation running X11 (the machine doing the kernel build need not be running X, but you might need to install xbase-clients so it can talk to the X machine).

  1. As root, add yourself to the src group (this lets you do most of the following tasks as yourself, rather than root):

    $ su
    # adduser [you] src

  2. Still as root, install the following packages—note that the kernel source is large (tens of megabytes):

    # apt-get install bzip2 fakeroot kernel-package kernel-source-2.x.y task-tclt

  3. Log-"all the way"-out and back in as yourself to enable the group change:

    # exit
    (login as [you])

  4. Unpack the kernel source tarball (installing the package placed it in /usr/src/):

    cd /usr/src/
    tar xvjf kernel-source-2.x.y.tar.bz2

  5. Create a symlink to the kernel-source directory and cd to it:

    ln -s kernel-source-2.x.y linux
    cd linux

  6. Configure the kernel. If an X server is available, use make xconfig, otherwise use make menuconfig. This is where the meat of kernel-building lies, but it's the same regardless whether you use the Debian kernel-package or not.
  7. Clean the source tree and reset the kernel-package parameters:

    make-kpkg clean

  8. Compile the kernel (substitute your machine's name for simon):

    fakeroot make-kpkg --revision=3:simon.1.0 kernel_image

    Be sure to include a revision number (here 1.0) and increment it in future versions, so the Debian package database can tell which of your custom kernel packages are newer. Also add an "epoch" number (here 3:) to the revision parameter so APT never attempts to "upgrade" your custom kernel automatically with a default distro kernel. In a sense, you've told APT that your custom kernels are always newer.

    When the compilation completes, /usr/src/ will contain the new kernel image as a Debian package:


  9. As root, install the kernel as any other package:

    cd ..

    dpkg -i kernel-image-2.x.y_simon.1.0_i386.deb
    Would you like to create a boot floppy now? [No] y
    You already have a LILO configuration in /etc/lilo.conf
    Install a boot block using the existing /etc/lilo.conf? [Yes] yes
    Testing lilo.conf ...
    Testing successful. Installing the partition boot sector...
    Installation successful.

    (Since /vmlinux is a symlink and the package updates it, the existing lilo.conf is still just fine.)

  10. Boot the new kernel. It's best to be physically at the machine, in case there's a problem.

References and Resources

Thanks to Rob Kidd of NOVALUG for his detailed comments on my original outline, and especially his advice to be in the src group and to use an epoch number.

Installing Debian GNU/Linux 2.2 For Intel x86
dselect Tutorial
The Debian GNU/Linux FAQ
Debian WWW search site
Debian User Reference Manual
Mailing List Archives

Ted Ruegsegger Free Software Foundation Associate Member # 33