Customizing & Installing Linux Kernel on Debian Squeeze

Here is a quickie for customizing and install Linux kernel 2.6.x on Squeeze.

Install some packages and kernel source:

$ sudo aptitude update
$ sudo aptitude install kernel-package bzip2 g++ libqt3-mt-dev libncurses5-dev sudo fakeroot

If you do not belong to group “src”, add yourself to the group as we work under /usr/src:

$ sudo adduser username src

You need to logout and login for this change to take effect. You also need to be able to use sudo or su to install the new kernel in the end.

The kernel packaged for Squeeze is at version 2.6.32. Alternatively a newer kernel could be obtained from and saved to /usr/src. The customization procedure should be similar. Here I just follow the Debian way:

$ sudo aptitude install linux-source-2.6.32

Extract the source tree:

$ sudo chgrp -R src /usr/src
$ sudo chmod -R g+w /usr/src
$ cd /usr/src
$ rm linux
$ tar -jxf linux-source-2.6.32.tar.bz2
$ ln -s linux-source-2.6.32 linux
$ cd linux

Edit the EXTRAVERSION entry in Makefile, as in:

EXTRAVERSION = .20100321.1

for example to add .20100321.1 to the kernel version number. This is convenient for keeping the existing, working kernels around when you need to recompile with different options.

Use xconfig or menuconfig to customize the kernel options. Before the make-kpkg lines, setting concurrency (most likely to the number of cores of my processor) is optinal but having a higher number typically reduces the compilation time.

$ make mrproper
$ make xconfig    # or make menuconfig
$ export CONCURRENCY_LEVEL=4    # this is optional
$ fakeroot make-kpkg clean
$ fakeroot make-kpkg --initrd kernel_image
$ cd ..
$ sudo dpkg -i linux-image-

Upon reboot in the GRUB menu you will find the newly installed kernel:

$ sudo reboot

Purging Old Kernel Image from System

For example, if the kernel to be uninstalled is of version 2.6.26 and the extra version that I used was 20091112.1, do:

$ sudo dpkg -P linux-image-

That’s it. However it is often a good idea to keep at least one kernel image that I know for sure to work so that when a custom kernel fails, I have something to fall back on.  On the other hand, it is also a good idea to purge very old kernel images to save space in /boot.

Giving Kernel Boot Options with Grub (Version 2)

The new Grub has a slightly different way of specifying boot options (/boot/grub/menu.lst no longer exists for version 2!).

$ sudo chmod +w /boot/grub/grub.cfg
... open and edit /boot/grub/grub.cfg ...
$ sudo chmod -w /boot/grub/grub.cfg

If I need to provide a kernel with boot options, find the “menuentry” for the kernel, and change from

linux /vmlinuz- root=UUID=somehash ro quiet


linux /vmlinuz- root=UUID=somehash ro quiet usbcore.autosuspend=1

in order to set the usbcore.autosuspend option, for example.


With Core i5 (2 cores but virtually 4 cores with hyperthreading), I get:

$ fakeroot make-kpkg clean
$ time fakeroot make-kpkg --initrd kernel_image
real    6m50.028s
user    21m45.186s
sys     2m42.246s

$ fakeroot make-kpkg clean
$ time fakeroot make-kpkg --initrd kernel_image
real    13m55.216s
user    13m23.638s
sys     1m50.359s

I say significant speed up!

What if Kernel Panics after Reboot?

(NOTE: This was true back when I was playing around when Squeeze was still far from stable. I don’t think this section is relevant as of November 2010, since Squeeze is very close to stable now. Just leaving the note in case for its archival value.)

Well, it turns out make-kpkg --initrd does not automatically create a /boot/inird.img-* file for my current configuration. I wondered for a while why my new custom kernel keeps panicking upon reboot but finally realized that was the cause.

Fortunately, I can create the image myself easily:

$ sudo update-initramfs -c -k
$ sudo update-grub

This should work.

This entry was posted in Uncategorized and tagged , , , , , . Bookmark the permalink.

12 Responses to Customizing & Installing Linux Kernel on Debian Squeeze

  1. Pingback: Installing Debian Squeeze (AMD64) on Lenovo T410s « Biboroku

  2. Pingback: Installing Debian Squeeze on Dell XPS 630i « Biboroku

  3. Pingback: USB 3.0 ExpressCard Adapter on Debian Squeeze | Biboroku

  4. Carlo Pires says:

    Thanks for posting. This helped me a lot.

  5. Pingback: Debian Linux - Squeeze - Build audio driver snd-cs46xx

  6. jim woodward says:

    does this method create headers?
    what should i do when sysnapsis wants to install a kernel that is older than the one I installed?
    thanks for post,

    • Taro says:

      Jim — If you have problem reverting to the custom kernel, you can try reinstalling it. But usually at boot (with grub/lilo) you should continue to have an option to choose whatever kernel installed on your system.

      • jim woodward says:

        My problem is: (and maybe it’s just ignorance)
        How do I get synaptic to not want to install a kernel which
        is older than the one I compiled and am using?
        My present kernel is

        • Taro says:

          I personally don’t use Synaptic (just using apt-get or aptitude command-line), so if there’s any specific difference I don’t know how to go about it. If it’s a security update, I tend to apply all package updates including kernel related stuff (via aptitude update, upgrade, dist-upgrade sequence, for example).

          Even after you do that, the custom kernel doesn’t get overwritten. The version you custom installed should continue to be available during the boot menu with grub or lilo. You just need to choose one, if not set as default. We actually have an option to keep kernel builds with different kernel options (after all customization is where Linux shines….). My older desktop still has 2.4.X kernel builds, and I sometimes run it when I have problems with the box….

          If you really need to keep your package to an older version, there is a way to do it (with apt pinning and such), but I don’t know why you need to bother with it in the kernel updates. I can imagine a few instances in which conflicts between the custom kernel and prepackaged versions need to be resolved (e.g., building a kernel module against a source), but unless you have that type of problem, I don’t see why you wish to bother with not applying security updates and all.

  7. shawn bai says:

    Hi, so great, I have the same problem that initrd is not produced,
    image is ok

    I follow your guide, it actually works out. Thanks.
    Well, it turns out make-kpkg –initrd does not automatically create a /boot/inird.img-* file for my current configuration. I wondered for a while why my new custom kernel keeps panicking upon reboot but finally realized that was the cause.

    Fortunately, I can create the image myself easily:

    $ sudo update-initramfs -c -k
    $ sudo update-grub
    BTW, wubi is the tool used to install Xubuntu.

  8. Pingback: Setting up a Quantum LTO5 Tape Drive on Debian « Stream #0

Leave a Reply

Your email address will not be published. Required fields are marked *