Linux: Custom Kernels with Debian and Fedora

Fedora and Debian make building a custom kernel and packaging it for rollout a simple process.

 By Carla Schroder | Posted Jul 30, 2007
Page 1 of 2
Print ArticleEmail Article


Beyond the Deadline: How GDPR Will Impact Your Company's Risk and Security Profile

Last week we took a tour of the generic way of building custom Linux kernels. Today we'll look some nice Debian shortcuts, and Fedora's unique way of building custom kernels.

The Debian Way of Customizing Kernels

Debian's kernel source packages are named linux-source-[version]. The current official source package versions are linux-source-2.6.18 (stable), linux-source-2.6.21 (testing and unstable), and linux-source-2.6.22 (unstable and experimental).

Binary Debian kernel packages are named linux-image-[version]. It's been this way since version 2.6.12, if you're remembering the olden days of the kernel-source and kernel-image packages. The new naming convention opens the door to using other kernels with Debian, which I don't know what those would be, but Debian is ready for them.

To get started, install a build environment (see part 1), plus your kernel sources and the fakeroot package:

# aptitude install linux-source-2.6.22 kernel-package fakeroot

This downloads the source tarball into /usr/src/ where we do not want it, so you need to move it to your personal kernel-building directory:

# mv /usr/src/linux-source-2.6.22.tar.bz2 ~/kernel

Change to your personal kernel-building directory and unpack the tarball:

$ tar zxvf linux-source-2.6.22.tar.bz2

Then change to the top-level source directory and start configuring your new kernel:

$ cd linux-source-2.6.22
$ make mrproper
$ make xconfig

When you're done slogging through configuration, run these commands:

$ make-kpkg clean
$ make-kpkg -rootcmd fakeroot -rev kernel.1 linux_image

fakeroot gives you enough root privileges to build kernels as an ordinary user. It won't let you run commands that need genuine root privileges, but it's good enough for kernel-building. This leaves you with a .deb package named linux-image-2.6.22_kernel.1_i686.deb. Of course you may make the -rev option say whatever you want. Then install it in the usual way with dpkg:

# dpkg -i linux-image-2.6.22_kernel.1_i686.deb

This installs the modules and handles module dependencies, creates a boot menu entry, and copies the kernel and related file to the /boot directory. Now you can reboot, select your new kernel from the boot menu, and play with your new kernel.

The Fedora Way of Customizing Kernels

Fedora patches its kernels all to heck, to the point that a vanilla kernel may not work. Of course it costs nothing but a bit of time to try. But if you want to use genuine Fedora kernel sources they come in source RPMs, so you'll have to build your kernel and then package it into an RPM. First fetch your kernel SRPM from your favorite Fedora mirror, such as:

$ wget http://mirrors.kernel.org/fedora/releases/7/Fedora/source/SRPMS/kernel-2.6.21-1.3194.fc7.src.rpm

Then make sure you have the RPM building tools, plus the normal build environment from part 1:

# yum install rpmdevtools

The next step is to create a build tree in your home directory, and make sure to do this as yourself and not as the root user:

$ fedora-buildrpmtree

This creates an rpmbuildtree directory populated with BUILD, RPMS, SOURCES, SPECS, and SRPMS directories. Next, install the source RPM. This will unpack files into your new rpmbuildtree directory:

$ rpm -ivh 2.6.21-1.3194.fc7.src.rpm

Ignore the warnings about "group kojibuilder does not exist."

Next, run the %prep stage of the RPM rebuild, and make the --target option match your CPU type:

$ rpmbuild -bp --target=i686 ~/rpmbuild/SPECS/kernel-2.6.spec

This extracts the kernel tarball and applies all the Fedora patches. Now change to the source directory of your new build tree:

$ cd ~/rpmbuild/BUILD/kernel-2.6.21/linux-2.6.21-1.3194.i686/

And get started with configuring your new kernel:

$ make mrproper
$ make xconfig

Finally, roll it all up into an RPM:

$ rpmbuild --target i686 -ba ~/rpmbuild/SPECS/kernel-2.6.spec

Again, make the --target option match your CPU type. Your new RPM should be in ~/rpmbuild/RPMS/i686/. Grab your new kernel.rpm and install it just like any other RPM:

# rpm -ivh kernel-2.6.21-1.3194.i686.rpm

This handles all the chores of copying files to /boot and creating a boot menu entry, so all you do is reboot and select your new kernel from your boot menu.

Comment and Contribute
(Maximum characters: 1200). You have
characters left.
Get the Latest Scoop with Enterprise Networking Planet Newsletter

By submitting your information, you agree that enterprisenetworkingplanet.com may send you ENTERPRISENetworkingPLANET offers via email, phone and text message, as well as email offers about other products and services that ENTERPRISENetworkingPLANET believes may be of interest to you. ENTERPRISENetworkingPLANET will process your information in accordance with the Quinstreet Privacy Policy.