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 kernel.org 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-220.127.116.1100321.1_18.104.22.16800321.1-10.00.Custom_amd64.deb
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-22.214.171.12491112.1
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-126.96.36.199.3 root=UUID=somehash ro quiet
linux /vmlinuz-188.8.131.52.3 root=UUID=somehash ro quiet usbcore.autosuspend=1
in order to set the usbcore.autosuspend option, for example.
Playing with CONCURRENCY_LEVEL
With Core i5 (2 cores but virtually 4 cores with hyperthreading), I get:
$ fakeroot make-kpkg clean $ export CONCURRENCY_LEVEL=4 $ time fakeroot make-kpkg --initrd kernel_image ... real 6m50.028s user 21m45.186s sys 2m42.246s $ fakeroot make-kpkg clean $ export CONCURRENCY_LEVEL=1 $ 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 184.108.40.20600321.1 $ sudo update-grub
This should work.