PATCHING THE KERNEL

RH9.0

What is a kernel patch used for?

A patch allows you to modify your kernel source code so that:

  1. Additional hardware functionality can be provided (e.g. a new USB gizmo comes on the market and it is not supported by your current kernel). Instead of downloading a whole new kernel, you may be able to use an incremental patch, upgrading from 2.4.x to 2.4.y, to get your device working.
  2. You can install an application that is not supported by the standard kernel. Win4Lin is an example of a Windows to Linux "bridge" application that requires a patched kernel.

In the following example, I will show how the Win4Lin patches are applied. This should help you understand the general process, applicable to any kernel patch.

Patching the kernel to enable "Win4Lin"

  1. First of all, don't even THINK of starting this until you have successfully configured and installed a new kernel version, as described on the previous page.
  2. Identify the patch(es) you need and download them or copy from CD ROM. For Win4Lin, you can obtain the relevant patch files from the download area of Netraverse here. For Win4Linversion 3.0.7 or above and kernel-2.4.20-8 (check version very carefully), you will need Kernel-Win4Lin3-RedHat9.0_2.4.20.8-02.src.rpm. Download to a temp directory and extract the patch files by entering:
    rpm2cpio Kernel-Win4Lin3*src.rpm | cpio -idmuv '*.patch'
    This will give you the two patch files: Kernel-Win4Lin3-RedHat9.0_2.4.20.8.patch and mki-adapter.patch .
  3. As root, cd /usr/src to the linux source directory. Make a new directory for the patched kernel tree, e.g. mkdir linux-2.4.20-8W4L
  4. Copy your current linux source tree contents to the new directory: cp -ravd /usr/src/linux-2.4.20-8/* /usr/src/linux-2.4.20-8W4L/
  5. Also copy the patch files you just extracted into the new source directory /usr/src/linux-2.4.20-8W4L/
  6. cd /usr/src/linux-2.4.20-8W4L
  7. Apply the first patch: patch -p1 <Kernel-Win4Lin3-RedHat9.0_2.4.20.8.patch> patch.log 2>&1 (use the < and > symbols exactly as shown)
  8. Check the patch log for errors (hopefully none!): less patch.log
  9. VERY IMPORTANT - edit the Makefile line where it specifies "EXTRAVERSION = -8" or "-8custom" to read "EXTRAVERSION = -8W4L. If you miss this step, disaster will surely follow...
  10. Apply the second patch: patch -p1 <mki-adapter.patch> mkipatch.log 2>&1
  11. Check the patch log for errors (hopefully none!): less mkipatch.log
  12. If everything is OK up to now, you can start to configure the patched kernel.

Configuring your patched kernel

The instructions are broadly the same as given before. In this case, we will show the specific example of Win4Lin. For it to work, you must be in the directory /usr/src/linux-2.4.20-8W4L

make distclean

cp configs/kernel-2.4.20-i686.config .config

make xconfig

Then choose the desired kernel options. Apart from the ones you may have chosen before, be sure to set:

SECTION KERNEL OPTION
Loadable module support Enable loadable module support (Y)
General setup Networking support (Y)
PCMCIA/CardBus Support (Y), CardBus Support (Y), Other Bridge Support (All N)
System V IPC (Y)
Kernel support for ELF binaries (Y)
Networking options TCP/IP networking (Y)
File systems ISO 9660 CD-ROM filesystem support (Y)
Windows application support Include NeTraverse Win4Lin Support (Y)

When you have finished, select the option "Save and exit".

Xconfig will tell you to check the top level Makefile (/usr/src/linux-2.4.20-8W4L/Makefile), so please do it now, and make sure - again - that the EXTRAVERSION is set to what you think it should be...! (Read step 9, above). If you keep it at EXTRAVERSION = -8, the following steps will OVERWRITE your default linux kernel, with possibly catastrophic results.

Everything OK so far? Now comes the really tedious bit -

  1. make dep #sets up all the dependencies
  2. make clean #prepares source tree for the build, cleaning out superfluous drivers
  3. make bzImage #makes a compressed boot image
  4. make modules #builds all the modules you requested
  5. make modules_install #installs the modules into /lib/modules/(kernelversion)/kernel/drivers/
  6. make install #copies the boot image (vmlinuz-kernelversion) and ramdisk initialization image (initrd-kernelversion.img) into your /boot directory and sets up the System Map

If there are any problems during the above processes, all I can suggest is that you start again from the beginning, doing a make mrproper before make distclean and if that fails, do a "Google" search on the error string you are getting. Someone else may have run into the same problem.

Check that you have the relevant vmlinuz, initrd and System Map files in your /boot directory. For example, if your EXTRAVERSION name is -8W4L, you should see files with that suffix included in their name.

Re-point your /usr/src/linux-2.4 symlink as follows:

cd /usr/src/
rm linux-2.4
ln -s linux-2.4.20-8W4L linux-2.4

Now configure your boot loader. I use Grub, for which the relevant configuration file is /boot/grub/grub.conf. Here is an example:

default 1
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/hda2
#          initrd /initrd-version.img
#boot=/dev/hda
timeout=10
splashimage=(hd0,0)/grub/splash.xpm.gz
password --md5 ******
title Red Hat Linux Win4Lin-enabled (2.4.20-8W4L)
        root (hd0,0)
        kernel /vmlinuz-2.4.20-8W4L ro root=LABEL=/ hdc=ide-scsi
        initrd /initrd-2.4.20-8W4L.img
title Red Hat Linux (default config 2.4.20-8)
        root (hd0,0)
        kernel /vmlinuz-2.4.20-8 ro root=LABEL=/ hdc=ide-scsi
        initrd /initrd-2.4.20-8.img

If you are using Lilo, the syntax is different (refer to Lilo documentation) and you must remember to run lilo before rebooting. Now you can reboot and test your patched kernel. When you are happy that it works, set the Grub default to 0: this will start the Win4Lin kernel, as in this example, by default.
Finally, if you are installing an application supported by the new kernel, download the application as .rpm, tarball or (in the case of Win4Lin) an installer script and install according to the supplier's instructions.



Previous