Home page of this blog

Wednesday, October 26, 2011

Custom 64 bit Ubuntu Kernel 3.1 optimized for i3, i5 and i7


Kernel 3.1

I built the 64bit kernel 3.1 for my Kubuntu 11.10 desktop optimized for i7. Here is the screenshot of the kernel in action


Feel of the new kernel 3.1 seems to be very exciting. Kubuntu booted to login screen within 10 seconds. (With default kernel it took more than 20 seconds to boot Kubuntu 11.10 unlike ubuntu 11.10 which was faster to boot)

Here is how I built the kernel 3.1 Ubuntu way (in short 7 steps)

In brief
  1. Install build dependencies
  2. Download kernel source and ubuntu patches
  3. Extract and apply ubuntu patches
  4. Create a new flavour and tweak kernel config
  5. Modify Makefile for optimization
  6. Build
  7. Reboot and Enjoy

In detail

Install build dependencies

Open terminal/konsole and execute the following apt-get commands if you don't have essential build packages necessary for building kernel from source in Ubuntu


#Install Build essential to build kernel

sudo apt-get install fakeroot build-essential crash kexec-tools makedumpfile kernel-wedge libncurses5 binutils-dev libelf-dev libdw-dev libnewt-dev libncurses5-dev



sudo apt-get  --no-install-recommends install asciidoc xmlto

Download kernel source and ubuntu patches

Download the source of newly released linux kernel 3.1. The following wget -c makes it simple to download from commandline


#Download kernel source



wget -c http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.1.tar.bz2


Here is how to download the 3.1 ubuntu patches

#Download ubuntu patches
wget -c http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.1-oneiric/0001-base-packaging.patch
wget -c http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.1-oneiric/0002-debian-changelog.patch
wget -c http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.1-oneiric/0003-default-configs.patch


Extract and apply ubuntu patches

Extract downloaded kernel source and apply patches. Here I used tar to unzip the bzip tarball and patch to apply the patch


#Extract kernel source



tar xjvf linux-3.1.tar.bz2


#Create a soft link 

ln -s linux-3.1 linux


#Enter linux directory

cd linux

#Apply the patches

patch -p1 < ../0001-base-packaging.patch 
patch -p1 < ../0002-debian-changelog.patch 
patch -p1 < ../0003-default-configs.patch


Create a new flavour and tweak kernel config

Before creating a new flavor, give execute permissions to debian build scripts for building the kernel properly


#make debian/rules as executable

chmod -Rv +x debian/rules

#make debian/scripts directory executable

chmod -Rv +x debian/scripts/

To create a new flavour, just clone from generic flavor, here is how

#create i7 flavor
cp debian.master/config/amd64/config.flavour.generic debian.master/config/amd64/config.flavour.i7

Do the kernel configuration, I selected processor type as CORE2 and kernel frequency to 1000HZ (just give y only to the newly created flavor when executing editconfigs)


#clean
fakeroot debian/rules clean
fakeroot debian/rules updateconfigs
#give y only to i7 flavor, leave the rest untouched
fakeroot debian/rules editconfigs

Copy the abi related files from existing generic flavor and tweak to reflect the newly created flavor

#copy the abi entries for i7 flavor and add i7 entries in vars and amd64.mk
cp debian.master/abi/3.0.0-12.20/amd64/generic debian.master/abi/3.0.0-12.20/amd64/i7
cp debian.master/abi/3.0.0-12.20/amd64/generic.modules debian.master/abi/3.0.0-12.20/amd64/i7.modules
sed -i s/getall\ amd64\ generic\ server\ virtual/getall\ amd64\ generic\ server\ virtual\ i7/g debian.master/etc/getabis
sed -i s/\=\ generic\ server\ virtual/\=\ generic\ server\ virtual\ i7/g debian.master/rules.d/amd64.mk
cp debian.master/control.d/vars.generic debian.master/control.d/vars.i7
sed -i s/\"Generic\"/\"core\ i7\"/g debian.master/control.d/vars.i7



Modify Makefile for optimization

This is the place where we apply the optimizations. Ubuntu 11.10 comes with gcc 4.6 which has added new architectue corei7


#edit arch/x86/Makefile and arch/x86/Makefile_32.cpu if you want to tweak the march and mtune params of gcc

vi Makefile

vi arch/x86/Makefile

vi arch/x86/Makefile_32.cpu

In the main makefile, I changed HOSTCC and HOSTCXX to look as follows


HOSTCC       = gcc -march=corei7 -mtune=corei7 -pipe

HOSTCXX      = g++ -march=corei7 -mtune=corei7 -pipe



In other makefiles, replace lowercased core2 with corei7 (simple isn't it?)

Build

Do a clean build


#clean and build

fakeroot debian/rules clean



The following builds the common header and source debs

skipabi=true skipmodule=true fakeroot debian/rules binary-indep

The following builds the newly created flavor. Note I added no_dumpfile=yes as it was not building the dumpfile.

time skipabi=true skipmodule=true no_dumpfile=yes fakeroot debian/rules binary-i7

Wait for sometime (depends on speed of your processor). No need to tweak concurrency settings, which are taken care automatically. Install the newly built debs as follows after going one directory above

cd ..

sudo dpkg -i linux-headers-3.1.0-030100_3.1.0-030100.201110241006_all.deb linux-headers-3.1.0-030100-i7_3.1.0-030100.201110241006_amd64.deb linux-image-3.1.0-030100-i7_3.1.0-030100.201110241006_amd64.deb

Reboot and Enjoy

To test the newly built kernel, reboot and select the newly installed kernel from grub. If the newly installed kernel does not boot for some reason, do not panic, select the old ubuntu kernel and boot. (Grub2 does not wait beyond 3 seconds if there is no other OS present and very annoying, press escape within first 3 seconds to display the grub menu if it does not display) Follow this to know more about how to customize grub2 http://maketecheasier.com/mastering-grub-2-the-easy-way/2009/11/19

or

https://wiki.ubuntu.com/Grub2

sudo reboot

Download links

I have uploaded the kernel 3.1 debs which I built and use.  If you don't want to build yourself you can try these.

Here are the SHA256SUM checksum


8d1c58d614056b3cb2e05562d1108cd0a25aa7900ea02f602e8da7a6ead00c83  buildscript.sh

3cbd100b33734330f6b4da7a25cce5c0a45db9cee16bf609c554cbc9cd7b3f98  linux-headers-3.1.0-030100_3.1.0-030100.201110241006_all.deb

6ad9338017182590ef791ed12bbcaf0857090fb6028ec90b6d81ea04c38948f5  linux-headers-3.1.0-030100-i7_3.1.0-030100.201110241006_amd64.deb

e1d62da1add7bfc0b9976fac7d8be32512da8eb09c5b41a6ab66b8c43d12b52e  linux-image-3.1.0-030100-i7_3.1.0-030100.201110241006_amd64.deb

Here are the download links



11 comments:

  1. And of course don't forget to run "sudo update-grub" before rebooting. It will save you some valuable time I just found out ;)

    ReplyDelete
  2. Great blog! I have an i3-380m processor running linux mint debian, are there any changes that I need to perform to the above to install the 3.1 custom kernel. At present I use the 2.6.32-5 kernel it's stable but slow.

    ReplyDelete
  3. You need to call sudo update-grub after calling sudo update-initramfs

    ReplyDelete
  4. you could give this kernel a try, this maybe fast, but debian's kernel, well there is no match for anything coming out from debian they are solid, strong and fast

    ReplyDelete
  5. Main advantage I see in this kernel 3.1 (or 2.6.33 and above) over 2.6.32 is TRIM is enabled for SSD. Autogroup scheduling is another big feature. No big Kernel lock in latest kernels. Lots and lots of such advantages.

    ReplyDelete
  6. Thanks for the tech advice, i'll give the 3.1 custom a try!

    ReplyDelete
  7. Having hard time follow how u do kernel build.

    Just wishing/wanting simple step by step process how it done .

    using Debian 6.03 amd64 with Core2dual cpu

    ReplyDelete
  8. can show how compile also kde 4.7.3 for i7?

    ReplyDelete
  9. I will give it a try though i doesnt seem that simple...

    ReplyDelete
  10. thanks for kernel linux install guides in my ubuntu.

    ReplyDelete