/* Void Main's Red Hat/Fedora Tips */

{ Red Hat/Fedora Tips(); } else { main(); }
Building the kernel in FC3
#include <stddisclaimer.h>

Prerequisites: With the 2.6 kernel it is rare that you have to actually install the kernel source and build it. But if you do I will attempt to explain how to do it. This tip assumes you have all of the kernel build tools, libraries and development packages installed. Also make sure the rpm-build package is installed.

Let us begin:

The basic instructions are actually in the FC3 release notes.

Normally I would do all of my building including RPM building under my normal user account but when building the kernel special privileges are needed to do things like make the initrd.

Now you need to become root and begin the build, starting with the installation of the kernel source. I prefer to use apt to get all my packages and source rather than up2date or yum but the end result is the same. For instance instead of the up2date command I do this:

Commands:
$ su -
(enter root's password)
# apt-get source kernel


This command places the original kernel source package for the version we are currently running in /usr/src/redhat/SOURCES along with all the patches applied by Red Hat/Fedora. The spec file gets placed in /usr/src/redhat/SPECS. You could optionally download the kernel *src.rpm and install it via "rpm -i" which does the same thing. Now you want to do a prep on the kernel, including your architecture type in the target param:

Commands:
# cd /usr/src/redhat/SPECS
# rpmbuild -bp --target=i686 kernel-2.6.spec


You can find your arch by typing "arch" oddly enough. In fact you could have just used it in the above command by using back quotes (or left quotes) like so:

Commands:
# rpmbuild -bp --target=`arch` kernel-2.6.spec


The left quotes will execute whatever is between them as a command and replace the quotes and the command between them with the output of said command, in this case "i686". Now change into the kernel build root:

Commands:
# cd /usr/src/redhat/BUILD/kernel-2.6.10/linux-2.6.10


At this point you might want to browse over the README in the directory you are currently in, it's got some good info in it. You also want to edit the "Makefile" and change the "EXTRAVERSION = -prep" variable to something other than "-prep". This effects the name of the kernel when you install it. I might name it something like "-1.760_FC3_Void1" for instance. For the current official kernel this would have been set to "-1.760_FC3".

If you want to make an exact kernel just like you have installed you would first copy your current config to the kernel root:

Commands:
# cp /boot/config-`uname -r` .config


Notice those left quotes again. On my system this is equivelant of this:

# cp /boot/config-2.6.10-1.760_FC3 .config

Now do this:

Commands:
# make oldconfig


This is a good "base" to start with. The kernel *should* build without a problem with this configuration. There are other base configs in the "configs" directory under the kernel base directory where you are currently at. You will find a config for the i586 and i686 and the SMP versions of those.

Now if you want to make configuration changes to this base configuration there are some included GUIs to do this. If you want to run the GTK based GUI you can:

Commands:
# make gconfig

make gconfig


The one I prefer is brought up with this command:

Commands:
# make xconfig

make xconfig


There is even a curses based one:

Commands:
# make menuconfig

make menuconfig


Make your customizations in one of the above config tools and then save the config. Now you have two ways of building the kernel. One way is to build it as an RPM and the other is to just build and install it without building an RPM. Here is the way to build and install it without building an RPM:

Commands:
# make
# make modules_install
# make install


The "make" builds the actual kernel and modules. The "make modules_install" installs the modules under /lib/modules/<kernelversion>. The "make install" installs the kernel in /boot and adds a GRUB entry for you. You can see all of the various make options by doing a "make help | more" but you likely won't need anything more than what I have listed.

Instead of doing that last set of commands you could have built an RPM. I normally try to install *everything* via RPM. First make a backup of the /usr/src/redhat/SPECS/kernel-2.6.spec and then make a couple of changes to it. For instance, if you do not want to build the SMP kernel (for multi-processor machines) you will want to turn this off in the spec file. It builds both UP and SMP kernels if you don't. Here's what the top section would look like if you have a single processor machine:

Code:
%define buildup 1
%define buildsmp 0
%define buildsource 0
%define builddoc 0

%define FC2 0
%define FC3 1


I would also customize the kernel version at this point. Find the "%define release" line for FC3 (on my spec it's line 31) and customize it. The following line will produce a kernel version of "2.6.10-1.760_FC3_Void1":

Code:
%define release %(R="$Revision: 1.760 $"; RR="${R##: }"; echo ${RR%%?})_FC3_Void1


Now you'll want to copy your .config file produced by the configuration step earlier to the SOURCES directory so your customizations will be included in the kernel. You might want to make a backup of the original first and then overwrite it with your customized version:

Commands:
# cd /usr/src/redhat/SOURCES
# cp kernel-2.6.10-`arch`.config kernel-2.6.10-`arch`.config.bak
# cp /usr/src/redhat/BUILD/kernel-2.6.10/linux-2.6.10/.config kernel-2.6.10-`arch`.config


Now build the RPM:

Commands:
# cd /usr/src/redhat/SPECS
# rpmbuild -vv -ba --target=`arch` kernel-2.6.spec --clean


When it's finished the binary RPM should end up in /usr/src/redhat/RPMS/i386 and the SRPM should end up in /usr/src/redhat/SRPMS. Install it like you would any kernel RPM:

Commands:
# cd /usr/src/redhat/RPMS/i386
# rpm -ivh kernel-2.6.10-1.760_FC3_Void1.rpm


Do not use "-Uvh" because you don't want it to replace existing kernels, you want it installed along side other kernels (just in case it doesn't work).

As you can see building the RPM takes a little more work but if you want to install your kernel on more than one machine this is the way to go. Again, there is usually very little need to recompile a kernel completely from source these days. 2.6 makes our life much easier. For instance, you don't even have to have the kernel source installed to build kernel modules like days of old.


NOTE: If you use VMware or the nVidia kernel drivers, or any other 3rd party kernel modules they will have to be rebuilt and installed after booting the new kernel.

P.S. If you find errors in this or things that need to be added let me know and I'll make changes.



Have fun!

kernel-2.6.spec after customizations in this tip (and a couple more)
kernel-2.6.spec.html colorized (ala VIM) version of above file.
Forum topic that spawned this tip
Forum topic on adding a patch to the kernel RPM.
Forums

Valid HTML 4.01!