Home page of this blog

Thursday, November 18, 2010

Kernel compilation in ten steps -- Ubuntu

Introduction: Last article I mentioned about how I did kernel compilation from source code. Here is a step by step how to.

This kernel compilation article will work for debian and debian based distros (and of course Ubuntu)

Step 1: Fetch kernel source

Browse http://www.kernel.org and choose a stable version and click full source

For e.g 2.6.34.7

To know more about the stability and features of a certain kernel version visit http://kernelnewbies.org  http://www.h-online.com and http://www.phoronix.com

Decide on the stable version based on your requirements and stability

Step 2: Install kernel build dependencies in debian/ubuntu

sudo apt-get install kernel-package libncurses5 libncurses5-dev


If you are a debian user, become root and use apt-get/aptitude directly to install kernel-package and libncurses5. After installing become normal user and follow steps below

Step 3:  Extract the source code

Unzip/untar the zip file of the kernel source code. Now enter into the directory of the extracted source code.

Step 4: Prepare config for kernel compilation

Step 4.1: make clean && make mrproper
Step 4.2: make menuconfig


This will open the kernel configuration, change/hack settings to your hearts content. By default make menuconfig copies your currently running kernel configuration. If you want a different configuration, copy that to .config file before launching make menuconfig. If you want to start fresh, use make defconfig before calling make menuconfig

Step 5: Make the kernel deb files after cleaning

Step 5.1: make-kpkg clean

Step 5.2:  do a build, based on your processor power, this will take some time. For example, my system compiles within 15 minutes since it is a quad core with hyperthreading. use CONCURRENCY_LEVEL=n, where n is the processor count

Core 2 duo/dual core processor owners
CONCURRENCY_LEVEL=2 fakeroot make-kpkg  --initrd --append-to-version=-shortdescription kernel_image kernel_headers


Quad core processor owners

CONCURRENCY_LEVEL=4 fakeroot make-kpkg  --initrd --append-to-version=-shortdescription kernel_image kernel_headers

Quad core with hyperthreading
CONCURRENCY_LEVEL=8 fakeroot make-kpkg  --initrd --append-to-version=-shortdescription kernel_image kernel_headers

Hexa core
CONCURRENCY_LEVEL=6 fakeroot make-kpkg  --initrd --append-to-version=-shortdescription kernel_image kernel_headers

Hexa core with hyperthreading
CONCURRENCY_LEVEL=12 fakeroot make-kpkg  --initrd --append-to-version=-shortdescription kernel_image kernel_headers

Once the compilation, linking is complete proceed to next step



Step 6: Install the debian packages

Change to previous directory, where the kernel packages are built as debian binary. There should be a header and a image deb file. Just use the following command to install the deb

cd .. && sudo dpkg -i *.deb


Step 7: Create a initrd

sudo update-initramfs -c -k <kernel version>

for e.g since I compiled 2.6.34.7, I used 

sudo update-initramfs -c -k 2.6.34.7

Now after this step, update your grub

Step 8: Update grub with new initrd

sudo update-grub

Step 9: Reboot

sudo reboot

Step 10: Enjoy!!

3 comments:

  1. To test 2.6.37.4 optimized for core2, follow this link

    To test 2.6.38 optimized for core2, follow this link

    ReplyDelete
  2. DOH! ;-D Never mind I found the Timer Freq in the config file. Still not sure if I should keep it at 300 or go up to 1000. ?

    ReplyDelete