Home Menu

Kernel Configuration


Contents


Reconfiguration


Recompilation


Installation

Example

You decide that you need to upgrade your kernel to the latest version. So you go to the kernel mirror list, and pick a good place to download the kernel. You go to the kernel directory and see a list of kernel versions. 2.4 is the largest number so you check there. The README file makes it clear that this version is not ready for prime time, so you try 2.3. The latest version is 2.3.99-pre9:


Modules

Example

You decide to go for a nice SCSI tape drive on your system. Unfortunately, the manufacturer doesn't provide Linux drivers. So you look on the web and find a site like HREF="http://lhd.zdnet.com/lhd_press_drivers.html">zdnet that has quite a few drives and lo, there it is. They have a loadable kernel module for your controller. Download the file (probably a tar file), untar it and put the output (.c and .h files) in /usr/src/linux-X.X/drivers/scsi (where your current linux source tree resides). A module might also come as a patch as discussed later.

Since its a module, check to make sure that you have enabled loadable modules in your kernel configuration. If not, rebuild it. If you install the modules, it should be in /lib/modules/your-version-number in the the scsi subdirectory.

Now, you can enter:

in /etc/modules.conf and reboot. Or, you can use insmod to install the module and see if it works, or if there are some problems. This is usually a good first step.

initrd

The initrd files that you commonly see in the /boot directory and referenced in the grub.conf file are RAM disk files. That is, they are images that can be loaded directly into memory to complement the kernel that is to be booted. They contain things (usually modules) that need to be loaded before the kernel can run. For example, if you have a SCSI disk and your kernel doesn't have the SCSI functionality compiled in, you can force the necessary driver modules to be loaded into memory and be available to load the kernel from the disk.

mkinird is the command used to create initrd files. It will automatically load anything mentioned in /etc/modules.conf as well as the default SCSI modules. There are two options for adding another module; with for adding modules to be loaded after the SCSI modules, and preload for modules to be loaded before the SCSI modules. For example,

which creates an initrd image named initrd-test.img, based on the 2.4.20 kernel (which has to be present) and in addition to the default contents, also preloads the hpt366 driver and postloads mymodule.

Interestingly, an initrd image is simply a compressed file image, so you can add things to the file system directly. For example,

You will find a number of things, including the modules you want loaded under the lib directory. Once mounted like this, you can add modules and other features if you so desire. Then,


Patching the Kernel

A kernel patch is a set of files that modify a kernel. You might do this to add a module, to make substantive changes to a kernel such as a version upgrade, or to plug a security exploit. In any case, the procedure is to apply the patch to the source, and then rebuild and install the patched kernel. Before trying this, you should always make sure you can build your current kernel and install it successfully.

Kernel upgrades are often done with patches. A patch is a set of diff files. diff is a program that will compare two files and output the differences on a line-by-line basis. If you have an old file and a set of differences between the old file , you can upgrade the old file to be a duplicate of the new file. Kernel patches have the diff files between different versions or mods and when applied, can upgrade the kernel.

Finding a Patch

If you browse to kernel.org site you can find patches to bring a linux kernel up to a new level. This includes both stable kernels which are unlikely to have major problems and unstable kernels that haven't been completely tested and may have issues. Of course, there are lots of places to get patches, including the purveyor of your version of Linux, a site that publishes a modified version of Linux, or many other places. However, do be careful; Jimmy Joe's General Lee Linux may not be particularly high quality.

Download a Patch

Patches normally are normally compressed by either gzip or bzip2 so their extensions are gz or bz2. For example, the patch to bring a Linux 2.4 kernel to version 2.4.26-rc2 is named patch-2.4.26-rc2.bz2. When you download a kernel patch, you will typically place the file in /usr/src, but that isn't necessary. In the following, assume that you have downloaded the file shown above and placed in /usr/src.

Extract the Patch

In /usr/src, bzip2 patch-2.4.26-rc2.bz2 will unpack the patch and create a directory patch-2.4.26-rc2.

Install the Patch

The patch program performs the patch process by applying the diff files in the patch data to the original data. The syntax is:

but the usual form is:

For example, in the situation above, we have /usr/src/linux-2.4 contains our current version, and we want to patch it with the data we put in directory patch-2.4.26-rc2. So we would do the following:

The -p1 option tells patch how to process filenames. The diff files directory structure will mimic the directory structure of /usr/src/linux-2.4 and patch will find files with the matching pathname to make changes. The filenames will be ../patch-2.4.26-rc2/..., but we need the files to match at the level of the patch-2.4.26-rc2. That is, if /usr/src/linux-2.4 has a file named config, then you would expect to find the same name in the patch directory at the same level. -p1 tells patch to ignore the first element in the path, so it becomes patch-2.4.26-rc2. If this directory contains a config, then we have what we need. You can think about it this way, each n in -pn removes one slash from a pathname and everything in front of it.

After executing the patch command, the kernel is ready to be rebuilt. Remember to perform an mrproper.


Bootable Floppy


Assignment

  1. Make some inconsequential change in your kernel config, recomplile and install. Wheee!! Some good choice are things like SCSI support, removing unused network cards or sound card stuff.
  2. Make a bootable floppy and try it out.
Home Menu