Home page of this blog

Monday, October 4, 2010

Ubuntu Maverick 64bit Kernel Compilation


After installing Ubuntu Maveric release candidate, I tried to play some movies. The movies were getting stuck. I tried to open windows and alt-tab windows. Everything seems to get stuck!

Why? The reason I believe lies in the way Ubuntu 64 bit kernel is built. 64 bit ubuntu kernel timer frequency is just 100 HZ

100 HZ is excellent for running inside cloud or virutalized environments, but 100 HZ  is unsuitable for desktop activity or games. Graphics drivers demand a very high timer frequency eventhough kernel has moved on to tickless. Nvidia proprietary kernel module requires 1000 HZ to play games or render graphics without a lag (this is based on my observation of how the movies lag though I have a very powerful processor i7 and a very powerful graphics card nvidia gtx 460).

So I wanted to get a kernel which has 1000 HZ kernel frequency. I did not find one and I am doing compilation myself.

I found the following blog extremely useful for kernel compilation


Unfortunately, the article is using git and I don’t have patience to download 700+ MB of git content and package content just to compile a 88 MB kernel.  The answer to this comes from the same blog which explains kernel compilation without using git, but written for ubuntu intrepid which is nearly 2 years back


The current method I used, fuses both the methods and compiles without using git.

Here is a how to of kernel compilation which I did exactly without using git for compiling. This may help someone with a similar problem, hence this document

This article only tells how to compile 64bit kernel and does not bother to explain 32 bit kernel compilation.

Step 1: Install all dependencies to compile kernel

The following command will install all the dependent packages needed for compiling a linux 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

Install the following separately (this avoids pulling all recommended packages, which are huge)

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

Ensure none of the dependent packages are missing by running the following command.

sudo apt-get build-dep linux

Step 2: Get the kernel source code

Create a directory called Builds and change into the created directory. This will make the task of handling the kernel builds pretty easy.

mkdir Builds
cd Builds

The following command helps the kernel source to be fetched and extracted in the current directory. In this case this is Builds directory. See that the command is executed as a normal user only (without sudo prefix)

apt-get source linux-image-$(uname -r)

Step 3: Create a copy before compiling

cp linux-2.6.35 linux -r

Always use the copy instead of the original source directory. In case there is an error and not recoverable, delete the directory linux and recreate it using above command.

Step 4: Create a new config

Change into the copied linux directory.

cd linux

Copy the generic flavour of the kernel and give the name of your processor for the new flavour. See that I am giving i7

cp debian.master/config/amd64/config.flavour.generic debian.master/config/amd64/config.flavour.i7

fakeroot debian/rules clean

Change the scripts permissions to make them executable

chmod -Rv +x debian/scripts/

fakeroot debian/rules updateconfigs

The following will bring up the kernel configuration screen for whichever configuration we give Y to edit. In this case I gave Y to config.flavour.i7

fakeroot debian/rules editconfigs

The following are the important configuration changes I made

  • Changed
    • Processor type and features --> Timer frequency --> 1000 HZ
    • Processor type and features --> Processor family --> Core 2/newer Xeon
  • Unticked(deselected)
    • Processor type and features --> Support for extended (non-PC) x86 platforms
    • Device drivers --> Staging drivers --> Nouveau (nVidia) cards

Step 5: Changing abi files before compilation

Copy the generic abi for the custom flavour. In this case it is as follows

cp debian.master/abi/2.6.35-22.34/amd64/generic debian.master/abi/2.6.35-22.34/amd64/i7
cp debian.master/abi/2.6.35-22.34/amd64/generic.modules debian.master/abi/2.6.35-22.34/amd64/i7.modules

Add i7 (or whatever flavour name we gave) to the getabis file under debian.master/etc/

sed -i s/getall\ amd64\ generic\ server\ virtual/getall\ amd64\ generic\ server\ virtual\ i7/g debian.master/etc/getabis

Add i7 (or whatever flavour name we gave) to amd64.mk file under debian.master/rules.d/

sed -i s/\=\ generic\ server\ virtual/\=\ generic\ server\ virtual\ i7/g debian.master/rules.d/amd64.mk

Make compiler aware of the flavour. change i7 to the flavour name we gave

cp debian.master/control.d/vars.generic debian.master/control.d/vars.i7

