TweakKernelPackage

Building a Custom Kernel RPM Package

This HOWTO is based on Kevin Hobbs' tutorial at http://oak.cats.ohiou.edu/~hobbsk/kernel-compilation-tutorial-en/index.html

The process was tested using Fedora Core 4 but may also work for other Fedora/Red Hat-based distributions.

Create RPM Build Environment

If you have not built RPM packages using your regular user account (not root) before, you should create an RPM build environment for your account before going any further.

Download the Source

Download the kernel-nnn.src.rpm from the SRPMS directory of your favourite Fedora mirror:

$ wget http://download.fedora.redhat.com/pub/fedora/linux/core/updates/4/SRPMS/kernel-2.6.15-1.1831_FC4.src.rpm
--12:08:40--  http://download.fedora.redhat.com/pub/fedora/linux/core/updates/4/SRPMS/kernel-2.6.15-1.1831_FC4.src.rpm
           => `kernel-2.6.15-1.1831_FC4.src.rpm'
Resolving download.fedora.redhat.com... 66.187.224.20, 209.132.176.20, 209.132.176.220, ...
Connecting to download.fedora.redhat.com|66.187.224.20|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 41,178,693 (39M) [application/x-rpm]

100%[===============================================================================>] 41,178,693   115.21K/s    ETA 00:00

12:13:27 (140.38 KB/s) - `kernel-2.6.15-1.1831_FC4.src.rpm' saved [41178693/41178693]

Install the Source

Use rpm to install the kernel source code:

$ rpm -Uvh kernel-2.6.15-1.1831_FC4.src.rpm
   1:kernel                 ########################################### [100%]

Disable SMP Build (Optional)

If a multi-processor kernel is not needed, edit ~/rpmbuild/SPECS/kernel-2.6.spec to disable the smp build. This step saves time and disk space.

%define buildsmp 0

Prepare Build

Use the rpmbuild prep stage to apply any patches and configure the kernel exactly as it is in the Fedora distribution:

$ rpmbuild -bp --target=$(arch) ~/rpmbuild/SPECS/kernel-2.6.spec
Building target platforms: i686
Building for target i686
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.99618
+ umask 022
+ cd /home/phowarth/rpmbuild/BUILD
+ LANG=C
+ export LANG
+ unset DISPLAY
+ '[' '!' -d kernel-2.6.15/vanilla ']'
+ cd /home/phowarth/rpmbuild/BUILD
+ rm -rf kernel-2.6.15
+ /bin/mkdir -p kernel-2.6.15
+ cd kernel-2.6.15
+ /usr/bin/bzip2 -dc /home/phowarth/rpmbuild/SOURCES/linux-2.6.15.tar.bz2
+ tar -xf -
...
+ echo '# i386'
+ cat .config
+ perl -p -i -e 's/^SUBLEVEL.*/SUBLEVEL = 15/' Makefile
+ perl -p -i -e 's/^EXTRAVERSION.*/EXTRAVERSION = -prep/' Makefile
+ find . -name '*.orig' -o -name '*~' -exec rm -f '{}' ';'
+ exit 0

Reconfigure the kernel

Use one of the kernel configuration interfaces to make changes to the kernel configuration. Since the entire source tree, including .config, will be overwritten before the actual build, you need to copy .config to the rpm source directory, replacing the original configuration for your architecture. In fact, you actually need to add make a small edit to the .config file, adding a comment line at the top of the file to specify the base architecture for your kernel:

$ cd ~/rpmbuild/BUILD/kernel-2.6.15/linux-2.6.15/
$ make menuconfig
$ (echo "# $(uname -i)"; cat .config) > ~/rpmbuild/SOURCES/kernel-2.6.15-$(arch).config
$ cd ~

{i} Some of the configuration interfaces require other packages, e.g. menuconfig requires ncurses-devel, xmenu requires qt-devel, and gmenu requires gtk2-devel.

Build the Kernel

The -bb option to rpmbuild will build the kernel binary package, performing every rpm build stage along the way but with the new configuration:

$ rpmbuild -bb --target=$(arch) ~/rpmbuild/SPECS/kernel-2.6.spec
Building target platforms: i686
Building for target i686
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.38044
+ umask 022
+ cd /home/phowarth/rpmbuild/BUILD
+ LANG=C
+ export LANG
+ unset DISPLAY
+ '[' '!' -d kernel-2.6.15/vanilla ']'
+ cd kernel-2.6.15
+ mv linux-2.6.15 deleteme
+ rm -rf deleteme
+ cp -rl vanilla linux-2.6.15
...
+ /usr/lib/rpm/redhat/brp-compress
+ /usr/lib/rpm/redhat/brp-strip-static-archive /usr/bin/strip
+ /usr/lib/rpm/redhat/brp-strip-comment-note /usr/bin/strip /usr/bin/objdump
Processing files: kernel-2.6.15-1.1831_FC4.phowarth
Processing files: kernel-devel-2.6.15-1.1831_FC4.phowarth
Processing files: kernel-debuginfo-2.6.15-1.1831_FC4.phowarth
Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
Checking for unpackaged file(s): /usr/lib/rpm/check-files /home/paul/tmp/kernel-2.6.15-1.1831_FC4.phowarth-root
Wrote: /home/phowarth/rpmbuild/RPMS/i686/kernel-2.6.15-1.1831_FC4.phowarth.i686.rpm
Wrote: /home/phowarth/rpmbuild/RPMS/i686/kernel-devel-2.6.15-1.1831_FC4.phowarth.i686.rpm
Wrote: /home/phowarth/rpmbuild/RPMS/i686/kernel-debuginfo-2.6.15-1.1831_FC4.phowarth.i686.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.61179
+ umask 022
+ cd /home/phowarth/rpmbuild/BUILD
+ cd kernel-2.6.15
+ rm -rf /var/tmp/kernel-2.6.15-1.1831_FC4.phowarth-root
+ exit 0

{i} The option -ba should be used (instead of -bb) to also make a source rpm if the new kernel will be distributed.

Install the Kernel RPM

Install the kernel rpm. Do not upgrade or otherwise replace a working kernel:

$ sudo rpm -ihv ~/rpmbuild/RPMS/$(arch)/kernel-2.6.15-1.1831_FC4.phowarth.$(arch).rpm
Preparing...                ########################################### [100%]
   1:kernel                 ########################################### [100%]

{i} This is the only time root privileges are required.


CategoryTip

Recent