Previous Section  < Day Day Up >  Next Section

Recipe 10.3. Slimming a Stock 2.4 Kernel

10.3.1 Problem

You would like to overhaul the kernel that came with your distribution and weed out all the unnecessary drivers, getting rid of support for hardware and functions you don't need.

10.3.2 Solution

Download new sources of the same kernel version and compile the new kernel, configuring it from scratch. To find your kernel version, use uname:

$ uname -r


The prequisites are:

  • First, make sure you have at least 500 MB of free disk space for the build process.

  • Next, make hard copies of the outputs of dmesg, lscpi, cat /proc/cpuinfo, and lsusb. (See Chapter 5 for more information on these.)

  • Back up all of your data, and have a bootable rescue disk at hand.

Unpack the new kernel sources into a folder in your home directory, such as ~/src:

$ tar xvjf linux-2.4.22.tar.bz2

Edit the new kernel makefile (~/src/linux-2.4.22/Makefile), giving a custom value to EXTRAVERSION, such as EXTRAVERSION = -slim-kernel

All of the following commands are run from ~/src/linux-2.4.22:

$ make mrproper

$ make menuconfig

$ make dep

$ make bzImage

$ make modules

$ su

# make modules_install

# cp ~/src/linux-2.4.22/arch/i386/boot/bzImage  /boot/vmlinuz-2.4.22-new-kernel

# cp ~/src/linux-2.4.22/ /boot/

When you configure the kernel, keep in mind that you are starting from scratch, so you must explicitly enable every feature that you want. And you must make sure that features you do not want are not enabled. These are some core features that you definitely want:

  • Loadable module support, built into the kernel.

  • Under the "General Setup" menu, be sure that support is built in for a.out binaries, ELF binaries, and MISC binaries.

  • Be sure to build support for all of your boot devices—IDE drives, CD-ROM, floppy disk, SCSI disk, or USB—into the kernel. If you leave them out, or build them as modules, your system will require a ramdisk (initrd image) to boot.

When you're finished, add the new kernel to the bootoader, reboot, and enjoy. Remember to copy your new .config file to a directory outside of the build tree to preserve it.

10.3.3 Discussion

This procedure configures the new kernel from scratch. make oldconfig doesn't work, because it does not let you change the old configuration; it only lets you add new things.

A typical base kernel runs around 1-3 MB (compressed), and the corresponding /lib/modules/$version runs around 10-30 MB. Some folks like to strip their kernels to the absolute bare essentials. On a server, especially one that is exposed to the Internet, it's a good security practice to keep it as lean as possible. But having a bit of fat on a desktop system or workstation isn't all that significant, and it may be convenient for future changes.

The name vmlinuz, according to lore, came about because the kernel on old Unix systems was vmunix. The vm stands for "virtual memory," to distinguish it from older kernels that did not have this feature. In your build tree, you'll see a vmlinux file. vmlinuz is the compressed version of this file. There's no need to be dull and stick with naming your kernels vmlinuz-$version. You can name them anything you like—kernel-mustard, kernel-panic, kernel-of-truth, fred-and-ginger . . . anything at all.

10.3.4 See Also

  • This chapter's "Introduction," for where to get kernel sources and where to look for documentation

  • The online help in the kernel configurator—almost every configuration item has an entry

  • Recipe Recipe 10.2, for explanations of build commands, managing .config files, and installing the new kernel

    Previous Section  < Day Day Up >  Next Section