Linux Quick Help:
Compiling the Kernel

First of all, some really authoritative instructions reside at http://metalab.unc.edu/LDP/HOWTO/Kernel-HOWTO.html.

Your kernel source resides at /usr/local/linux, don't under-estimate the importance of the README file that's there, along with the Documetation subdirectory which explains a lot about modules (in modules.txt and networking/net-modules.txt).


The most important thing to know is that kernels must be built from /usr/src/linux, many of the header files depend on this.

As such, it's usually a good idea to make linux be a symbolic link pointing to the actual directory that contains the source code.

For example, I delete my linux symbolic link, grab a new kernel and untar it in the directory, rename the newly created directory and make a symbolic link.

I prefer using symbolic links in order to go back and rebuild prior distrubtions, if it ever becomes necessary.

The latest kernel can be obtained from any number of places including: http://www.kernel.org/ and ftp://ftp.tux.org/kernel/. (If you are looking for entire distributions try ftp://ftp.cdrom.com/pub/linux/ or ftp://ftp.tux.org/distributions/.)

I almost never apply patches, rather I find it much simpler to just get the entire kernel as a whole and build from there.

Building the kernel isn't complex, you just have to understand what each step does.

/usr/src/linux# make mrproper
This completely cleans out your binary directories. I only do this if I've really screwed something up. Note that this deletes your .config file, so you might want to rename it first! I hardly ever do this.

/usr/src/linux# make menuconfig
This is where you set all the configuration parameters for the kernel. The general gist is that you can build stuff into the kernel, make it a module for loading later, or exclude it all together (saving in size). Your settings typically go in a configuration file called .config. Other commands are make config and make xconfig, should you be using X Windows for the latter.

/usr/src/linux# make dep
This determines all the header file dependencies. Do this whenever you've made a change to the configuation.

/usr/src/linux# make clean
If you've already built the system and are making minor changes, not wanting to re-compile all the objects again, skip this step. If you want to be a purist and make sure you're starting absolutely fresh, do this step.

/usr/src/linux# make bzImage
This compiles the kernel, compresses it, and saves it in arch/i386/boot/bzImage. (Your platform may vary, so read the output string.) It is possible to do a make bzdisk and send the image to a previously inserted floppy for testing.

/usr/src/linux# make modules
If you selected modules <M> for any part of the kernel, you'll have to build them as well.

/usr/src/linux# make modules_install
This moves the module binaries to
/lib/modules/kernel_version.

/usr/src/linux# make install
Honestly, I'm not sure what this one is doing in full. But, I believe it moves the System.map file to the root directory so that the kernel can autoload modules properly. I think it also does some tricks with the rdev command to instruct the kernel which drive is the root drive when booting.

/usr/src/linux# cp arch/i386/boot/bzImage /kernel-x.y.z
When I check the kernel at the root with the one in the arch/i386/boot directory, it's usually always different in size and date. As such, I move the kernel manually, to the root directory, using a name that is very clear about what it is.

/usr/src/linux# cp /System.map /boot/System.map
I've found that for some reason the System.map file doesn't always get copied to this location. This seems to be where lilo gets its information when it installs.

/usr/src/linux# liloconfig
I either use this utility, or more likely, edit /etc/lilo.conf by hand. I make an entry for the newest kernel and I always try to leave one old kernel around, just for emergencies.

/usr/src/linux# lilo
This actually makes the kernel get installed, so it can be booted. The top two steps can often be done, under default configurations, with make bzlilo -- the catch is that you must name your kernel /vmlinuz for the scripts to work.

Editing the loadable modules list
You'll note that in /etc/rc.d/rc.modules there is a command to figure out module dependencies and bunch more to load various modules. If you made some things modules, you'll want to make sure those lines are uncommented.

Ctrl-Alt-Del
Reboot the system and invoke the new kernel. You may have to play with some of your configuarion settings to get it all to work right.

This page last updated 27-Jul-1999 09:35:40.
Linux Quick Help by MindPrint