Linux Kernel Cornucopia

Sometimes compiling that first kernel can be a bit intimidating. But, it's probably what you have to do if you want to play doom, abuse, or Quake under Linux.

When you first install Linux, more than likely you're using a generic kernel with support for every mainstream type device already built into it. To make room for it all on a floppy disk, some things were left out, like sound and some types of network support. To use your system to the max, you must compile your own custom kernel.

You can either rebuild a custom kernel of the version that came with your distribution, or you can download the latest kernel source. You'll need to decompress it into /usr/src/linux using either tar xvfz if the package is a tar.gz file, or rpm -ivh for an rpm file. Be sure to do this as root.

There are several operations if you're building a modular kernel:

  1. make mproper
  2. make config (there are several options for doing this)
  3. make dep
  4. make clean
  5. make zImage
  6. make modules
  7. make modules_install install the new kernel on a floppy or in /boot

If you're building a monolithic kernel, say, on a pre-2.0.x kernel that doesn't do modules, you're ready to install the kernel right after step 5.

Running "make mproper" cleans out the source tree of any leftover junk from previous kernel builds. Since the kernel source is normally quite large--mine is about 40MB--it's important that it's very organized. If you're using a pre-existing /usr/src/linux/.config file, don't bother with "make mproper".

Whenever you compile source code under Unix, you normally must have a Makefile. The kernel Makefile tells the compiler and linker what to do while walking through the 40MB source tree.

Three options exist for this:

  1. make config
  2. make menuconfig
  3. make xconfig

"make config" was the tried and true way of designing a kernel. No help buttons, no cheating: you just have to know what you're doing. It asks the questions, and you just have to know what it's talking about. (This still beats editing the entire Makefile by hand.)

"make menuconfig" was a giant step for ease of use. The same options are presented to you, but now all the questions are presented for you to choose from a neat menu system. Once you've selected your preferences you can save them and go on with the rest of your kernel build.

"make xconfig" is truly the way to design your kernel for today's computer. You run it in X-Windows, and there's built-in help and buttons for each selection. Since many of the questions get quite esoteric ("Do you wish to include RZ-1000 error handling?"), a help button can come in extremely handy indeed!

After you've designed your kernel, you usually need to run "make dep" and "make clean" to prepare the source tree for the build. These two arrange module dependencies and do a final housecleaning in the source tree before the kernel build.

"make zImage" actually builds the kernel. ("make zlilo" will actually install the kernel, but don't do this unless you know the kernel works already!) On a newer Pentium style computer, compile time is about 15 or 20 minutes, depending on what else you're doing. If you run "make zImage" outside of X-Windows, it will be considerably faster. But, with today's fast computers, you might as well build it while you're chatting on IRC. You can discuss your new design with the folks in #linux!

Build any modules you require with "make modules". Then install those modules with "make modules_install". Omit these steps if you want a monolithic kernel.

Now comes the tricky part. What if you've made a mistake? What if this new kernel breaks your computer? What if you can't even boot up again because your new kernel is so incredibly broken?

You have two choices: put the image on a boot floppy to try it out first, or copy it to /boot and label it as experimental. If you choose the latter, you will need to modify your /etc/lilo.conf file so you can select either the old or new kernel image. I would recommend the boot floppy first, and if that works, copy the zImage (found in /usr/src/linux/arch/i386/boot) to /boot/vmlinuz.experimental. Just add an "image" stanza to your /etc/lilo.conf file pointing to the bootable partition and the new kernel image. Then at system startup, when you see the "LILO boot:" prompt, hit the TAB key, and you'll get a list of boot options from which you can choose!

Once you have compiled that new working custom kernel, you'll find you've opened up a new world of possibilities for your box. Multimedia and games are only the beginning. That's the power of rolling your own operating system kernel!


©David S. Jackson, 1997.