You've heard and read all about the new Linux 2.6 kernal. Now it's time to roll up your sleeves compile and install it safely, of course, and without overwriting your existing kernel.
We recently highlighted some of the new features of the Linux 2.6 kernel.
Now we'll look at the process of compiling and installing a new kernel safely, without overwriting your existing kernel.
You can install as many kernels as you like on a Linux system, and select the one you want to run at boot time. This makes it easy to test different kernels, and different kernel configurations, with particular sets of hardware or applications. The wise network admin always tests new kernels before running them on production machines.
Being able to compile, upgrade, modify and test new kernels is a useful skill to have. It's not that difficult &$151; Linux is designed to be modular, so you can plug in or remove bits as you need. A typical general-purpose Linux distribution lards the kernel with all kinds of things you'll never need, so you'll often see a performance gain after configuring and re-compiling your stock kernel.
Get A Pre-Fab Kernel To Play With
Look to your own distribution for already-built kernels. SuSE, Mandrake, and Red Hat customize their kernels extensively, while other distributions don't mess with them quite as much. If you're looking to reduce potential troubles, stick to your distribution packages. For example, Red Hat users can use up2date to automatically download and install new kernels. up2date will configure the bootloader to boot the new kernel by default. It will not replace your old kernel, and both will be in the boot menu. If, instead, you download and install a kernel RPM, be sure to install it with rpm -i, not rpm -U, because the -i flag will install the new kernel without touching the old one. The -U flag will overwrite your existing kernel. Debian users need look no further than apt-get install kernel-image-2.6.x.
Customizing A Kernel
You'll need the kernel source code to compile and customize a kernel. Again, you can look to your own distribution for kernel sources, so that you can customize the kernel, and still have the benefits of any modifications made by the vendor. Each distribution has its own method for customizing kernels, so be sure to check the documentation for your distribution.
Or, if you wish to try a plain-vanilla, unmodified kernel, go to the motherlode at The Linux Kernel Archives. The following steps are generic to most Linuxes.
Compiling a Linux kernel takes a bit of muscle, and a lot of disk space. Use a machine with at least a 500 MHz CPU, 128MB of RAM, and a good 500MB of free disk space. The build process needs a lot of room, so you'll get most of that disk space back. When it's completed, the 2.6 kernel takes up as much as 40MB, and kernel sources as much as 80MB. You can get away with using a slower CPU and less RAM, it will just take a lot longer. There is also the option of building kernels on fast machines to use on less-powerful machines.
Continued on Page 2: Software Requirements
Continued From Page 1
Kernel compilation is fussy about the tools used. Here's the major software requirements from the Documentation/Changes file, which you'll find in the kernel tarball.
|Gnu C || 2.95.3 ||# gcc --version|
|Gnu make || 3.78 || # make --version|
|binutils ||2.12 || # ld -v|
|util-linux ||2.10 || # fdformat --version|
|module-init-tools ||0.9.10 || # depmod -V|
|e2fsprogs ||1.29 || # tune2fs|
|jfsutils ||1.1.3 ||# fsck.jfs -V|
|reiserfsprogs || 3.6.3 || # reiserfsck -V 2>&1|grep reiserfsprogs|
|xfsprogs ||2.6.0 || # xfs_db -V|
|pcmcia-cs ||3.1.21 || # cardmgr -V|
|quota-tools || 3.09 || # quota -V|
|PPP ||2.4.0 ||# pppd --version|
|isdn4k-utils ||3.1pre1 || # isdnctrl 2>&1|grep version|
|nfs-utils ||1.0.5 ||# showmount --version|
|procps || 3.1.13 || # ps --version|
|oprofile || 0.5.3 || # oprofiled --version|
It's important to pay attention to these, especially gcc. If you compile your new kernel with any other version of gcc, you'll probably get errors. Most newer Linux distributions ship with gcc 3.x. You can have more than one version of gcc installed on your system. Install gcc 2.95.3, without overwriting your existing gcc installation, then invoke it with
# gcc -V 2.95.3
We'll go into compilation in-depth in Part 2.
Note that you can safely ignore anything that you don't need. For example, if you're not running quota, you won't need to update quota-tools, even if it's on your system. If you're not using the JFS filesystem you won't need jfsutils. And so forth. These items matter only if you're using them. The most important programs are gcc, Gnu make, binutils, util-linux, and module-init-tools, because these all relate directly to kernel-building.
Download and Unpack Your Shiny New Kernel Sources
Get the latest stable 2.6 kernel from The Linux Kernel Archives. Click on the "F" to get the complete kernel source. It's a 32MB download, and it unpacks to 172MB. Download and unpack it somewhere in your /home directory. The traditional way is create ~/src, and unpack it in there:
$ bzcat linux-2.6.3.tar.bz2 | tar -xvf -
Be sure to review the Documents directory. There are bales of good information in there. README gives installation instructions. Next, it's a good idea to make printouts of your hardware information, you will need it. Make a hard copy of /etc/fstab, and print out the output of lscpi:
$ lspci | lpr
$ dmesg | lpr
If the margins are too small, use lpr -o page-left=72 -o page-right=72 to set them at one inch.
Check your /usr/src directory for a .config file. There won't be one if you've never compiled a kernel on the system. If it does exist, make a backup copy, because it's going to be overwritten. Then run
$ make mrproper
This resets the source directory to a pristine state, giving our new kernel a clean start.
The first thing we want to do is find ../linux-2.6.3/Makefile and edit it. At the very beginning are these lines:
VERSION = 2
PATCHLEVEL = 6
SUBLEVEL = 3
Yes, the 2.6.3 kernel is named Feisty Dunnart (see Resources.) What we want to do here is give EXTRAVERSION a unique value, so that we can quickly identify this kernel. This can be anything, like -shiny-new-test-kernel, so after it's all built and installed, the kernel name will look like this:
$ uname -r
We're almost there. If you can't wait for Part 2 and want to leap ahead, keep in mind that almost all of the steps in building a kernel can, and should, be done as an ordinary, unprivileged user. Only two steps require root privileges: running make modules_install, and editing your boot loader.
2.6.2 aka "Feisty Dunnart" release announcement
See All Articles by CrossNodes contributor Carla Schroder