Building custom kernels for Ubuntu

Friday, August 3rd, 2007 at 2:16 pm | 4,296 views | trackback url
Tags:

I’ve been building kernels for a very long time. In fact, I even wrote my own kernel HOWTO describing how to do it.

When I install a new Linux distribution from original media, the first thing I do, is replace the stock kernel with my own custom build, which is optimized for my own environment (tuning HZ, removing unused drivers, patching some other interfaces, etc.).

When I moved from Debian to Ubuntu, building kernels became a problem. All of the kernels I’d try to build from the upstream source would fail to complete a boot. At first, I thought it was something with mkinitrd(1). I tried to fix that and it would still fail to complete a boot.

So I started looking for some better options, and came up with this very small HOWTO:

  1. Download the latest kernel source that you want to run. If you want THE latest kernel source, you can pull Linus’ tree directly as follows:
    git-clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git linux-2.6
  2. Unpack it into whatever directory you want to use as scratch space. I tend to unpack the kernel source into $HOME/src, but you can use another location if you want. (Remember: Do not EVER build kernels as ‘root’, ever!)
  3. You’ll want to start with the same configuration that your running Linux kernel is using, and optimize from there. To do that, just do the following:
    zcat /proc/config.gz > config.new

    Or you can do:

    cat /boot/config-`uname -r` > config.new
  4. Copy that into your unpacked kernel source tree as .config
    cp config.new $HOME/src/linux-2.6/.config
  5. Now merge your existing config with the new features in the new kernel
    make oldconfig
  6. Install some of the necessary build tools for Ubuntu (or Debian)
    sudo apt-get install linux-kernel-devel fakeroot kernel-wedge kernel-package
    sudo apt-get build-dep linux-source
  7. Now just build the kernel source you’ve prepared
    make-kpkg --rootcmd fakeroot --initrd --append-to-version=-<custom_string_here> kernel-image kernel-headers
  8. That’s it! The kernel .deb packages will be in ../ after your build, and you can then go ahead and install them as root.
    sudo dpkg -i linux-headers-2.6.23-rc1-gnu_2.6.23-rc1-gnu-10.00.Custom_i386.deb
    sudo dpkg -i linux-image-2.6.23-rc1-gnu_2.6.23-rc1-gnu-10.00.Custom_i386.deb

That’s it. Now I can get back to a productive, working environment with the latest kernels on my laptop running Ubuntu, without much fuss.

Last Modified: Friday, August 3rd, 2007 @ 14:16

Leave a Reply

You must be logged in to post a comment.

Bad Behavior has blocked 918 access attempts in the last 7 days.