Translations of this page:

Kernel compile for RedHat based linux [beta]

There are many howtos for compiling kernels, but most of them don't work. Why? It's not that they are wrong. The problem is that every linux distribution has its own idiosyncrasies. There is no howto that works for all cases. This document will help you to compile linux kernel for Redhat based distributions:

  • Redhat
  • Fedora
  • Redhat Enterprise
  • CentOS

First of all you must have the kernel source. Even all Redhat distributions are similar, kernel source is not installed in the same way for all of them. With Redhat 6,7,8 and 9 you can select kernel source from OS installer or later you can install kernel-source-xxx.rpm Some (or all?) Fedora distributions don't have this package. One thing is sure for all Redhat distributions - complete source of open source packages is provided in .src.rpm format, including the linux kernel. Sources are usually not included with distributions, but you can download them from official websites as well as mirror sites.

Here are some locations of OS sources:

Preparing the sources

Download and install source rpm. Please correct file name and url depending on what OS you are using. Good idea is to check if you already have the source:

ls /usr/src/linux*

You should see directories like “linux-2.6.18” or “linux” if you have the kernel source installed.

cd ~
wget http://download.fedora.redhat.com/pub/fedora/linux/core/6/source/SRPMS/kernel-2.6.18-1.2798.fc6.src.rpm
rpm -i kernel-2.6.18-1.2798.fc6.src.rpm
cd /usr/src/redhat/SPECS
rpmbuild -bp kernel-2.6.spec --target=i686
cd /usr/src/kernel/BUILD/kernel-2.6.18/
mv linux-2.6.18.i686 /usr/src/linux-2.6.18
cd /usr/src
ln -s linux-2.6.18 linux
  • if you are using pentium 1 processor use –target=i586 for rpmbuild option
  • if you are using 2.4 kernel .spec file will be named kernel-2.4.spec
  • putting link to linux-2.6.18 directory is good idea because there are some programs which refer to linux sources with /usr/src/linux directory. If you have older version of kernel source you should remove the “linux” link to old kernel directory first

Configuring the kernel

If kernel is the same version as currently running you can copy config file from your /boot directory:

cd /usr/src/linux
cp /boot/config-2.6.18.xxx ./.config

Or you can use some of default configs:

cd /usr/src/linux
ls ./configs
cp ./configs/kernel-2.6.18-xxxx ./.config

The best way is to use ncurses configure program to select compile options for kernel:

cd /usr/src/linux
make menuconfig

If this doesn't work try to install ncurses-devel-xxx.rpm package.

Use “make help” command to see other configure targets.

I won't describe various configure options here. There will be separate howto for configuring the linux kernel.

Compile and Install

Compilation is almost the same on all linux distributions:

make dep #for 2.4 (or lower) kernel version only
make bzImage
make modules
make modules_install
make install

“make install” will configure automatically your current boot installer to load new kernel, but you can check it jsut in case. Do not delete old kernel from boot loader. If your new kernel fails to boot use old kernel.

If you re-compile the new kernel using different options be sure that you booted with your old kernel or else “make install” will fail.

Removing the old kernel

It's not a good idea to remove your original kernel, but if you compiled and installed second kernel and you need to update it with latest version you may want to remove it. To remove a kernel you must delete these files:

cd /boot
rm initrd-<version>.img
rm System.map-<version>
rm vmlinuz-<version>
cd /lib/modules
rm -fr <version>
lcb/kernel/redhat-kernel-compile.txt · Last modified: 09.11.2008 01:54 by npelov
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki