Building Kernels the Debian Way

This isn't for people who are happy using the Debian binary kernel image or who need the Debian kernel patches and the like. I have no idea how that stuff works, I fear, although I should learn at some point since I probably don't need to build my own kernel as much as I do.

I've always built my own kernel from when I started running Linux in the 1.0 days, and I've always had good luck with the generic kernel on the hardware I have. Under Red Hat I just built my own kernel from source the regular way, installed it manually, and copied the various supporting files around manually. For a while under Debian I did it the same way, but then Hua pointed me at the Debian way to do it and it was really easy.

For some reason, this doesn't seem to be at all well-documented, or at least I didn't find the documentation, so here are the instructions for people who are used to building their own kernel:

  1. Make sure you have kernel-package installed (this is the package that contains the kernel package building tools).

  2. Untar the appropriate kernel under /usr/src. You don't need a /usr/src/linux link to the versioned directory unless you want it, although if you have to build any drivers from outside the Debian packaging system, you'll need to tell them where the unpacked source tree is.

  3. cd into the kernel source directory and configure it however you want. I usually use make menuconfig, but whatever you like works. If you're just upgrading the kernel, you can skip this step and just copy your config from your previous kernel (usually in /boot/config-<version>) into a file named .config.

  4. Run make-kpkg kernel_image.

  5. Your kernel package is now sitting in /usr/src. Install it with dpkg -i.

That's all there is to it. Easy, isn't it? And now your kernel files are all tracked by the package manager, you can remove old kernels with the packaging commands, make-kpkg takes care of building all the modules and installing them at the same time, and it takes care of running lilo for you.

If you have other things that need kernel modules that don't come as part of the kernel (like AFS or ALSA), install the modules-source packages for those and untar the .tar.gz files that are put into /usr/src. This will create source directories in /usr/src/modules. Then, each time after you build the kernel, also run make-kpkg modules_image and you'll also get debs for all of your extra packages that you can install with dpkg -i. That's all there is to that too.

Some other things to be aware of: the kernel package will create a /vmlinuz link or updated it if it already exists. I personally don't like this link, so the good news is that if you delete it, the kernel packages are also smart enough to not recreate it. You will need to make sure that you update /etc/lilo.conf (or do the equivalent Grub configuration change) if you don't have your boot configuration just pointing to /vmlinuz (and you're probably going to want to add an entry for your old kernel just in case anyway), so there's still some lilo.conf updating that you have to do. I like to manually maintain a /boot/vmlinuz link to the latest kernel that I've installed, point the default LILO entry at it, and then keep a couple of entries for old versions around just in case.

Hope this helps someone else. Once I got past the hump of using the regular Debian tools, it's saved me a ton of time.

Last spun 2022-02-06 from thread modified 2013-01-04