Ottawa PC Users' Group (OPCUG)
 
   Home
   LinuxSIG

Tux Linux

 

Compiling a Linux Kernel (the operating system)

by Don Chiasson

Introduction

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 (ncurses based)
(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").

make

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

(from: https://help.ubuntu.com/community/Kernel/Compile)

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!

 

 

 

Donald James Chiasson 1941-2010

Don Chiasson

OPCUG members will remember Don as an enthusiastic supporter of free software - especially in the "free speech" sense - although Don was also fond of telling us that it was also free as in "free beer"! Don was instrumental in forming the Linux, Free and Open-Source Software Special Interest Group, and several of his presentations to the SIG are posted on the web site.

Ottawa PC News; Volume 27, Number 9; pp. 5; November, 2010