||Do you have questions?
We have answers!
Compiling a Linux Kernel
(the operating system)
by Don Chiasson
A few years ago, when you loaded Linux, it was often necessary to compile the kernel from source code, usually to include a less common network card or other device driver. Distributions now are good, and this is not necessary, but it is interesting, macho even, to roll ó er I mean build ó your own. There are many sites that give instructions on how to do so, but for whatever reason I chose the ones below.
Linux is written in C (not C++) using the gcc compiler. There are straightforward procedures for doing the build, basically a series of questions. You donít have to know anything about C or the internals of the kernel.
General information on compiling a kernel at: http://kernelnewbies.org/FAQ
then, look under "How Do I Compile a Kernel" at: http://kernelnewbies.org/FAQ/KernelCompilation
How do I compile a kernel?
These instructions assume we are installing version 2.6.0 of the kernel, replace all instances with the version you are trying to build. These instructions are also x86-specific; other architectureís build procedures may differ.
(1) Download your tarball from ftp.XX.kemel.org where XX is your country code. If there isnít a mirror for your country, just pick a near one.
(2) Unpack the tarball in your home directory
bzip2 -dc linux-2.6.0.tar.bz2 | tar xvf -
(Replace bzip2 with gzip if you downloaded the .gz)
(3) cd into the linux directory. Youíll now need to configure the kernel to select the features you want/need. There are several ways to do this:
|(a) make config
||(Command line questions)
|(b) make oldconfig
||(Useful only if you kept a .config from a previous kernel build)
|(c) make menuconfig
|(d) make gconfig
||(GTK+ based X-Windows configuration)
|(e) make xconfig
||(QT based X-Windows configuration)
(4) Now we can build the kernel (for older kernel like 2.4.x first build the dependencies with "make dep").
(5) Wait. When it's finished, it will have built both the kernel (bzImage) and the modules
(For older kernels like 2.4.x, you need to run "make bzImage ; make modules").
(6) Become root to be able to install modules and kernel.
Everything before this point can and should be done as a normal user, there is really no need to be root to compile a kernel. Itís actually a very bad idea to do everything as root because root is so powerful, one single mistake is enough to ruin your system completely.
(7) Install the modules.
make modules install
(8) Install the new kernel.
cp arch/i386/boot/bzImage /boot/vmlinuz-2.6.0
cp System.map /boot/System.map-2.6.0
A couple of comments...
Reasons for compiling a custom kernel
- You are a kernel developer.
- You need the kernel compiled in a special way that the official kernel is not compiled in (for example, with some experimental feature enabled).
- You are attempting to debug a problem for which you have filed or will file a bug report on the stock Ubuntu kernel.
- You have hardware for which the Ubuntu kernel doesnít include support
Reasons for NOT compiling a custom kernel
- You merely need to compile a special driver. For this, you only need to install the linux-headers packages.
- You have no idea what you are doing, and if you break something, youíll need help fixing it. Depending on what you do wrong, you might end up having to reinstall your system from scratch.
- You got to this page by mistake, but checked it out because it looked interesting. Believe me, this isnít interesting at all!