Previously I wrote an article on how to compile a custom kernel for Ubuntu Intrepid, it used the apt-get method for getting the kernel source. If you prefer to use git to get the latest kernel source you can use this post. Most of this post is a copy of the previous post but to make it easier to follow the instructions I decided to write up everything in this post as well.
Jan 8, 2009: Added git add to the “commit the changes” section.
Dec 11th: Added installation of needed packages.
Nov 27th: Added command to change to intrepid directory.
Oct 31st: I changed some steps in the section Getting ready for compilation to be prepare ourselves for compiling new releases of the kernel.
I’ll be doing everything as root.
First we need to install some applications so we can do the compilation:
apt-get install fakeroot build-essential apt-get install crash kexec-tools makedumpfile apt-get build-dep linux apt-get install git-core libncurses5 libncurses5-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/packaging/kernel as I package other software as well. All the commands I type will be done from this directory.
Getting the source
There are a couple of ways to get the kernel source from Ubuntu, using git which this article is using or by using apt-get. If you prefer to use apt-get follow my other article I have written.
To get the source using git
git clone git://kernel.ubuntu.com/ubuntu/ubuntu-intrepid.git intrepid
The source code is installed in the directory intrepid.
We create a branch with a copy of the kernel version we want to work on. To determine which the latest official release is:
cd intrepid git tag | grep Ubuntu*
This results in something like this:
Ubuntu-2.6.27-7.10 Ubuntu-2.6.27-7.11 Ubuntu-2.6.27-7.12 Ubuntu-2.6.27-7.13 Ubuntu-2.6.27-7.14
git checkout Ubuntu-2.6.27-7.14 -b core2
Creating a new config
I’ll be using the method of creating a new flavor, this adds a bit more work but you can always compile the original kernels. Now for the fun stuff, editing the config so it fits my needs. I won’t go into detail which settings I changed, if somebody is interested I certainly can give that information. I use the current running config as my base.
cp /boot/config-$(uname -r) . make menuconfig
When you’re done we make a backup of the config file.
mv .config ../config.core2
Now we need to clean up the git tree
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. My previous version is 2.6.27-7.13.
cp debian/abi/2.6.27-7.13/i386/generic debian/abi/2.6.27-7.13/i386/core2 cp debian/abi/2.6.27-7.13/i386/generic.modules debian/abi/2.6.27-7.13/i386/core2.modules cp ../config.core2 debian/config/i386/
We also need to edit some files
In the next few parts I’ll explain what you need to change
Search for the line:
getall i386 generic server
Change it in:
getall i386 generic server core2
Search for the line:
flavours = generic server
Change it in:
flavours = generic server core2
Files: debian/control.stub and debian/control
For both files we need to copy three sections:
- Package: linux-image-2.6.27-7-generic
- Package: linux-headers-2.6.27-7-generic
- Package: linux-image-debug-2.6.27-7-generic
A section is defined from the line Package to the next line starting with Package.
In the copied sections we need to replace “generic” with “core2” on all the lines that start with Package.
Now we need to commit our changes in the git repository
git add . git commit -a -m "Core2 modifications"
The text after -m is the message you add to your commit.
It’s finally time for compiling.
CONCURRENCY_LEVEL=2 NOEXTRAS=1 skipabi=true skipmodule=true fakeroot debian/rules binary-core2
Because I have a Dual Core I want to utilize both processors by setting the CONCURRENCY_LEVEL. Set this to the amount of processors you have, if you have only one, just skip it completely. No matter grab yourself some coffee while we’re compiling.
After the compilation is finished we’ll have two deb files in the parent directory. To install the files
dpkg -i linux-image-2.6.27-7-core2_2.6.27-7.14_i386.deb dpkg -i linux-headers-2.6.27-7-core2_2.6.27-7.14_i386.deb
Check your bootloader if the newly installed kernel is the default one, for grub edit the file /boot/grub/menu.lst
Reboot and enjoy your newly installed kernel.