Build a RHEL5 kernel using a custom configuration

From time to time, RedHat’s predefined kernel configuration does not suit your needs. You may want to disable or enable drivers that are not in the stock config, or you may want to build more specialized kernels. But you want to keep the build framework and all the patches. Here’s a short howto. With small changes, it works on RHEL4 as well. In Fedora, the build framework has become a bit more mature, with more options and less editing of files. You can find their corresponding document at http://fedoraproject.org/wiki/Docs/CustomKernel.

In the following you may replace “i686″ and “i386″ for “x86_64″ if you have an AMD64 or EM64T cpu on your target system. Run the following on a build system. If you are of the more clever users (you are reading this, right?), you’ll replace /usr/src with your private rpm build space, see http://users.linpro.no/ingvar/rpm.html.

  • Download kernel-2.6-something.src.rpm from RHN
    Surf to https://rhn.redhat.com/
    -> Channels
    -> Red Hat Enterprise Linux Server 5
    -> IA-32 (i386)
    -> Packages
    -> Filter by Package: kernel -> Go
    -> kernel-some-version
    -> Download Source Package

  • Install the source package you just downloaded into your rpm build space
    rpm -ivh kernel-2.6-something.src.rpm
  • Install build dependencies
    yum install ncurses-devel kernel-devel make gcc
  • Unpack source code to get access to the configuration files
    cd /usr/src/redhat/SPECS
    rpmbuild -bp --target=i686 kernel-2.6.spec
  • Pick a starting point configuration, for example, stock i686
    cd /usr/src/redhat/SOURCES
    find . -name kernel\\*config
    cp kernel-2.6.18-i686.config kernel-2.6.18-i686.config.orig
    cp kernel-2.6.18-i686.config /usr/src/redhat/BUILD/kernel-2.6.18/linux-2.6.18.i686/.config
  • Make your local configuration changes
    cd /usr/src/redhat/BUILD/kernel-2.6.18/linux-2.6.18.i686
    make oldconfig
    make menuconfig
  • RedHat’s build system needs a commented line in the top of the config file with the target system’s generic architecture platform
    vi .config

    Enter line on the top with a ‘#’ followed by a space and the output of the command ‘uname -i’ on the target system. For, for example, a 32bit intel box, the top line of .config should read:

    # i386
    

    Then copy the file back to the SOURCES directory

    cp .config /usr/src/redhat/SOURCES/kernel-2.6.18-i686.config
  • Configure what kernel variants you want to build. Also add a local identifier in the release field, so you don’t match an existing kernel.
    cd /usr/src/redhat/SPECS
    vi kernel-2.6.spec

    Change the following lines, unless you need extra packages like xen, doc, pae, or kernel-headers. Search for lines that look the ones below. Do not enter new tags. Instead of “local”, you may write anyhting you want in the release tag.

    %define buildxen 0
    %define builddoc 0
    %define buildkdump 0
    %define buildheaders 0
    
    %define release 8.1.15.local%{?dist}
    
    %ifarch i686
    %define buildpae 0
    
  • Build the kernel. This may take 10 minutes, or 2 hours, depening on your build system cpu/memory, and how many kernel packages you are building.
    time rpmbuild -bb --target=i686 kernel-2.6.spec
  • Leave a Reply