How to compile a new Ubuntu 11.10 (Oneiric) kernel

As Ubuntu 11.10 was released it’s time for another article in my “How to compile a kernel for Ubuntu …” series. This article will show you how to get the latest kernel from the Ubuntu kernel maintainers for Ubuntu 11.10 and create a kernel which you can modify to make it more suited for your computer.

Introduction

git
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.

Architecture
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.

Flavor
I choose the name i7 as the flavor name as I’ll be building a kernel geared towards my laptop which has a i7 processor. Besides the change of processor type in the configuration I also have some other changes but that’s beyond this article.

Preparations

Let’s get started by preparing our machine for compiling the Ubuntu 11.10 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
exit

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/oneiric

Getting the source

cd /d1/development/kernel/ubuntu/oneiric
git clone git://kernel.ubuntu.com/ubuntu/ubuntu-oneiric.git  source
cd source

The source code of the kernel 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 custom build Ubuntu 11.10 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-3.0.0-13.21 -b i7

This will create a branch called i7.
Don’t select kernels like Ubuntu-3.0.0-1200.1, where the number after the second dash is in the thousands. These are specialized kernels and they may not work on your specific machine.

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 -df

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.

To see the previous release we use:

ls debian.master/abi

The previous release in this case is 3.0.0-12.20

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

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/amd64.mk

Search for the line:

flavours        = generic server virtual

Change it in:

flavours        = generic server virtual i7

File: debian.master/control.d/vars.i7

This files does not exist and in order to make the compilation process aware of our own flavor we want to compile we need to create it.

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."
desc="x86/x86_64"
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.

Compilation

It’s finally time for compiling, to keep our newly created branch in pristine condition we will do the compilation in a separate branch. We keep our branch clean as this will help later on when we want to update our new branch to a newer kernel.

git checkout -b work
fakeroot debian/rules clean

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

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

The above statement will create the following deb files:

linux-doc_3.0.0-13.21_all.deb
linux-headers-3.0.0-13_3.0.0-13.21_all.deb
linux-source-3.0.0_3.0.0-13.21_all.deb
linux-tools-common_3.0.0-13.21_all.deb 

Create the tools package:

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

The above statement will create the following deb file:

linux-tools-3.0.0-13_3.0.0-13.21_amd64.deb

Create the flavour depended files:

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

The above statement will create the following deb files:

linux-headers-3.0.0-13-i7_3.0.0-13.21_amd64.deb
linux-image-3.0.0-13-i7_3.0.0-13.21_amd64.deb

Installation

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-3.0.0-13-i7_3.0.0-13.21_amd64.deb linux-headers-3.0.0-13_3.0.0-13.21_all.deb linux-image-3.0.0-13-i7_3.0.0-13.21_amd64.deb

