One of the scariest moments in many Linux users' lives is the moment when they ask someone for help, and they get the reply, "You really have to/need to/should recompille your kernel to make that work."
In this article, I hope to take some of the fear out of the process, and make it all a bit less intimidating. This article is aimed at the user who is familiar with the use (or at least the basic concepts) of file storage and the command line, but doesn't necessarily know about compiling things from source.
What's a kernel?
The kernel is the most fundamental part of the operating system. It's the Linux part of "GNU/Linux". It controls the memory allocation, handles the multitasking of applications, enforces some security controls, deals with the interfaces to all of the hardware (through device drivers), and manages the file storage on the machine (through filesystem drivers).
Why do I want to recompile it?
There could be several reasons to recompile your kernel. Among them:
- Optimising for your processor.
- Adding a driver or feature which wasn't in the original kernel shipped by your distribution.
- Upgrading to a new kernel before your distribution packages it.
- Removing all the unused cruft from the "generic" kernels supplied by your distribution.
- Testing development kernels.
How do I recompile my kernel?
There are four stages you need to go through: get the sources & unpack, configure, compile, and install. The most complicated is the configuration. After that, it gets easier and, in general, considerably less intimidating.
Getting the sources
First, you will need the kernel source. Most distributions ship kernel source packages for various versions. These will almost always have additional patches in them, giving you extra features or bugfixes. Some of the vendor kernels (like Red Hat's, for example) are very heavily modified. Take a look in your distribution's package store for a suitable kernel source package.
There are also a large number of other kernel sources available – the most commonly-used one is the "official" one from Linus Torvalds, sometimes referred to as the "Linus", or the "vanilla" kernel. These can be downloaded from http://www.kernel.org/ and its mirrors.
After downloading the kernel source, unpack it. This will depend on the form that you got it in (Debian, for example, will unpack it automatically), but the standard "tarball" (linux-x.y.z.tar.gz or linux-x.y.z.tar.bz2) form from kernel.org can be unpacked with either
$ tar -xzf linux-x.y.z.tar.gz
$ tar -xjf linux-x.y.z.tar.bz2
depending on which one you downloaded. I would suggest doing this either in /usr/src or in /usr/local/src.
This section is incomplete.
$ cp /boot/Config-old-kernel .config $ make oldconfig $ make menuconfig
Building the kernel
Building a kernel is the easiest bit of the process, although possibly the longest as well. Just run
$ make bzImage
If you are using modules, you should also run
$ make modules
This will take anywhere between a couple of minutes and several hours, depending on the number of features you configured in, the speed of the machine, and the vintage of the kernel. My K6-2/500 takes about an hour to compile a fairly feature-rich 2.4 kernel. It can do an empty-ish 2.0 kernel in a few minutes.
This section is incomplete.
1. cp arch/i386/boot/bzImage /boot/vmlinuz-newkernel 1. make modules-install 1. nano /etc/lilo.conf 1. lilo