Linux Step By Steps


REVISED October 2001

Mike Andrew / David Bandel

Patching a kernel refers to upgrading to the latest 'n greatest by small increments.

Rather than downloading a  25 meg source, it is possible, indeed desirable from your point of view, to simply apply the changes in source code that occur between revisions. These changes can be as little as half a megabyte. A considerable saving in download time.

First and foremost the kernel source you upgrade must be 'pristine'. It means that at some time previous, you have obtained a pristine kernel source from or one of it's mirrors. Redhat distribution source code is NOT pristine (nor is any other distro). You must work from pristine source, or, have the ability to reverse patch what ever changes a distributor made. If this is the case for you, bite the bullet, download a pristine kernel, and use these steps for ever more.

"pristine source" is exactly that. Unmodified source code. It does not apply to the compiled binaries or any extraneous additions that may be present in the directory. Thus, you can safely compile pristine source, create and boot the kernel image derived from it, and regardless of all the now extra bits 'in there' , it is still, pristine source. This means you can conveniently port your current kernel configuration into the new kernel, without problems. It is not, "source code".

The steps required for patching a kernel are exceptionally easy.

Now be warned. One slip, one typo on your part, can devastate the source you have. Read every step carefully.

The examples used assume pristine kernel source 2.4.10 located in
and the symlink
/usr/src/linux pointing to it.

One: Obtain the patch.

The patch you require is one more than your current pristine kernel.

download patch-2.4.11.bz2  from

place this patch file into /usr/src

repeat this step for each patch above 2.4.11

Two: Prepare a new linux folder.

Type the following

cd (space) /usr/src
cp (space) -r (space) linux-2.4.10 (space) linux-2.4.11
rm (space) linux
ln  (space) -s (space) linux-2.4.11 (space) linux

Three: dry run

bzcat (space) patch-2.4.11.bz2 (space) | (space) patch (space) -p0 (space) --dry-run (space) | (space) more
What this command does is unpack the compressed patch file and automatically apply it to the "linux" directory. the --dry-run is test mode, it won't damage the source if there's an error. The verb "more" allows you to check thru the processing looking for a FAIL message. A pristine source will NEVER fail No ifs, no buts. If you get FAILS, you dont have a pristine source, simple as that.

Alternatively, you can type the following
bzcat (space) patch-2.4.11.bz2 (space) | (space) patch (space) -p0 (space) --dry-run (space) > (space) dump

You can then edit the "dump" file to your heart's content, looking for fail messages.

Four: the Full Monty.

bzcat (space) patch-2.4.11.bz2 (space) | (space) patch (space) -p0

Five: iterative

You are now ready to complle kernel 2.4.11

You do so in the normal manner (see kernel->compile on this site)

If however you have a series of patches (say up to 2.4.99) simply iterate thru steps two to four before compiling. Remember that the criteria is to change the symbolic link, thus, the second iteration would be

cp (space) -r (space) linux-2.4.11 (space) linux-2.4. 12
rm (space) linux
ln  (space) -s (space) linux-2.4.12 (space) linux

and as each patch succeeds

rm linux-2.4.11

Naturally, in the examples above, you would NEVER

rm linux-2.4.10

2.4.10 (in this example) is your lifeline. You can always revert and start over if things went seriously awol.


To back a patch out, simply add the -R (reverse) switch:

     bzcat patch-2.4.xx | patch -p0   -R

One more Addenda: