Custom Kernels on Debian

I’ve been running Debian on my laptop for the last two months. Some people were quite surprised about that since I’m such an Ubuntu religious nut and all, but I’ve always liked Debian and running it again have made me realise yet again  just how awesome it is. I’ll probably install Ubuntu on it again for Unity. In my humble opinion Unity’s underlying technologies is better than what is used in Gnome Shell and it’s not available in Debian yet, but that’s a whole different blog post entirely.

An unnatural deep-seeded desire to run the latest and greatest

I haven’t bothered with custom kernels in a long time. I think the last time I ran a custom kernel on my own machine was in 2006. There was a time where I would just read kernel code and change random things just to see what would happen, I’m definitely not that brave anymore.

Today, while reading through the Ubuntu Alpha 2 release notes I noticed that it ships with kernel 2.6.38-rc2, and that it also contains the famous ‘200 line patch‘ that improves desktop performance on high loads. I wanted in on that, but the newest pre-built Debian kernels are on 2.6.37. I thought that I might as well see how much work it is to install a vanilla kernel these days, and as it turns out, it’s incredibly easy.

How it’s done

  1. Download a kernel tarball from kernel.org and put it in a new directory and extract
  2. Install the ‘kernel-package’ package
  3. If you’d like to make any modifications, do so and run ‘make-kpkg –initrd kernel_image’ (with sudo or fakeroot if you’re not root) in the root of the kernel source
  4. It will base the configuration on your running kernel and prompt for new features/drivers/etc. If you’re unsure or don’t care about a question, just press enter.
  5. After the process is complete, you’ll have a brand new kernel package one directory up. All you need to do is install it using “dpkg -i”. It will create an initramfs image and add it all to GRUB for you in the postinst scripts.
  6. Reboot to run the new kernel.

That was surprisingly easy. The kernel booted the first time and wi-fi/sound/video/suspend/etc works 100%. Even better, I get a package that I can recycle on other computers if I want and when Debian releases a newer kernel, then I can simply update using my favourite package management front-end.

You may also like...

9 Responses

  1. James Johnson says:

    You might also be interested in ulatencyd. It’s a daemon that controls how the kernel spends it’s resources. I’m using it with the stock Ubuntu 10.10 kernel (2.6.35-25-generic) with good results.

    URL: https://github.com/poelzi/ulatencyd/

  2. Note that by doing things this way, you miss out on all of the kernel patches that stock Debian / Ubuntu kernels include. It may be better to start with one of those source packages and apply the patches you want, rather than starting with a stock kernel.org tree.

  3. jonathan says:

    @Tristan *nod* I did consider that. I’d like to see what gets patched, I’ll probably look at that today and hopefully I’ll actually understand what those patches do. I guess in such a high-profile package they will at least be well documented with references to bugs, etc :)

  4. Shane says:

    I’m curious as to why you think Unity is a better underlying technology than Gnome Shell. Are you actually planning a blog post for this? Will Debian ever get Unity packages?

  5. ace102 says:

    #! /bin/sh

    # Build_Kernel Ver. .00001
    # Run under /usr/src. Adjust .

    #Dependency Check
    #sudo apt-get install -y –force-yes build-essential bin86 kernel-package libqt3-headers libqt3-mt-dev wget libncurses5 libncurses5-dev
    #Wget the kernel
    #wget http://www.kernel.org/pub/linux/kernel/v2.6/testing/linux-2.6.38-rc2.tar.bz2
    #Untar the kernel
    #tar -xvjf linux-2.6.38-rc2.tar.bz2
    #Symbolic link the kernel directory
    #ln -s /media/ubu/Stuff/stuff/linux-2.6.38-rc2 linux
    #Apply any patches here. Repeat a Wget for the patch itself but they offer fully patched kernels now.
    #wget http://www.kernel.org/pub/linux/kernel//v2.6/snapshots/patch-2.6.37-git17.bz2
    #Apply patch
    #sudo bunzip2 patch-2.6.37-git17.bz2
    #sudo cp pat linux
    #sudo cp patch-2.6.37-git17 linux
    cd linux
    #Copy the previously used config for re-use in the new kernel.
    #sudo cp /boot/config-2.6.38-rc2 .config
    #Apply any patches here. ‘patch -p1 < ‘
    #sudo patch -p1 < patch-2.6.37-git17
    #sudo patch -p1 Save.
    #sudo make xconfig
    #Make it clean
    #sudo make-kpkg clean
    #sleep 180
    #sleep 60
    #Build the new kernel.Adjust Concurrency to the CPU cores +1. Install if the build completed successfully.
    #Add a break here if the build didn’t complete successfully or add ‘&& sudo dpkg -i *.deb’ after the step below. We can just move out of the directory if the stage is successful.
    #Move files from /include/generated to /include/linux
    #sudo cp /usr/src/linux/incldue/generated/* /usr/src/linux/include/linux
    sudo CONCURRENCY_LEVEL=4 make-kpkg –initrd kernel_image kernel_headers modules_image && cd ..
    #Back out of the linux directory
    #cd ..
    #Install the image and headers
    sudo dpkg -i linux*.deb
    #Remove the Kernel Directory and downloaded bz2s.
    #sleep 30
    #sudo rm -rf /usr/src/linux-2.6.37 && sudo rm /usr/src/linux
    #Symbolic Link the *new* headers directory to /lib/modules//build & source
    #First remove bad links if there are any.
    #Move .deb
    sudo mv *.deb /media/ubu/Goodone
    #
    sudo rm /lib/modules/2.6.38-rc3/build && sudo rm /lib/modules/2.6.38-rc3/source
    #Now synbolic link the new header directory to build and source.
    sudo ln -s /usr/src/linux-headers-2.6.38-rc3 /lib/modules/2.6.38-rc3/build && sudo ln -s /usr/src/linux-headers-2.6.38-rc3 /lib/modules/2.6.38-rc3/source
    #Reinstall any video,etc drivers after reboot or add a stage for envyng or something like that yourself.;)

  6. cphayes0882 says:

    Thanks for this little tutorial. I am trying to become a power user of linux, and this little guide is helping me. Thanks again for it.

  7. isama says:

    Thank you for writing this down. I’ve built a freebsd kernel before, it’s easy, but never built a working linux kernel. 2.6.38 is building right now, i think it’s going to work. THANK YOU.

  1. 3 February 2011

    […] This post was mentioned on Twitter by Arjan Waardenburg, Ubuntu World Wide. Ubuntu World Wide said: #ubuntu #linux Jonathan Carter: Custom Kernels on Debian: I’ve been running Debian on my laptop for the last two… http://bit.ly/gaG6Je […]

  2. 4 February 2011

    […] I haven’t bothered with custom kernels in a long time. I think the last time I ran a custom kernel on my own machine was in 2006. There was a time where I would just read kernel code and change random things just to see what would happen, I’m definitely not that brave anymore. More here […]

Leave a Reply