Monday, July 11, 2011

How to install linux kernel in Ubuntu 10/11

Open a terminal and type the following,

sudo apt-get install fakeroot kernel-wedge build-essential makedumpfile kernel-package libncurses5 libncurses5-dev


Then run the following command,

sudo apt-get build-dep --no-install-recommends linux-image-$(uname -r)


And finally type,

mkdir ~/src
cd ~/src
apt-get source linux-image-$(uname -r)
cd linux-2.6.32


At the time of writing 2.6.32 was the current kernel source, it should remain at this version throughout the life of Ubuntu 10.04

It is a good idea to start with the same .config as the currently running kernel, so type the following,

cp -vi /boot/config-`uname -r` .config


Now we are ready to customize the build and kernel options.

make menuconfig


Once you have finished, save and exit. It is now time to compile. However to speed up the build if you have a dual core processor type,

export CONCURRENCY_LEVEL=3


The general rule is 1 + the number of processor cores.

make-kpkg clean
fakeroot make-kpkg --initrd --append-to-version=-jian kernel-image kernel-headers


After a few minutes or hours your kernel compile will be complete. The next step is to install it.

The kernel package will be created in the parent directory of ~/src/linux-2.6.32 (i.e. ~/src)

cd ~/src
sudo dpkg -i linux-image...deb
sudo dpkg -i linux-headers-2.6.38Custom_amd32.deb



We are almost ready, prior to 10.04 the initramfs kernel image was automatically created. The Ubuntu wiki suggests using the scripts to create the image but I have been unsuccessful in using this method, hence the manual approach.

sudo update-initramfs -c -k all


BUG: Please use the alternate method described below as this command fails to create an image for your new kernel. Special thanks to Helios38. - 16/06/2010


Alternatively if you know the kernel version, substitute the word all with the kernel version.

Example, sudo update-initramfs -c -k 2.6.38.7


Finally we need to add the initramfs image to the grub.cfg file located at /boot/grub/grub.cfg.

For the easy and automatic method as oppose to manually editing the grub.cfg file, just type the following,

sudo update-grub


Now just reboot and your new kernel should automatically load.

How to remove your kernel

sudo dpkg -r linux-headers-...
sudo dpkg -r linux-image-...
sudo rm /boot/initrd.img-...