Originally Published: Saturday, 27 May 2000 Author: Tom Dominico, Jr.
Published to: learn_articles_firststep/General Page: 1/1 - [Std View]

Taking the Plunge: Compiling the Kernel

You've been putting it off for awhile now. You've been hoping that you wouldn't have to do it, but you've come to the point where it's unavoidable. Perhaps you need additional hardware support, or need to enable a particular networking option. For whatever reason, it's time to perform a traditional Linux rite of passage: the compilation of the kernel.

You've been putting it off for awhile now. You've been hoping that you wouldn't have to do it, but you've come to the point where it's unavoidable. Perhaps you need additional hardware support, or need to enable a particular networking option. For whatever reason, it's time to perform a traditional Linux rite of passage: the compilation of the kernel.

First, let's talk a bit about the kernel itself. The kernel is the core of the operating system. It performs the essential operations of the system, controls your hardware, etc. Support for hardware can either be compiled directly into the kernel, or as a module. What is a module? Well, it's just a chunk of code that has compiled separately and resides in a directory (/lib/modules/) along with other modules, grouped by function. You can think of them in the same terms as the device drivers that you may be familiar with from Windows. These modules can then be "linked" into the kernel while it is running. What this basically means is that you can dynamically add and remove hardware support at will. It also means that you can upgrade (recompile) a module without having to recompile the whole kernel. Using modules is generally the preferred way of doing things in Linux.

It's always a good idea to recompile your kernel after you install Linux. Why? The "stock" kernel that is installed is somewhat bloated, because it tries to support a wide range of hardware. Also, it may not contain support for a certain feature that you require, such as IP Masquerading (using a Linux computer as a "gateway" in order to share an Internet connection). Or, perhaps you just wish to upgrade your kernel to the latest version. For newer users, I'd recommend that you stick to the so-called "production" kernels, which have even numbers after the first "point". For instance, 2.2.16 would be considered "production", or stable, while 2.3.99 is considered a "development" version and may be buggy.

I'm not going to walk you through the process of actually compiling the kernel, because there are a number of good resources on the web that do a good job of this. These include the official HOWTO at linuxdoc.org, and a simpler version at linuxnewbie.org.

The actual compilation process is not as painful as you might suspect. Basically, you are going to start out by downloading the kernel source. Depending on your distribution, you might be able to get this as a package. For example, on my Debian system, a simple "apt-get install kernel-source-2.2.16" did the trick. You'll then unpack the source and configure the kernel. This is the trickiest part, and you may be unsure as to what the various options mean. Many of them are self-explanatory, though you might need a little help on some of them. Try looking through your favorite Linux book, such as "Running Linux". Other HOWTOs may also come in handy (for example, the CD-Writing HOWTO tells you what you'll need to do to enable CD-writing support). You can also ask the friendly folks on IRC (try #linuxhelp on irc.linux.com, for starters).

Once you've configured the kernel, you will compile it (which may take a bit if you have a slow processor), test it out (I usually put it on a floppy first, boot from the floppy, and make sure everything works), install it, and compile your modules. It really only takes a few commands, and when you're done, you'll be surprised at how simple it was. You can then bask in the knowledge that you have taken a giant step forward in your Linux experience. So, go ahead and take the plunge - it's easier than you think!

Tom Dominico (tomd@linux.com) is a programmer, database administrator, and Linux convert. Cursed with insomnia, he spends his sleepless nights chatting on IRC, tweaking his Linux box, and reading everything he can get his hands on.