Linux Kernel 3.9 on Ubuntu

The Linux kernel 3.9 was released on on Monday, April 29, 2013 by Linus and currently I’m running the new kernel on my Ubuntu 13.04 machine but you can do this on any Ubuntu version. This article will describe how you can compile the mainline kernel from the official git repository in a Ubuntu way.


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


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

sudo su -
apt-get install fakeroot build-essential devscripts
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 libunwind8-dev libaudit-dev libpython-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/vanilla/

Getting the source

The mainline repository is big, so cloning the repository will take a while, depending on your Internet speed.

cd /d1/development/kernel/vanilla
git clone git:// source
cd source

The source code of the kernel is installed in the directory source.

We’ll check the tags set by Linus to determine which version of the kernel we want to compile

git tag|sort -V

I don’t recommend the release candidates kernel at any time, just use the latest stable version, in our case v3.9

In order to compile the kernel in the Ubuntu way we will add a Ubuntu remote repository to our local repository. For this article we will use the Ubuntu 13.04 (Raring) repository.

git remote add raring git://
git fetch raring

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 kernel with an updated mainline kernel at a later time.

As determined earlier we will checkout v3.9 of the kernel.

git checkout -b i7 v3.9 --

This will create a branch called i7.

Ubuntunize the branch

We will pull in the needed Ubuntu files to compile the kernel in the Ubuntu way.

git checkout raring/master -- debian
git checkout raring/master -- debian.master

Create our own Changelog
In order to set the right version during the compilation, we need to change the changelog which is located in debian.master/changelog
First of all we need to determine which version of the mainline kernel we are compiling.

head -5 Makefile

This will display something like this

NAME = Unicycling Gorilla

The version numbering we will be using is VERSION.PATCHLEVEL.SUBLEVEL, which makes the version in our case 3.9.0 but for the changelog we need to expand this.
I use the following format: 3.9.0-999.1
The 999 is used so whenever Ubuntu comes out with a 3.9.0 kernel for the Ubuntu version we’re running, our kernel will seem to be the newer. The .1 is just an extra and is used when we want to recompile the 3.9.0 version after we make some config changes, just increase this number and you have a newer kernel version.
It’s highly recommend to follow the version dash number dot number format.

The changelog needs a name and email address, if you want your own name and email change the DEBEMAIL and DEBFULLNAME.
To recreate the changelog

rm debian.master/changelog
DEBEMAIL=""; DEBFULLNAME="Peter van der Does"; dch -v 3.9.0-999.1 --distribution raring --package linux --create -c debian.master/changelog Mainline kernel build: v3.9.0

This will create the changelog in debian.master as follows

linux (3.9.0-999.1) raring; urgency=low

  * Mainline kernel build: v3.9.0

 -- Peter van der Does <>  Mon, 29 Apr 2013 12:43:11 -0400

Modify check files
During modification of configuration files and during the compilation process, Ubuntu does some checks to see if it all looks good but as we are not compiling a kernel with Ubuntu patches these checks might fail. Therefor we will be modifying these files and instead of doing it manually, we’ll use a small script to accomplish the needed changes.

