Aerospace



Home

Company Information

Information Request

Linux How-to Guides

ADSP 21xx
Digital Signal Processing
Tutorials

SW Utilities

On-line Order Form

Linux Support

Windows Support


Bonk

Have you found this site useful? Did we save you time? Did we cure your head-ache? Is your hair growing back now?

Please make a donation to help with maintenance.


Custom Search

Kernel Patch HowTo

Herman Oosthuysen
for Mandriva 2006 and later, Updated April 2007.

Copyright Aerospace Software Ltd, GPL, http://www.gnu.org, 2003.


Scope

This document provides a brief description of the Linux kernel patch and compile process.

This process is documented in many generic howtos, but this one is version specific and therefore without all the generic caveats, disclaimers, tricks and traps for all the other Linux distributions, which can make a guide hard to follow. This is important, since a single mistake will blow you out of the water...


For the Super Impatient

If you wish to do the bare minimum to compile software, install the source as explained below then:

make oldconfig && make prepare && make modules_prepare

For the Normal Impatient

If you wish to compile software on your system, then you first have to compile the kernel, to ensure that all dependencies and headers are set up.

Get your kernel version:

# uname -a

Run MCC Software Configuration and search for 'kernel' and install the source for your kernel version.

Now do this:

# cd /usr/src/linux
# make mrproper
# make oldconfig
# make bzImage
# make modules

If you only wish to be able to compile software, then stop here.

If you wish to really hack and install the kernel, then do:

# make modules_install
# make install
# reboot

Le voila!


For a Redhat, Fedora or Centos System

On new Redhat systems, the headers are included in the kernel-devel package and the compile process is a little different. First you need to update a few things:

# up2date redhat-rpm-config rpm-build
# up2date --get-source kernel
# rpm -ivh /var/spoo/up2date/kernel*.src.rpm

Then you have to prepare the kernel source and links:

# cd /usr/src/SPECS
# rpmbuild -bp --target-i686 kernel-2.6.spec
# cp -a /usr/src/redhat/BUILD/kernel-2.6.x.y/linux-2.6.x.y /usr/src
# ln -s /usr/src/linux.2.6.x.y /usr/src/linux

Now you can build the kernel:

# make mrproper
# make oldconfig
# cp .config .config.old
# make

You can stop here if you only want to compile other programs and did not change the kernel, or you can install it again:

# make modules_install
# make install

La voila!


Manual Install

Copy the compressed kernel image to the /boot directory:

  • # cp  /usr/src/linux/arch/i386/boot/bzImage  /boot/vmlinuz-2.4.22-1as.img

Why vmlinuz?

There is some history behind that.  Digital Equipment Corporation had an OS called VMS, so at first vmlinux was used, then it was compressed and became vmlinuz.  You can call your image whatever you want, though it is easier to find your way around a system if everybody keeps to the same conventions.


Post Install

Edit /etc/lilo.conf (or /boot/grub/menu.lst) and include an option to boot from the new image. Copy the default text, change the image and label:

image=/boot/vmlinuz-2.4.22-1as.img
label=linux-2.422-1as
read-only          
root=/dev/hda1 
I

f you have modified the lilo.conf file, you have to install the boot loader, else the system will not be able to boot.  Grub is less finicky.  I only give a Lilo example, since this is the tricky one:

  • # /sbin/lilo

Save the new configuration:

  • # cp  System*.map*  /boot/
  • # cp  ./config  /boot/config-2.4.22-1as
  • # cp  ./config  /usr/src/kernelconfigs/config.2.4.22-1as

Kernel Patch Process

If you need to apply a kernel patch, first do all of the above without making any configuration changes and make sure that the system can boot up as before.  Only then patch the kernel, rinse and repeat.  Otherwise, if the system won't boot up after applying the patch, you will have no idea about what went wrong and you may have difficulty recovering from the disaster...

To make the patch process work, keep separate directories for an original kernel source tree from Mandrake Linux, and your modified kernel source tree.  We assume that your /src/linux symbolic link is pointing to your brand new super kernel version.

Make a Patch

Create a compressed patch file for your modified kernel source tree with the diff and bzip  utilities - the basic syntax of diff is
diff [options] from-file to-file:

  • cd  /usr/src
  • diff --unified  --recursive  --new-file  linux-2.4.22-6mdk  linux > yourpatch-2.4.22-6mdk
  • gzip  yourpatch-2.4.22-6mdk

Apply a Patch

The bzip, cat and patch utilities are used to apply a compressed patch file to a directory tree pointed to by the /src/linux symbolic link:

  • cd  /usr/src
  • zcat  yourpatch-2.4.22-6mdk.gz  |  patch  -p0  -E

Check for rejected parts:

  • find  /usr/src/linux  -name  '*.rej'  -print

This happens when you apply a patch to a different kernel version than the one the patch was intended for.  Remove any rejected files after manual patching has been done with:

  • find  /usr/src/linux  -name  '*.rej'  -exec  rm '{}' ';'

Any files that would be modified by the patch are first backed-up into a file with the same name, but with the suffix of .orig added.  You can remove these files with:

  • find  /usr/src/linux  -name  '*.orig'  -exec  rm  '{}' ';'

RPMs

While we are on the compile topic, note that whenever you make and install software from source, it is actually a good idea to compile the programs to RPMs, since then you are able to easily remove them again, if you have to.

Making RPMs used to be a black art, steeped in mystery, but thanks to a utility called checkinstall the voodoo is no more. Get checkinstall here: http://asic-linux.com.mx/~izto/checkinstall/download.php

For Mandriva 10.2LE, you have to get the source code 1.6.0 or later and compile checkinstall. Don't use the RPM file, it is for RedHat.

Using checkinstall, the method to make an RPM is extremely simple:

# ./configure
# make
# checkinstall

The result is a RPM file, which can then be installed with:

# rpm -i whateveritis 

For the growing army of Ubuntu Geeks, Checkinstall can make 'debs' too.


'Hope this helps!
Herman



Copyright © 2005-2008, Aerospace Software Ltd., GPL.