Thursday, July 16, 2015

Compile a Custom Kernel on Debian

This post is mostly a note to myself in case I ever have to do this again, but if you can make use of it, please feel free!

So you'd like to compile your own kernel in Debian. There are at least a few valid reasons why. First, the reason I did it, is to test kernel patches. Second, you may want to configure your kernel to work around driver bugs. For example, see this Debian-PPC-mailing-list thread about compiling your kernel to get the Nouveau driver working on G5 Power Macs (long thread, but very interesting information). And third, you may want to test newer kernels from upstream to get a head start on bug squashing. In any event, here are the exact steps I took to compile my own kernel in Debian Linux:

sudo aptitude install fakeroot kernel-package libncurses5-dev #installs the development packages (about a gigabyte).

sudo aptitude install linux-source-3.16 #installs the source into /usr/src.

cd ~/Development #change directory into the "Development" folder in my home folder.

tar -Jxf /usr/src/linux-source-3.16.tar.xz #unpacks the source into current directory.

cd ~/Development/linux-source-3.16 #change to linux-source-3.16 directory; if you're applying patches, this is the stage to do it.

make menuconfig #configure your kernel options.

make-kpkg clean #clean stuff?

fakeroot make-kpkg --initrd --revision=1.0 --append-to-version=-custom1 kernel_image #compiles the kernel; the "--revision" and "--append-to-version" options may be redundant, but I just did them both; notice the "-custom1" begins with a leading "-".

sudo dpkg -i ../linux-image-3.16.7-ckt9-custom1_1.0_powerpc.deb #installs the kernel.

So there you have it! It should automatically make your new kernel the default, but if it doesn't you can add a new kernel section to /etc/yaboot.conf, placing it at the top above the "Linux" and "old" sections. Conclude of course by running "sudo ybin -v".

The actual compiling took eight hours on my G3 iBook, and not wanting to burn out my iBook compiling a kernel, I set up a desk fan to blow across the keyboard to keep temperatures sane. Here's a time saver, though: If you want to apply subsequent patches, you can go straight to the "fakeroot make-kpkg" step and this will only recompile the modules you're patching rather than the whole kernel. So that's nice.

Finally, if you want to test new development kernels, obviously you'd download the source from upstream rather than Debian's repository.

Debian kernel compiling reference link (h/t rican-linux).


  1. Dan,

    Thanks for posting this information!

  2. I was eventually going to write a very similar article, but now I don't have to. :) Thanks for sharing!