Edit the supported processor name in the above file. For e.g I changed to Core i7 from Generic

sed -i s/\"Generic\"/\"core\ i7\"/g debian.master/control.d/vars.i7

Step 6: Kernel Compilation

Since I wanted to optimize for core2 microarchitecture, I edited the following two files


In the file arch/x86/Makefile I made the following change

        cflags-$(CONFIG_MCORE2) += \
                $(call cc-option,-march=core2,$(call cc-option,-mtune=core2))

See the bolded mtune=core2, it was generic and I changed to core2

In the file arch/x86/Makefile_32.cpu I made the following change

cflags-$(CONFIG_MCORE2) += -march=core2 $(call tune,core2)

See the bolded march=core2, it was i686 and I changed to core2

Here is how I compiled for my flavour i7

Clean before building

fakeroot debian/rules clean

Independent package build

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

Flavoured build

Build now, change CONCURRENCY_LEVEL=4 for quad cores and CONCURRENCY_LEVEL=2 for dual cores

CONCURRENCY_LEVEL=8 skipabi=true skipmodule=true fakeroot debian/rules binary-i7

Step 7: Installing newly built kernel

Change to previous directory, where all the build output as .deb files are created

cd ..

For e.g

sudo dpkg -i linux-headers-2.6.35-22-i7_2.6.35-22.35_amd64.deb linux-image-2.6.35-22-i7_2.6.35-22.35_amd64.deb

This will install all dkms modules which are already installed ( including nvidia proprietary driver if already installed from additional drivers)

restart (there should be a red colored power button in the top right corner of ubuntu, indicating that a restart is in due)



  1. Hi ,

    I need to change my KERNEL TIMER Frequency but my system is 32 bit linux i686/gnu linux 2.6.31-22.

    How can i update the kernel timer frequency to 1000 Hz on my 32 bit system.

    Regards ,


  2. What version of ubuntu do you use, I think 2.6.31 is Ubuntu 9.10 (Karmic)

    Follow this link (that blog is excellent and I compile kernel following that blog)


  3. Thanks! Works for me.

    For an Atom CPU in a 32-bit environment, modify the lines below as follows:

    cp debian.master/config/i386/config.flavour.generic debian.master/config/i386/config.flavour.atom

    cp debian.master/abi/2.6.35-22.32/i386/generic debian.master/abi/2.6.35-22.32/i386/atom

    cp debian.master/abi/2.6.35-22.32/i386/generic.modules debian.master/abi/2.6.35-22.32/i386/atom.modules

    sed -i s/getall\ i386\ generic\ generic-pae\ virtual/getall\ i386\ generic\ generic-pae\ virtual\ atom/g debian.master/etc/getabis

    sed -i s/\=\ generic\ generic-pae\ virtual/\=\ generic\ generic-pae\ virtual\ atom/g debian.master/

    cp debian.master/control.d/vars.generic debian.master/control.d/vars.atom
    sed -i s/\"Generic\"/\"Atom\"/g debian.master/control.d/vars.atom

    I have gcc 4.4 and optimizations for atom appear in 4.5, so I didn't modify the compilation flags.

    CONCURRENCY_LEVEL=2 skipabi=true skipmodule=true fakeroot debian/rules binary-atom

    I'm used to building a kernel in 15 minutes or so; this one took more than three hours! I could have removed a lot of unused drivers to speed it up.

    Bogomips and glxgears appear to be unchanged with the custom kernel.

  4. Very useful howto. Easy to understand, it worked very well.

  5. Could you please post a comparison of the performance results?

    Thank you!

  6. Forget about 0.xxx percent speed increase.

    Won't it be excellent if this Dirndl thing is released really today, I am excited to see it coming to life ...

    See more


  7. http://www.howtogeek.com/howto/ubuntu/how-to-customize-your-ubuntu-kernel/

    I'd like to recommend this alternative article for the Ubuntu, as it seems to be an easier to understand articles for those new to compiling your own custom kernel. I followed that article last night and I am now running on my own custom custom kernel with no issues. I had compiled with 1000Hz kernel and a few disabled features that I don't need or use.

  8. what is content of sources.list, it needs to complete from step:1 @ sudo apt-get build-dep linux


  9. goto synaptic package manager and enable software sources, you don't need to do it manually