kernel build exercise
What ingredients, where from?
As with open source software generally, there are 2 broad approaches to upgrading to a new kernel on a linux system: 1) download and install its precompiled binary or 2) download and compile its source code. And, again generally, method 1 is easier but method 2 affords fine-grained control. Having that control is the reason for building a kernel from source.
Kernel source's place of origin is www.kernel.org. New, plain vanilla kernels are placed there there periodically by Linus Torvalds and the distributed team of kernel maintainers that has grown around him. Then distributions like Fedora modify/extend/improve/patch these kernels, thus maintaining their own versions of kernel source. This is reflected in the separate version numbers for kernel itself versus the distributions that incorporate it. Fedora Core version 5 for example is based on kernel version 2.6.15.
Suppose you have a Fedora 5 machine. You installed it from Fedora 5 installation CDs. You want to upgrade to kernel 2.6.18. If you are not interested in compiling from source, the shortcut is to get the precompiled binary, in rpm form, and install that. You would find it at, for example,
After downloading it, just install it as usual with "rpm -Uvh" and next time you boot you'll have a new option on your GRUB bootloader menu. The adjustments are all made for you. Easier and lazier still,
yum install kernel
will do the same, for whatever kernel version is the latest in Fedora's yum repositories. However, forget that because you are interested in compiling from source. You could find the source at kernel.org as
or get Fedora's version from any Fedora mirror
The many mirrors all have the same file-tree structure. Note precompiled binary is in core/updates/5/i386/ while source is in core/updates/5/SRPMS/.
Doing the job
We will install from source, getting it from Fedora. Obtain and install:
rpm -Uvh kernel-2.6.18-1.2239.fc5.src.rpm.
This deposits a lot of files in /usr/src/redhat. The one with the source code is linux-2.6.14.tar.bz2. Change the working directory to /usr/src then untar the archive:
tar -xjvf redhat/SOURCES/linux-2.6.18.tar.bz2
The result is to create a subtree /usr/src/linux-2.6.18/ full of many files. These are ingredients for building the 2.6.18 kernel. Change into the new directory:
and browse through the README file there (originally written, till recently maintained, by Linus Torvalds). Copy a dot-config file to this directory:
cp /usr/src/redhat/SOURCES/kernel-2.6.18-i686.config ./.config
The dot-config file sets many choices for which pieces of the kernel to include and omit, and whether to contain them in the main kernel binary file or in an outboard dynamically callable module file.
Upon this baseline, express and record your particular desires for building this kernel and what features it should include. If you do not have a GUI:
If you have a GUI ( startx & generally launches it) then better:
Within the xconfig program you can select or deselect many (hundreds of) components. Let's choose a few features different from default. Then, after creating and booting our new kernel, exercising those features will convince us that it worked.
Find and select these features:
General setup / Kernel .config support, and Enable access to .config
File systems/ DOS/FAT/NT filesystems / NTFS file system support
processor type / Preemption model / preemptible kernel
Find and disable:
Code maturity level options / Prompt for development and/or incomplete code/drivers
From within the xconfig application save then exit. Your selections are recorded in a file named .config. Examine its contents. The kernel build process uses that file and implements its selections. Under the new kernel, you will have support for the ntfs file system. You'll prove that by mounting and accessing the existing ntfs partition on your hard disk. Under the current version of your operating system, ntfs is not included so you can't mount that partition. Prove now that you can't by trying:
mount -t ntfs /dev/hda1 /mnt
You should get an error message to the effect that the system doesn't know about ntfs. If you can overcome this after the recompile/reboot, it'll constitute proof that you've replaced one kernel with another. (This assumes that Windows lives in /dev/hda1.)
The instructions for the kernel build process are in the delivered file Makefile. There, make one editorial change. Very near the top, find the line:
and give it value -1 (hyphen one):
The Makefile gets involved automatically when you run the make command, as you did in order to get the xconfig application and will do again now for several further purposes. Execute these commands in succession:
make bzImage [ took 45 min on a slow machine, 10 on a recent model ]
make modules [ took 2.5 hr, or a half hour ]
Then make bzImage creates the central piece of the operating system in a single large file, and make modules creates the outboard, dynamically-loadable-module pieces of the operating system in numerous smaller ones. Then make modules_install copies the modules to the place where they need to be at runtime. make install runs a script that automates a number of adjustments. Among its effects, it places new files in /etc/boot:
vmlinuz-2.6.18-1 --this is the new kernel, a copy of the install tree's arch/i386/boot/bzImage
plus symbolic links to two of them:
vmlinuz -> vmlinuz-2.6.18-1
System.map -> System.map-2.6.18-1
and it inserts the requisite stanza in the bootloader configuration file /etc/grub/grub.conf to reference the new kernel on the boot menu:
title Fedora Core (2.6.18-1)
kernel /boot/vmlinuz-2.6.18-1 ro root=LABEL=/ rhgb quiet
Now reboot the machine:
An additional option should appear on the bootloader menu under your chosen name "Fedora Core (2.6.18-1)" offering the new kernel. Select it and let the system boot up fully. It will probably declare its name on screen along the way, otherwise try:
to see it assert the claim that it's new. To really verify it though, use one of the previously absent features you instructed to be built in. Try to access a local NTFS partition. Assuming you have one holding a copy of Windows in /dev/hda1:
mount -t ntfs /dev/hda1 /mnt
The above ls command should reveal signature Widows root directory files (e.g., boot.ini, pagefile.sys, ntldr). Congratulations. Enjoy your new kernel.
Here is the README that comes with the
Here is a howto guide about building the kernel.