Buildng a Custom Redhat Kernel RPM

This howto may also be useful for modifying other RedhatLinux packages as well. Much thanks to AaronCaskey for writing the original version of this.

See also: RedhatLinux, UsingRpm, DebianKernelPackage

Download the Source RPM

  1. Download the official RedhatLinux SRPM (remember to check the updates directory for the latest version)

    http://mirror.aarnet.edu.au/pub/linux/redhat/updates/9/en/os/SRPMS/

  2. Install the source RPM into /usr/src/redhat/SOURCES:

    # rpm -Uvh kernel-<version>.src.rpm

Patch the Kernel

The Redhat Way is to leave the original source alone and only make changes via patching, it's a good idea to stick to that.

Creating Patches

The latest version of AutoMount 4.1.0 comes with a patch for the Redhat kernel (for ghosting support) so for that we don't need this step. However if you need to make changes and don't have a patch here's an (untested) example of how to make one:

  1. Find the .spec file for the newly installed kernel sources:
    # cd /usr/src/redhat/SPECS
  2. Prepare the sources for building (-bp means "build prep")

    # rpmbuild -bp kernel-2.4.spec
  3. The prepared source should now be in the BUILD directory, make a copy of it before you make any changes.
    # cp -a /usr/src/redhat/BUILD /tmp/
  4. Now make what ever changes you require to the kernel sources, when you are done you can make a patch by diff'ing your copy against the modified original. The generated patch is what you use in the next step.
    # diff -ur ????? > /tmp/kernel-custom-adam.patch

Applying Patches

  1. Copy any desired patches into /usr/src/redhat/SOURCES:

    # cp /tmp/autofs4-2.4.20-redhat.patch /usr/src/redhat/SPECS
  2. It's a really good idea to edit the release tag in the spec file. If you add a site tag and build number then you'll be able to figure out which boxes are running which version of a custom kernel:

    %define release 30.spack.01
  3. Now add patch to the list of patches in the spec file (I had to put the autofs patch at the end to avoid it conflicting with another patch):
    Patch11040: autofs4-2.4.20-redhat.patch
  4. And add the patch, and any required options to patch, to the application section of the spec file:
    "%patch11040 -p1"
  5. Test the patching process, your patch should show up in the output. If it generates errors you need to figure out what's wrong and fix it before you continue.
    # rpmbuild -bp kernel-2.4.20.spec

Compiling the Kernel

Assuming everthing went well you should now be ready to build a new kernel:

  1. Change into the SPECS directory:
    # cd /usr/src/redhat/SPECS
  2. Build the kernel packages you require. You may want to specify which targets you require inux system can build kernels for muliple targets:
    # rpmbuild -ba kernel-2.4.20.spec                 # builds the i386 kernel, sources, docs etc
    # rpmbuild -bb --target=i686 kernel-2.4.20.spec   # to build the bigmem and other i686 kernels
    
  3. When it's finished building you should have these kernels:
    # ls /usr/src/redhat/*RPMS/*
    /usr/src/redhat/SRPMS:
            kernel-2.4.20-30.spack.01.src.rpm
    /usr/src/redhat/RPMS/i386:
            kernel-2.4.20-30.spack.01.i386.rpm
            kernel-doc-2.4.20-30.spack.01.i386.rpm
            kernel-BOOT-2.4.20-30.spack.01.i386.rpm  
            kernel-source-2.4.20-30.spack.01.i386.rpm
    /usr/src/redhat/RPMS/i686:
            kernel-2.4.20-30.spack.01.i686.rpm
            kernel-bigmem-2.4.20-30.spack.01.i686.rpm
            kernel-smp-2.4.20-30.spack.01.i686.rpm
    

Installing the New Kernel

Install your new kernel RPM the same way you would for anything else:

Modern versions of RedhatLinux will update the GrubBootloader automatically, if you use the LiloBootloader you'll need to update your /etc/lilo.conf manually.


CategoryUnix

RedhatKernelPackage (last edited 2004-02-28 05:37:20 by AdamShand)