WPI Worcester Polytechnic Institute

Computer Science Department
------------------------------------------

Building A Linux Kernel




1. Configuring the Kernel

To build a new kenel or modify an existing kernel such as modifying process scheduler or writing a new file system, you need to get a Linux kernel source. In current fossil client installation, the kernel source is located under /usr/src/linux-2.2.14.SuSE. Please, do NOT work directly on this directory. Rather, login as a normal user (not root) and copy the source directory to your home or /tmp directory as follow (the example assumes that your login name is USER):

Note that you need to add yourself to group "root" (in /etc/group) to have permission to copy the Linux sources. The permission on "/usr/src/" is changed so that normal users (such as "guest") cannot read the Linux source that you might have modified directly on (instead of coping the source to your directory and modify it).

The next step after coping the source to your own user directory is to make soft link from "/usr/src/linux" to the linux source you have copied, and make sure that the linux source you have copied is not readable by random users:

After copying the linux source to your directory, make changes to the source as required for class projects. For example, for cs3013 proj0 you will not need to make any kernel modification. For cs4513 proj0, you will need to slightly modify kernel source to install a new file system given. In general, before you configure and compile and after you copy and modify a kernel, it is good habit to run "make clean" to make sure you have no stale .o files lying around:

You can also run "make mrproper" to make sure you have no stale .o files and dependencies lying around. However, be carefull. This will also delete ".config" file that has the current kernel configuration options. If you want to keep the current configuration, one hack is to rename ".config" before runing "make mrproper" and rename the configuration file back to ".config". If you have copied the current fossil client linux source (/usr/src/linux-2.2.14.SuSE), it is not necessary to run "make mrproper".

Next thing to do is configuring the kernel. Run "make config" to configure the basic kernel. Alternate configuration commands are:

Do not skip this step even if you are only upgrading one minor version. If you do not want to change the current fossil client default kernel configuration, just "save" and "exit". Finally, do a "make dep" to set up all the dependencies correctly. Now you are ready to compile the kernel you just configured.



2. Compiling the Kernel

After configuring the kernel, do a "make zImage" to create a compressed kernel image. If you want to make a boot disk (without root filesystem or LILO), insert a floppy in your A: drive, and do a "make zdisk". If your kernel is too large for "make zImage", use "make bzImage" instead. For the default fossil client kernel settings, you are required to use "bzImage", since it will complain about the size of kernel you are trying to build, if you use "zImage" option.

If you configured any of the parts of the kernel as `modules', you will have to do "make modules" followed by "make modules_install". Note that "make modules_install" requires "root" permission, and doing it will delete the currently installed kernel modules located under /lib/modules/2.2.14. It is strongly recommended to backup /lib/modules/2.2.14 before installing your own modules. For example:

Read Documentation/modules.txt for more information. For example, an explanation of how to use the modules is included there. At this point, you should have your kernel image under "~USER/linux-2.2.14/arch/i386/boot/" directory (zImage or bzImage)



3. Installing the Kernel

After compilation, you need to move the kernel image you have compiled to "/boot/" directory. Please, do not delete the currently kernel image (/boot/vmlinuz), since if anything goes wrong, you cannot boot again. In the rest of this example, it is assume that your new kernel image is "bzImage".

Now you need to modify /etc/lilo.conf to give LILO (Linux Loader) the location of your new kernel image. The current /etc/lilo.conf will look like:

Append the following to the end of /etc/lilo.conf:

Note that you will also use "sudo" to modify /etc/lilo.conf. After modifying /etc/lilo.conf, run lilo:

This will reinstall LILO, so that when you reboot you can choose your kernel image to boot the system. Now, it's time to reboot your system. Run one of the following command with your fingers crossed ^^:

Make sure nobody logged into your machine before rebooting your system ("who" will show you people currently logged in). When rebooting, type in "test" at "LILO boot:" prompt to boot your kernel (hit TAB to list available boot options).

For more information and issues on building linux kernel, refer to /usr/src/linux-2.2.14/README and /usr/doc/howto/en/html/Kernel-HOWTO.html.

4. Clean Linux Source and Config File

A clean Linux 2.2.14 kernel source and a copy of the default fossil client kernel configuration file is also available under "/home/public/src/" directory at the fossil server. Here is how to untar (with gunzip) the kernel source.

If you feel you did someting wrong with your own kernel configuration and would like to start from the fossil client default one again, you can use the configuration file named "fossil-kernel.config" on the fossil server under "/home/public/src/". However, it needs to be renamed to ".config" after coping it to your linux directory.



[Return to the WPI Homepage] [Return to the CS Homepage]