Compile the Linux Kernel

0 views
Skip to first unread message

achindra...@gmail.com

unread,
May 24, 2005, 8:53:26 AM5/24/05
to giGA...@googlegroups.com
How to Compile the Linux Kernel


RedHat is not Linux, it is a distribution based on the Linux kernel.
The Linux kernel is a complex program which provides the underlying
services to the rest of the Linux distribution. But it is easy to add
new features or improvments to it, unlike commercial operating systems
like Windows 95 or MacOS, the source code is freely available. It is
common practice with a Linux based operating system to recompile the
kernel from source and much effort has been put in to make this a
realitively user-friendly experience.


"But why recompile it? It works fine as it is." There are three reasons
for a recompile.

*- Firstly, we may have some hardware that is so new that there's no
kernel module for it in on your distribution CD.
*- Secondly, we may have come across some kind of bug which is fixed in
a revision of the operating system.
*- Lastly, we may have some new software which requires a newer version
of the operating system.


Getting the Kernel Sources

The most recent releases of the kernel sources are available on
ftp.kernel.org. This site is mirrored worldwide so there is probably a
fast copy of it somewhere near by. Locate the file for the latest
version of the operating system and download it to /usr/src. Then issue
the tar zxf command to unpack it.

Alternatively, if we already have the kernel sources and only need to
upgrade one version number (from 2.2.1 to 2.2.2 for instance) then need
to download the patch file to /usr/src and then use the command:

gzip -dc patch-2.2.2.gz |patch -p0

to upgrade our old kernel sources. Patch files are much smaller to
download than the whole thing.

If we do not need the very latest version, then installing a kernel
source package from the distribution CD may be an easier way to
proceed.


Configuring For a Build

Change directory to /usr/src/Linux and issue the command:

make menuconfig

This will build a few programs and then quickly pop up a window. The
window menu lets us alter many aspects of kernel configuration.

After we have made any necessary changes, save the configuration and
follow the instructions--

do a

make dep; make clean

The first of these commands builds the tree of interdependencies in the
kernel sources. These dependencies may have been affected by the
options we have choosen in the configure step. The make clean purges
any now-unwanted files left from previous builds of the kernel.

Now we are ready to go! Issue this command:

make zImage

and then, if we are on a machine slower than a Pentium 200, we got
ample time to go and make a cup of tea. This takes about 20 minutes on
a Pentium 90...the kernel has a lot of source code as one may have
noticed when downloading it. When this is complete do a:

make modules

This will not take as long.


Installing a New Kernel

The last step is installing the new kernel. On an Intel-based system
the kernel is installed to the right place in /boot with the command

cp /usr/Linux/src/arch/i386/boot/zImage /boot/newkernel

then

make modules_install

This will install the modules in /lib/modules. Next, edit
/etc/lilo.conf to add a section like this

image = /boot/newkernel

label = new

read-only

At the next reboot, select the kernel 'new' in lilo, and it will load
the new kernel. If it works fine, move it to the first position in the
lilo.conf so it will boot every time by default.


Summary

Compiling the kernel is a relatively simple operation- if done before!
At first it can seem daunting.

Reply all
Reply to author
Forward
0 new messages