How to compile a new Ubuntu 11.04 (Natty) kernel

Ubuntu 11.04 was released a while back and I’ve been getting questions about compiling your own kernel for Ubuntu 11.04. I’ve just been busy with other projects but as I have been writing articles on “How to compile a kernel for Ubuntu …” for a few releases and there is no exception for Ubuntu 11.04.


I’ll be using git to get the latest kernel version. This is my favorite way to get the sources and it is in my opinion the fastest way to make changes later on when you want to update your own kernel to the latest version.
I suggest adding my Launchpad repository to your system. The repository holds the latest version of git and is usually updated within a day of a new release of git, follow the instructions on the page Git Packages for Ubuntu to add my repository.

I am compiling the amd64 which basically is the version used for all 64 bit versions, if you want to compile for i386 you need replace amd64 for i386 throughout this article.

I choose the name i7 as the flavor name as for my personal use I’ll build a kernel for a i7 processor. Besides the change of processor type in the configuration I also have some other changes but that’s beyond this article.


Let’s get started by preparing our machine for compiling the Ubuntu 11.04 kernel.
Open a terminal.

sudo su -
apt-get install fakeroot build-essential
apt-get install crash kexec-tools makedumpfile kernel-wedge
apt-get build-dep linux-image-$(uname -r)
apt-get install git libncurses5 libncurses5-dev libnewt-dev

Create a directory where you would like to build your kernel, this directory will hold the kernel source in a sub directory and all the deb files will end up in this folder. I choose /d1/development/kernel/ubuntu/natty

Getting the source

cd /d1/development/kernel/ubuntu/natty
git clone git://  source
cd source

The source code is installed in the directory source.

Creating a branch
We will create a branch in which we will be doing our modifications. That way the master branch will stay in tact which will make it a whole lot easier when we want to update our own Ubuntu 11.04 kernel to a newer version.

To see all the available kernels available type the following command:

git tag|grep Ubu|sort -V

The Ubuntu kernel developers tag each version as Ubuntu- and therefore we can checkout the version we want as

git checkout Ubuntu-2.6.38-11.48 -b i7

This will create a branch called i7.

Creating a new config

I’ll be using the method of creating a new flavor, this adds a bit more work but this way you can always compile the original kernels.

We’ll use the generic flavor as the base for our own flavor being i7, as discovered by one of the readers of this blog, this extension needs to be in small caps.

cp debian.master/config/amd64/config.flavour.generic debian.master/config/amd64/config.flavour.i7
fakeroot debian/rules clean
debian/rules updateconfigs

To make changes to the configuration file we need to edit the configuration file. The kernel developers have created a script to edit kernel configurations which has to be called through the debian/rules makefile, unfortunately you will have to go through all the flavors for this script to work properly.

debian/rules editconfigs

The script will ask you if you want to edit the particular configuration. You should not make changes to any of the configurations until you see the i7 configuration

Do you want to edit config: amd64/config.flavour.i7? [Y/n]

Make your changes, save the configuration and then keep going until the script ends.

When you’re done, make a backup of the config flavor file.

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

Now we need to clean up the git tree in order to get ready for compilation.

git reset --hard
git clean -xdf

Getting ready for compilation

Because we are going to be creating a new flavor based on a existing flavor (generic in my case) we need to create some extra files. During compilation the process checks the previous release for some settings, as we’re creating a local flavor it doesn’t exist in the source, so we’re creating it. The previous release in this case is 2.6.38-8.42

ls debian.master/abi
cp debian.master/abi/2.6.38-8.42/amd64/generic debian.master/abi/2.6.38-8.42/amd64/i7
cp debian.master/abi/2.6.38-8.42/amd64/generic.modules debian.master/abi/2.6.38-8.42/amd64/i7.modules

Copy our flavored configuration file back.

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

We need to edit some files:

File: debian.master/etc/getabis

Search for the line:

getall amd64 generic server virtual

Change it in:

getall amd64 generic server virtual i7

File: debian.master/rules.d/

Search for the line:

flavours        = generic server virtual

Change it in:

flavours        = generic server virtual i7

We need to make the compilation process aware of our own flavor we want to compile.

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

You can edit the file and make it your own.

arch="i386 amd64"
supported="i7 Processor"
target="Geared toward i7 desktop systems."
bootloader="grub-pc | grub-efi-amd64 | grub-efi-ia32 | grub | lilo (>= 19.1)"
provides="kvm-api-4, redhat-cluster-modules, ivtv-modules, ndiswrapper-modules-1.9"

We need to commit our changes in the git repository.

git add .
git commit -a -m "i7 Modifications"

The text after -m is the message you add to your commit.


