Building custom kernal RPMs for Fedora Core 4

From Nearline Storage
Jump to: navigation, search

To build RPMs as a general user you need to create an rpmbuild directory tree in your home directory. This only needs to be done once. Here are the commands:

$ cd ~
$ cp -a /usr/src/redhat rpmbuild
$ echo '%_topdir %(echo $HOME)/rpmbuild' >>.rpmmacros

(The following example assumes that the kernel package being rebuilt is the 2.6.17-1.2139_FC4 package.)

Download the kernel source from http://download.fedora.redhat.com/pub/fedora/linux/core/updates/4/SRPMS/kernel-2.6.17-1.2139_FC4.src.rpm

$ rpm -ivh kernel-2.6.17-1.2139_FC4.src.rpm
$ cd ~/rpmbuild/SPECS
$ rpmbuild -bp --target i686 kernel-2.6.spec

"rpmbuild -bp" executes the %prep stage from the SPEC file, which unpacks the source and applies any patches.

If you have your own patches to apply, modify the SPEC file to apply them for you.

$ cd ~/rpmbuild/BUILD/kernel-2.6.17/linux-2.6.17.i686

Edit the Makefile and set EXTRAVERSION to be something unique. This will be tacked onto the end of the kernel version info to identify it as your kernel when it gets installed.

The next step is to configure the kernel. If you are using a packaged kernel from the distibution, you can find the config file that was used to build it in your /boot directory. It will be named config-<kernel_version>. If you'd like to use it as a starting point then copy it into /rpmbuild/BUILD/kernel-2.6.17/linux-2.6.17.i686/ and name it ".config". Compile and launch the kernel configuration tool with the following command:

$ make menuconfig

Move the config file that was created to where the build process will find it:

$ cp .config ~/rpmbuild/SPECS/kernel-2.6.17-i686.config

Build and install the kernel:

$ rpmbuild -ba --target i686 ~/rpmbuild/SPECS/kernel-2.6.17.spec
$ cd ~/rpmbuild/RPMS/i686
$ sudo rpm -ivh <kernel_rpm>

Use mkinitrd to make the new boot image file (for example):

$ mkinitrd initrd-2.6.16-1.2115_FC4.img 2.6.16-1.2115_FC4

Finally, add a stanza to /etc/boot.cfg for your kernel and try booting it.