Friday, February 5, 2010

Building a Custom Kernel from Source

I've managed to avoid this for quite a while, but there was no escape this time.

On my last blog post I mentioned that I've hit a problem with the new Debian/testing Kernel (2.6.32).

After a quick search I found Kernel bug #14791, which seemed to be my exact problem. The good news was that there was a patch available, the bad news was that it was "[dropped] from the list of recent regressions due to the lack of testers".

So I stepped forward and decided to test the patch, hoping, first, that it does indeed fix my problem, and second, that it would be incorporated in the next Kernel release, if and when I verified that it worked.

But this meant that I needed to compile an upstream Kernel and install it. Twice (once to verify that the most current Kernel has this problem, and another to verify that the patch fixes it).


Well, doing this, on a Debian box, turns out to be actually rather easy, as long as the upstream Kernel isn't too far removed from a Kernel that's already installed on your box. It's even easier than compiling the official Debian Kernel source package - trust me, I tried.

The official guide is at the Debian Linux Kernel Handbook, where chapter 4 describes common Kernel related tasks such as Building a custom kernel from the "pristine" kernel source (section 4.5).

So here's how I did it, using Kernel source code from the mainline Git repository:
  1. get the source code:
    git clone git://
  2. copy the current Kernel configuration to the source tree:
    cd linux-2.6
    cp /boot/config-2.6.32-trunk-686 ./.config
  3. configure the Kernel (based on the current configuration):
    make oldconfig
    you'll be presented with a series of configuration questions (mostly, I just selected the default options by hitting ENTER repeatedly) - this is likely to be a short process, as long as you're compiling a Kernel that's similar enough to the one from which the base configuration was taken
  4. run:
    make-kpkg clean
    fakeroot make-kpkg --initrd --revision=foo.1.0 kernel_image
    the string foo.1.0 will be the version of the resulting Debian package
  5. after a rather long while the build will, hopefully, finish successfuly, and you'll be left with a Kernel Debian package in the parent directory ../linux-image-2.6.33-rc5_foo.1.0_i386.deb
  6. install the new Kernel (as root):
    dpkg -i linux-image-2.6.33-rc5_foo.1.0_i386.deb
  7. for some reason the above step did not generate an initramfs image, so you may need to create one:
    update-initramfs -k 2.6.33-rc5 -c
The end of the story is that I verified that the patch does fix my problem, and after I reported my findings, the patch was submitted by its author, and was soon accepted.

It ain't much of contribution, I know, but it's definitely more than I had expected to be making...

No comments:

Post a Comment