Check your bootloader if the newly installed Ubuntu 11.10 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.10 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
Showing 45 comments
Skip to the end and leave a comment.
  1. Ben Davis

    When I get to this step:

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

    I get:

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

    I followed this pretty much verbatim…

    • Edwin

      I have tried this over and over, and am still running into this exact same problem. Everything builds fine, but it just says “No rule to make target `binary-i7′. I have tried many times in excruciating detail to make sure I wasn’t mistyping anything. It does throw continuous warnings saying python-config isn’t available, but it just says it will build without python-support. Could that be a problem?

      I am building on a fresh install of oneiric directly from Ubuntu. Thanks!

  2. Peter

    Sounds like a typo or missed step:
    Check the files: debian.master/etc/getabis and debian.master/rules.d/amd64.mk
    Check you copied the file debian.master/control.d/vars.i7

  3. Björn Wahlström

    I tried to compile for an i386 machine with adaptions to your guide
    On the step “# skipabi=true skipmodule=true fakeroot debian/rules binary-i7″
    I get the following error messages

    check-config: FAIL: value CONFIG_LSM_MMAP_MIN_ADDR 0
    check-config: FAIL: value CONFIG_SECURITY y
    check-config: FAIL: value CONFIG_SECURITY_SELINUX y
    check-config: FAIL: value CONFIG_SECURITY_SMACK y
    check-config: FAIL: value CONFIG_SECURITY_YAMA y
    check-config: FAIL: value CONFIG_DEFAULT_SECURITY_APPARMOR y
    check-config: FAIL: !exists CONFIG_SECCOMP | value CONFIG_SECCOMP y
    check-config: FAIL: !exists CONFIG_HAVE_SECCOMP_FILTER | value CONFIG_SECCOMP_FILTER y
    check-config: FAIL: !exists CONFIG_CC_STACKPROTECTOR | value CONFIG_CC_STACKPROTECTOR y
    check-config: FAIL: ( ( arch armel | arch armhf ) & value CONFIG_DEFAULT_MMAP_MIN_ADDR 32768 ) | ( value CONFIG_DEFAULT_MMAP_MIN_ADDR 65536)
    check-config: FAIL: value CONFIG_TMPFS_POSIX_ACL y
    check-config: FAIL: value CONFIG_BLK_DEV_DM y
    check-config: FAIL: value CONFIG_INIT_PASS_ALL_PARAMS y
    check-config: FAIL: value CONFIG_IMA n
    check-config: FAIL: value CONFIG_IPV6 y
    check-config: FAIL: value CONFIG_ECRYPT_FS y
    check-config: 21/37 checks passed — exit 1
    make: *** [config-prepare-check-ebx] Error 1

    Any idea how to correct?

  4. null

    “””I followed this pretty much verbatim”””

    Same here, and I get the same error

  5. Qinglin Ye

    When I followed this HOWTO and got stuck on this step (where ‘i7′ had been replaced by my own flavor name):
    #skipabi=true skipmodule=true fakeroot debian/rules binary-i7

    And I got the same error output on this page: http://ubuntuforums.org/showthread.php?t=1468299

    Before that output, I found:

    run-parts -v debian/tests
    run-parts: executing debian/tests/README
    run-parts: failed to exec debian/tests/README: Exec format error
    run-parts: debian/tests/README exited with return code 1
    run-parts: executing debian/tests/check-aliases

    So I ‘rm’ed debian/tests/README, then everything is OK.

    May it helps.

    • Peter

      What were the permission for README in that directory? It sounds like the file was set for executable.

      • Qinglin Ye

        Yes, it’s executable.

        -rwxrwxrwx 1 root root 1134 2011-11-12 12:06 README*

        I didn’t set the permission manually, it must be a bug.

        • Peter

          First you pulled the repository as root, not a good thing to do, you really should do that as a normal user.

          When you pull a repository with git the file permissions are set as well by git. I have a a feeling all file rights are set to 777 in the entire repository. Not sure how it happened though.

          • Qinglin Ye

            Your reply leads me to notice the permissions of the other files. They are all set to root/777, including files outside the repository.

            I am using a wubi-installed Ubuntu, is that cause the problem?

            Thank you.

          • Peter

            I never used the wubi-installed version, But I’m pretty sure that might be the cause of the wrong rights. As it’s running on a Windows box and Linux and Windows rights don;t really go hand-in-hand they might have opted to set the right to 777 for the wubi-installation.

  6. it is working

    for “””I followed this pretty much verbatim””” guys,
    are you sure you replaced “i386″ with “amd64″ in your i386 based PCs??

  7. Dan

    “small caps”? Do you mean “lowercase”?

    • Peter

      Yup lowercase.

  8. spybee

    Nice tutorial!! However..

    It is not very wise to work as an admin when you compile your source code!! Use sudo instead.

    • Peter

      You are right and that’s why you exit the root shell after the preparations.

      apt-get install git libncurses5 libncurses5-dev libnewt-dev
      exit

    • Jane

      ο οί έ ου ί ί ε ά ε ού Gnome3 Unity. ά ή ο number 1 ε ώ ου ου ά ε ο Ubuntu reseale party ( ε ο ί εο:) ό ο ο ί ου έ ε ο Ubuntu ή ο ώ ο ου έ ε υ ά ο ί ο υ ή ή. Ό ε ά ε ο ο devvelopers ου Gnome ο ά ε ί ύ ου ο Gnome 3 ε ί ου 2-3 ό . ο ό ε εί ε ε ώ ε έ ου ί ου ο ώ εί ο έο Gnome. ο Unity ο ί ε υ ο ο ή ε ου ε ευ ίου 6 ή ε . Ο ό ε ό ε ο ο έ ε ά ουv ε Gnome 3 (ε ά ε ά ο Ο ώ ο) ο Ubuntu υ ε ή ε ε ο Unity. ο έ ου ε ή ου ε ο Gnome 2 ού ε υ ε εί υ ο ή ή ά υ ή ου εί ά ε ο ου dev ου Gnome ή ου ο Gnome 3. Ή ό ου έ ο ο ά ου ά ου ο ή ο ε ε ί ου . ο εί ο οίο έ ε , ά ε ο υ ά ο stack ου Gnome 2 ο υ ε ί ε , ο ύ ε ο υ εί .. ό ο ό ??? Ό ό ο ά ε ά ου ε έε ο ή ε ου GTK3 ??? ί έ ε ο KDE4, ά ε ά ο 1-2 ό ο ά ο ού .Ο ε ο έ ε έ ου ε εί ε ευ υ ώ . Ο ό ε έ ε ο ή Desktop Environment έ ου ε Gnome 3, Unity, KDE4, XFCE ά ο ά.

  9. Erik

    Thanks a lot for this. Very easy to follow – I actually used this page with along with the one for Natty to compile a 3.2 kernel for my Ubuntu Studio 11.04 install. Just substituted ‘precise’ in place of ‘oneiric’ in the section ‘getting the source’.
    Thank you.

  10. plmegalo

    A tips to make the compile process go faster :
    just before running compilation, type the following command line :

    export CONCURRENCY_LEVEL=n

    Where “n” can be from 2 to 8
    For instance “2″ for a core2 and “8″ for i7

    • Peter

      This should already be build in the scripts provided by Canonical.

      • plmegalo

        indeed, but that way you can fix it better for your machine (default would be 4 or 6 for i7 though 8 can still enhance speed, for instance ;))

  11. TechLW

    Really nice,
    very cool sharing.

  12. Abbas

    Hi Peter,
    I left a question, but couldn’t find answer,even my question was removed, is there a pre-condition to join this forum, as

  13. Alexander

    Hi,
    My question is: how to build custom kernel with keeping module compatibility?
    What do I mean: when I built 3.0.0-14-generic kernel and installed it. But when loading proprietary kernel module I got:
    zinFrameDriver: disagrees about version of symbol module_layout
    Thanks in advance

    • Peter

      Not really sure if you can, it sounds like the zinFrameDriver isn’t compatible with the 3.0 kernel.

  14. Alexander

    zinFrameDriver is compatible with 3.0.0-14-generic #23-Ubuntu kernel. But I need to customize this kernel and at the same time not to lose compatibility customized kernel with zinFrameDriver.

    • Peter

      The message also pops up when you run the same kernel version but a different configuration. Nothing you can do about that I guess.

  15. Patrick Dickey

    I’m trying the instructions here. However, when I try to install build-dep, I get an error saying that package doesn’t exist. Is it a part of build-essentials, or do I need to add a different repository to find it?

    Have a great day:)
    Patrick.

    • Patrick Dickey

      Scratch this comment. I tried combining all of the apt-get installs, and I included the apt-get build-dep command as one of the things to be installed… That’s what I get for taking shortcuts.

  16. Ragu

    As many users pointed out, even i am getting the following error.

    ragu@ragu-VirtualBox:~/source$ skipabi=true skipmodule=true fakeroot debian/rules binary-x86
    make: *** No rule to make target `binary-x86′. Stop.

    I used x86 instead of i7.

    I tried to resolved the issue, by following the steps you mentioned i.e check for typos. So i cross checked the files for any typo, but everything looks fine.I have edited them properly with proper input.
    What could be the issue ?

    Thanks
    Ragu

  17. Leandro

    WITH COMPILED KERNEL:

    What I detected is this. I have two different readings for the same processor but one comes from cpuinfo_cur_freq and the other one comes from scaling_cur_freq as seen below:

    sudo cat scaling_cur_freq; sudo cat cpuinfo_cur_freq
    800000
    1800000

    What’s the true reading? Why with stock kernel it don’t happen the frequencies match!

    cat scaling_driver; cat scaling_governor
    acpi-cpufreq
    ondemand

    cat time_in_state
    2201000 57624
    2200000 2875
    2000000 2297
    1900000 631
    1800000 620
    1700000 709
    1600000 659
    1500000 789
    1400000 793
    1300000 822
    1200000 801
    1100000 977
    1000000 1142
    900000 705
    800000 842189

    WITH STOCK KERNEL:

    With stock kernel, just for comparison, as you can see it’s more logical and the readings match, even the one that shows the time_in_state.

    sudo cat scaling_cur_freq; sudo cat cpuinfo_cur_freq
    800000
    800000

    cat scaling_driver; cat scaling_governor
    acpi-cpufreq
    ondemand

    cat time_in_state
    2201000 22259
    2200000 50
    2000000 28
    1900000 57
    1800000 42
    1700000 53
    1600000 55
    1500000 112
    1400000 241
    1300000 280
    1200000 355
    1100000 296
    1000000 403
    900000 1642
    800000 145615

    • Leandro

      Complementing the information /proc/cpuinfo

      processor : 0
      vendor_id : GenuineIntel
      cpu family : 6
      model : 42
      model name : Intel(R) Core(TM) i7-2670QM CPU @ 2.20GHz
      stepping : 7
      microcode : 0×23
      cpu MHz : 800.000
      cache size : 6144 KB
      physical id : 0
      siblings : 8
      core id : 0
      cpu cores : 4
      apicid : 0
      initial apicid : 0
      fpu : yes
      fpu_exception : yes
      cpuid level : 13
      wp : yes
      flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx lahf_lm ida arat epb xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid
      bogomips : 4390.25
      clflush size : 64
      cache_alignment : 64
      address sizes : 36 bits physical, 48 bits virtual
      power management:

    • Leandro

      Somebody on OpenSUSE forum that had the same problem gave me this tip and it simply worked, now the frequencies always match:

      add the kernel boot options: i915.i915_enable_rc6=1 i915.i915_enable_fbc=1 i915.lvds_downclock=1 pcie_aspm=force

  18. Leandro

    With kernel 3.4 this issue doesn’t happen and it’s not needed to put those boot options. You can set frequency to 800MHz without problems. I compiled, myself, the 3.4.3 kernel and proved it. If you do a cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq; cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq, you’ll see that both frequencies will be 800000 and not 1800000 and 800000 as it was before. You can use powertop or i7z to check it out too.

  19. Steve

    Update for building 12.04 / 12.10

    Peter, I just want to say thanks for developing and posting these HOWTO guides, they’ve been hugely helpful over the past couple years. Also, I’ve been working on building the 3.5 kernel with the latest precise and quantal trees and ran into a couple problems and solutions I thought I’d share.

    * needed more packages: sudo apt-get install flex bison pkg-config python-dev
    * needed to edit this file: debian/debian.env
    the problem there is that it points to debian.quantal rather than debian.master, you must have it set to debian.master or the build wont produce the tools and other packages

    That’s about it, the rest of the build process seems to work as per your 11.x HOWTO above.
    Best,
    -Steve

    • Peter

      Thanks for the heads up Steve.
      I haven’t looked at the upcoming Ubuntu 12.10 release myself, but this will surely speed up the writing of the next how to.

  20. Paul

    If after the last step, “sudo dpkg -i…” I want to make changes to the .config and recompile what steps can be omitted? Can I simply start over at debian/rules editconfigs?

  21. G

    Great. Thanks a lot!

    But how can I get a corresponding source package? This would be necessary in case someone would like to distribute a customized kernel. (Also deliver source b/c GPL)

    • Peter

      I don’t have the 11.10 repository anymore but at all the commands where you start with skipabi=true add do_full_source=true, so for example:

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

      would become

      skipabi=true skipmodule=true do_full_source=true fakeroot debian/rules binary-indep
      • G

        Not sure if I am mistaken. But what I need is
        diff.gz, dsc, orig.tar.gz files

        • G

          dpkg-source -b does what I need

  22.  

Leave a comment

For questions and/or support consider using the forums.