for i in debian/scripts/*-check debian.master/scripts/*-check
	if [ -f "$i" ]; then
		cat - <<EOM >"$i"
exit 0
		chmod 755 "$i"

The above script is available for download.

The Ubuntu kernel maintainers also patch the kernel so it can compile for Hypervisor, if you don’t need this, you have to make a change to the file:


Change the line

do_hyperv       = true


do_hyperv       = false

If you want Hypervisor support in your kernel you need to change some other files, but I won’t get into this in this article.

At this time we will commit our changes with git so we don’t lose them.

git commit -a -m "Ubuntunized"

Creating a new kernel configuration

I’ll be using the method of creating a new flavor, this adds a bit more work but this allows you to always compile the original kernel, if you wanted to.

We’ll use the flavor you are currently running as the base for our own flavor, being i7. Please note that, as discovered by one of the readers of this blog, the extension needs to be in small caps.

cp /boot/config-`uname -r` debian.master/config/amd64/config.flavour.i7
fakeroot debian/rules clean defaultconfigs

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 we will have to go through all the flavors for this script to work properly.

debian/rules editconfigs

The script will ask us if we want to edit the particular kernel configuration. We should not make changes to any of the configurations until we see the i7 configuration.

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

We make our changes, save the configuration and then keep answering no to any other questions until the script ends.

When we’re done, we will commit the changes into the git repository.

git add debian.master/config/amd64/config.flavour.i7 
git commit -a --amend

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 kernel 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 kernel release we use:

ls debian.master/abi

The previous release in this case is 3.8.0-18.28

cp debian.master/abi/3.8.0-18.28/amd64/generic debian.master/abi/3.8.0-18.28/amd64/i7
cp debian.master/abi/3.8.0-18.28/amd64/generic.modules debian.master/abi/3.8.0-18.28/amd64/i7.modules

We need to edit some files:

File: debian.master/etc/getabis

Search for the line:

getall amd64 generic

Change it in:

getall amd64 generic i7


File: debian.master/rules.d/

Search for the line:

flavours        = generic

Change it in:

flavours        = generic 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 armhf"
supported="i7 Processor"
target="Geared toward i7 desktop systems."
desc="=HUMAN= SMP"
bootloader="grub-pc [i386 amd64 x32] | grub-efi-amd64 [i386 amd64 x32] | grub-efi-ia32 [i386 amd64 x32] | grub [i386 amd64 x32] | lilo (>= 19.1) [i386 amd64 x32] | flash-kernel [armhf arm64]"
provides="kvm-api-4, redhat-cluster-modules, ivtv-modules"

We need to commit our changes in the git repository.

git add .
git commit -a --amend


It’s finally time for compiling our kernel and 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 kernel packages will be created in the directory /d1/development/kernel/vanilla
Create independent packages:

PYTHON_CONFIG=x86_64-linux-gnu-python-config fakeroot debian/rules binary-indep

The above statement will create the following deb files:


Create the tools package:

fakeroot debian/rules binary-perarch

The above statement will create the following deb file:


Create the flavour depended files:

fakeroot debian/rules binary-i7

The above statement will create the following deb files:


Install the new Kernel

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.9.0-999-i7_3.9.0-999.1_amd64.deb linux-headers-3.9.0-999_3.9.0-999.1_all.deb linux-image-3.9.0-999-i7_3.9.0-999.1_amd64.deb

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

Reboot and enjoy our newly installed Linux 3.9 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 11 comments
Skip to the end and leave a comment.
  1. Mordac

    Or you can just download the package from the 13.10 development release :P

    • DrAcid

      Or you could just appreciate an opportunity to learn how to build a kernel from source :)

      • Daniel Fletcher

        Or even better, download the source with all of the Ubuntu “sauce” patches (ureadahead, apparmor, etc) and not just the Debianized source from GIT:

        Within a few days the version number will change so you’ll be able to see the ‘superseded’ message and just change the URL accordingly.

  2. mike


    I am getting this error, can you please tell me how can I fix it?

    make[1]: Entering directory `/home/mikes/kernel_vanilla/source/debian/build/tools/tools/perf’
    Makefile:755: The path ‘x86_64-linux-gnu-python-config’ is not executable.
    Makefile:755: *** Please set ‘PYTHON_CONFIG’ appropriately. Stop.

    • Peter

      Are you compiling for 64 bit or 32 bit?

      If it’s 64 bit, make sure you installed the package libpython-dev
      If it’s 32 bit also install libpython-dev and replace this line

      PYTHON_CONFIG=x86_64-linux-gnu-python-config fakeroot debian/rules binary-indep


      PYTHON_CONFIG=i686-linux-gnu-python-config fakeroot debian/rules binary-indep


      PYTHON_CONFIG=i386-linux-gnu-python-config fakeroot debian/rules binary-indep
  3. cepharch

    Thanks for this tutorial! Worked like a charm.
    Can you please add infos what has to be done if I wanna compile the next version. Do I have to clean the whole source out? And how to do so? or what ever…
    I only know how to do this stuff when compiling for android. But there I have a manifest, sync and make clobber so on…
    Thanks in advance!



  4. Phyrexus

    This is great, I’ve been compiling my kernels using your tutorials for a long time now!

    I was wondering if you could point me to the Hyper-V support files that I need to modify for compilation, since I’ve noticed some problems with my laptop that won’t function without it.

  5. Errol Neal

    Hey thanks for the how-to. Question for you. What is the proper way to add patches on top of this?
    So lets say I have a couple of patch files that I apply to the kernel, what is a easy way to track those changes?

  6. p4j0c4

    I get this error:

    make[1]: Entering directory `/home/p4j0c4/.builds/linux-3.12/source/debian/build/tools-perarch/tools/power/cpupower’
    CC lib/cpufreq.o
    CC lib/sysfs.o
    CC utils/helpers/amd.o
    utils/helpers/amd.c:7:21: fatal error: pci/pci.h: No such file or directory
    compilation terminated.
    make[1]: *** [utils/helpers/amd.o] Error 1
    make[1]: Leaving directory `/home/p4j0c4/.builds/linux-3.12/source/debian/build/tools-perarch/tools/power/cpupower’
    make: *** [/home/p4j0c4/.builds/linux-3.12/source/debian/stamps/stamp-build-perarch] Error 2

    • Timo

      Try to install pciutils-dev and rerun.

      • p4j0c4



Leave a comment

For questions and/or support consider using the forums.