It’s finally time for compiling but before we can start the compilation process there is one more step to do. I didn’t put this in the Preparations section as you need to do the following step whether you make changes to the configuration or not

fakeroot debian/rules clean

All the packages will be created in the directory /d1/development/kernel/ubuntu/natty
Create independent packages:

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

The above statement will create the following deb files:


Create the tools package:

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

The above statement will create the following deb file:


Create the flavour depended files:

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

The above statement will create the following deb files:



After the compilation is finished we’ll have the above packages in the parent directory.

To install the files

cd ..
sudo dpkg -i linux-headers-2.6.38-11-i7_2.6.38-11.48_amd64.deb linux-headers-2.6.38-11_2.6.38-11.48_all.deb linux-image-2.6.38-11-i7_2.6.38-11.48_amd64.deb

Check your bootloader if the newly installed Ubuntu 11.04 kernel is the default one, for grub check the file /boot/grub/menu.lst or if you run grub2 check /boot/grub/grub.cfg

Reboot and enjoy your newly installed Ubuntu 11.04 kernel.

This article is filed under the categories Ubuntu » Compile a kernel and has the following tags associated with it: , , .

For more of the same articles see the page Compile a kernel for Ubuntu overview
  • Most likely you don’t need to compile the kernel, as you can download all new kernel releases provided by Ubuntu:

    • Most people don’t have to compile their own kernel unless they want/need to modify the kernel configuration or just want to learn how to compile one. The kernel supplied by Ubuntu through their repository works fine for most people and their computers.

      I compile my kernel for my processor and I change the options in the configuration to my liking.

  • Suppose I want to experiment with the kernel… Which options do you consider worth changing? I mean, easy changes that make an impact on the whole system and that could be measured later (things like quantums, network tunning, memory usage, etc…).

    Ps: Great article, very clear and straightforward

    • With just the options I don’t think you will see big impacting measurable changes. Changing the processor type to the type you run instead of general x84_64, if you run i386 and have 4GB of memory or more you need to change that option, these are good changes but will you notice a difference, I’m not really sure (the memory in i386 is something you will notice of course).

  • I run Fluxbox and still use a dockapp to control audio rolling the scroll wheel up or down while over the wmix applet. Starting in 10.04 Ubuntu dropped the OSS compatibility layer from ALSA. Thus /dev/mixer is no longer available. aoss and padsp do not help. I have several choices, I can give up on wmix, I can rewrite it to use ALSA or PulseAudio (time consuming) or I can re-enable ALSA OSS and recompile the kernel.

    Very often new or improved wifi drivers or webcam drivers are only available via kernel patches and custom kernel builds.

  • stumped2

    Would it still work to add DEB_BUILD_OPTIONS=parallel= to take advantage of multicore compiling?

    • Rich

      I’ve been putting CONCURRENCY_LEVEL=N into the environment where N is the number of cores available.

      • If you run:
        fakeroot debian/rules clean
        debian/rule printenv

        You will see if the CONCURRENCY_LEVEL is automatically set to the correct number.

        Same for the DEB_BUILD_OPITIONS as this is translated to CONCURRENCY_LEVEL during the building process.

  • Max

    The extension should also not have any underscores, or you may get an illegal package name error.

  • I’ve done all the steps to “skipabi=true skipmodule=true fakeroot debian/rules binary-i7”

    When I run that command I got this message.
    root@MyUbuntu: /usr/src/GengOS/source# skipabi=true skipmodule=true fakeroot debian/rules binary-i7
    make: *** No rule to make target `binary-i7′. Stop.

    What should I do next?

    and when I ran the previous command “skipabi=true skipmodule=true fakeroot debian/rules binary-perarch”
    the file I got was “linux-tools-2.6.38-11_2.6.38-11.48_i386.deb”
    not “linux-tools-2.6.38-11_2.6.38-11.48_amd64.deb”


    • Sounds like a typo or missed step. Check the section Getting ready for compilation and where you edit the files:

      • James

        I have the EXACT same issue as GenG…

        “make: *** No rule to make target `binary-i7′. Stop.”

        and got the “_i386.deb” instead of “_amd64.deb”

        I double-checked the debian.master/etc/getabis and debian.master/rules.d/ files, and have edited them correctly per your specs…

        Any other suggestions? I need to get this figured out! =P

        Thanks in advance!

        • Bob

          Remember where he says:

          When you’re done, make a backup of the config flavor file.

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

          and then later you copy it back?
          Copy our flavored configuration file back.

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

          I forgot to copy it back and got the result you got. Then I copied it back and got the compilation I expected.

  • jewfromdahood

    I changed my name for the kernel, but I did that for all prior versions of your tutorial. So it’s not i7 it is “kosher” as I removed all the pork.

    make[4]: *** Waiting for unfinished jobs….
    CC arch/x86/boot/tty.o
    CC arch/x86/boot/video.o
    CC arch/x86/boot/video-mode.o
    CC arch/x86/boot/version.o
    CC arch/x86/boot/video-vga.o
    CC arch/x86/boot/video-vesa.o
    CC arch/x86/boot/video-bios.o
    make[3]: *** [arch/x86/boot/compressed/vmlinux] Error 2
    make[3]: *** Waiting for unfinished jobs….
    make[2]: *** [bzImage] Error 2
    make[1]: *** [sub-make] Error 2
    make[1]: Leaving directory `/home/administrator/source/11.04/2.6.38-11.50/source’
    make: *** [/home/administrator/source/11.04/2.6.38-11.50/source/debian/stamps/stamp-build-kosher] Error 2

    stumped what do I do?

  • Fredrik_Swe

    Thx for a great article!

    I followed every step and I compiled a kernel which I presently run. However, I would like to experiment a bit further with some configurations. How do I keep as many as possible of the compiled files and only recompile the ones changed?

    I have compiled a lot of kernels before (slackware, redhat, debian) but
    I have never used git or branches before and I don’t fully understand the input and output of the editconfigs script. Where can I read more about it?

    Thx again.

  • Jonathan Lundquist

    Great article, helped me get a working kernel with patches for iscsi-scst. Only problem is, apt-get upgrade wants to replace linux-headers-3.0.0.-12 etc. Any suggestions how to let it know this build is newer? THANKS.

  • Rich

    Thanks for these.

  • Rich

    There’s a problem here, (and in the oneiric instructions as well).

    The “git add .” instruction adds debian.master/control.stub. This is problematic. While the current working directory may continue to build successively, clones of this git repository will fail with “package linux-image-2.6.38-12-i7 is not in control info”.

    Debian/control is apparently built during “debian/rules clean”. In these instructions, that happens before the new flavour is added. Debian/control won’t be rebuilt if none of the input files have changed. In the original working directory, the input files appear to have been changed but in clones, copies, etc, they don’t. And since they apparently haven’t been changed, the control file doesn’t get rebuilt, and the new flavours aren’t recognized.

    I think you need a more specific “git add” command which omits at least this generated file, (and possibly others).

    • I just ran through all the steps again and I don’t see the control.stub being added.

      You are correct it’s made after the debian/rules/clean but everything that’s created in Creating a new config section is erased by the steps:
      git reset --hard
      git clean -xdf

      What I didn’t add in these articles are those steps at the end of the compilation. If you want to clone the branch you have to clean up your branch after each compilation by using the steps above, or maybe a better solution is to create a working branch to do the compilation in :
      git branch -b work
      as the 1st step in the Compilation section.
      After you are done with the compilation you can checkout the i7 branch and erase the work branch
      git checkout i7
      git branch -D work

      • Rich

        Bah, sorry. You’re right.

        I’m putting the whole mess into subversion. If I do the git clean, then the subversion .svn directories get removed so I have to skip that step or the exercise is useless for me.

  • C.


    I am recompiling the kernel to try to get the ost out of it when we run computationally intensive statistical models. I was wondering whether there is a way of connecting the output of cpuid to the kernel config.

    Also, I would like to compile the kernel (and any other package) with the option -march=native and for the right number of cores (e.g through CONCURRENCY_LEVEL=N). Where is the best configuration file to put this options, so that we have to write them only once and they are used for compiling all the files in the kernel (and possibly also all the other packages as well).


    • For the -march=native you have to edit the Makefile in /d1/development/kernel/ubuntu/natty/source

      Around line 245 you can find the hostcc and you can add -march=native

      The CONCURRENCY_LEVEL is determined automatically, no need to set that. To check run:
      debian/rules clean
      debian/rules printenv

      Not sure what you mean with connecting the output of cpuid to the kernel config. You mean automatically set the proper CPU in the kernel config based on the cpuid output? If so you would have to write a script that takes that info and determines what needs to be changed in the kernel configuration files. Not an easy task but it can be done of course.

      • C.

        Thanks a lot Pete, you are very helpful. I forgot to thank you for the article as well. I did the usual googling, and yours was the best by far.

        1) Concerning –march=native, is it enough to change the hostcc in that file to cascade on the compilation of all the modules and parts of the kernel?

        2) If I wanted to use another compiler rather than gcc, e.g. the intel compiler or path64, is it enough to modify that same hostcc?

        3)Cpuid: I think you are right, I need to clarify. I would like to connect the output of cpuid (or /proc/cpuinfo) to the kernel config, in such a way that we set all of the options for compiling the kernel specifically for that CPU.

        4) I would also like to connect the output of lspci to kernel config in the same way, so that we compile the kernel with optimised for that specific machine make up: chipset, controller, graphic card, sound card and so on …

        The aim is to optimize the machine for running large computationally intensive statistical models, written in R, Octave, Python with Numpy. Do you think it will make a difference? Would you use -O3 together with –march=native or not? Any other optimization you would consider (e.g. low latency, blah blah)?

        Thanks a lot.

        • Concerning 1 and 2 the answer would be yes. That’s the only place you would have to change it.

          It would require some sort of script and darn good knowledge of the kernel configuration file and hardware to do this. Impossible, no, can I do it, no sorry.

          I would use -O3 and -march=native together, march checks for things like SSE, -O3 uses different optimization.
          I’m pretty sure setting these will make a difference in your case. Low latency sounds like that would make send as well, I’ve never worked in an environment like you are setting up, so I can’t really say what other settings would be beneficial.
          Most likely you should also optimize your filesystem, memory etc but that’s beyond the scope of this article.

  • C.

    Thanks a lot Peter!

    It makes a very interesting project for one of our students, I hope.

  • C.

    Thanks a lot Peter.

    PS: If you want to deep clean the directory after compilation (like make clean), but would like to keep all the configuration files you have created, how do you do it?

    • To get back to the situation before the compilation process started type:

      git reset --hard
      git clean -xdf

  • C.

    Thanks it worked well.

    Is it possible to force the compiler to use more than one core to compile, or more than one processor, in order to accelerate compilation?

  • Rasoul

    I have followed all the steps without facing any problem, but at the end when I checked the /boot/grub/grub.cfg file, there was no i7 menu!? I restarted the computer, but nothing changed in the boot menu neither. I have portioned my disk for ubuntu to have /boot, /, swap space, and /home in different partitions. Does it effect the above process?

    • Peter

      Partitioning doesn’t effect the boot loader.
      Do you run Grub, Grub2?
      Did you see any errors during the installation of the new kernel?
      Is the kernel present in the /boot directory?

      • Rasoul

        Hi Peter, I went through all the process again and this time I found out a difference in the boot menu; i7 kernel was created under “Previous Linux versions”!

        • Peter

          What is the version of the default kernel and what version are you trying to compile? It sounds like you are compiling an older version as what you have running currently.

          • Rasoul

            The default version of the kernel is “2.6.38-13-generic”. The i7 kernel was created under “Previous Linux versions” as “2.6.38-11-i7”.

          • Peter

            So it makes sense the kernel you compiled is under Previous Linux versions. 2.6.38-13 is a newer kernel as the one you compiled, 2.6.38-11

          • Rasoul

            I would like to make some changes to the usb driver and recompile the kernel as PowerUSB. Unfortunately, making any change to the C files in drivers/usb/host/ will be back to the original. How can I prevent this issue?

  • vishalyadav1313

    sir i am an student and have latestly accquired an tab that runs an android 2.3 an want to get linux to run over it how can i wipe clean androide 2.3 and modify the kernel to run on that hardware pls guide me where can i start from

  • TK

    Unfortunately, “apt-get build-dep linux-image-$(uname -r)” fails for me with “E: Unable to find a source package for linux-meta.”

    • Peter

      Make sure you enabled Sources in the Software Sources. What’s the output of uname -r ?

  • ramana

    I have some doubt, this ubuntu and kernel building process is only for amd,x86 processors are it can be for Pandaboard also? I was doing project on pandaboard, to installing ubuntu-11.04 on pandaboard(OMAP4430). The above process is supported for the OMAP4430 Processor?

    • Peter

      I don’t know much about cross compiling for omap but here’s something that might help you out.
      Before the section Creating a branch you need to do the following:
      git checkout ti-omap4

      This branch seems to be for the omap4 processor. Now I don’t know what the remaining steps are, I’m pretty sure the directories are different, there is for example a debian.ti-omap4 directory.
      You can find a bit more info on this page:

      Hope it helps, good luck.

  • shluvme

    Hey, I want to update the DSDT file of my kernel so that power management would work properly. I’ve generated a fixed dsts file with the correct settings that suite my processor but I’m not sure how to “recompile” the kernel. BTW I’m currently running 2.6.39-020639rc4-generic.
    Should I follow this tutorial or is there a “shorter” way ?
    thanks in advance !!

  • Hi have compiled Ubuntu successfully for panda board , but need to change boot
    logo. So i changed /kernel path/driver/video/logo/logo_Linux_clut224.ppm image to my custom logo image. clean and compile kernel, but there is no change in dual
    penguin logo.

    what can i do to change this logo.

  • Eviatar

    I’m getting:
    check-config: FAIL: !exists CONFIG_DEBUG_RODATA | value CONFIG_DEBUG_RODATA y

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

    Have any idea?