Ubuntu Karmic has been released to the public a few days ago and it’s time to write up a How To Compile a Kernel article. Only a few small changes have been made to the way we have compile a kernel for Ubuntu Karmic compared to Ubuntu Jaunty but they are significant enough for it’s own how-to.
I wrote this how to because my laptop has 4GB of internal memory and with the default kernel that ships with Ubuntu Karmic the entire 4GB is not addressed.
Lets get started building our own custom kernel for Ubuntu Karmic from scratch.
November 13, 2009: Compilation: The NOEXTRAS is no longer used . CONCURRENCY_LEVEL is automatically determined in the rules files.
November 10, 2009 : Changed the installation command. Thanks to comment by HotShotDJ
November 8, 2009 : Typo in the installing the kernel section. Only the headers were installed, not the image.
I wrote the follow up article: How to update your custom Ubuntu Karmic kernel after a new kernel release
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 i386 version, if you want to compile for amd64 you need replace i386 for amd64 throughout this article.
I choose the name core2 as the flavor name as for my personal use I’ll build a kernel for a Core2 processor. Besides the change of processor type in the configuration I also select support for 64GB as my laptop has 4GB, which is the main reason I started compiling my own kernels. I have some other changes but that’s beyond this article.
Let’s get started by preparing our machine for compiling a kernel for Ubuntu Karmic.
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 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/development/kernel/karmic
Getting the source
cd /d1/development/kernel/karmic git clone git://kernel.ubuntu.com/ubuntu/ubuntu-karmic.git source
The source code is installed in the directory source.
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 future updates a whole lot easier.
To see the latest version:
cd source cat debian.master/changelog|more
Press q to get back to the prompt.
This results in something like this:
linux (2.6.31-15.50) UNRELEASED; urgency=low CHANGELOG: Do not edit directly. Autogenerated at release. CHANGELOG: Use the printchanges target to see the curent changes. CHANGELOG: Use the insertchanges target to create the final log. -- Stefan Bader
Tue, 03 Nov 2009 09:58:14 +0100 linux (2.6.31-15.49) karmic-proposed; urgency=low
The latest version is the first version after the UNRELEASED section. In this case it is 2.6.31-15.49. Sometime there is no UNRELEASED section and in that case the latest version is the first version you see.
You could select any version you see in the changelog but for the sake of this article we’ll use the latest version.
git checkout Ubuntu-2.6.31-15.49 -b core2
This will create a branch called 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.
We’ll use the generic flavor as the base for our own flavor,core2.
cp debian.master/config/i386/config.flavour.generic debian.master/config/i386/config.flavour.core2 fakeroot debian/rules clean debian.master/scripts/misc/kernelconfig oldconfig
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, unfortunately you will have to go through all the flavors for this script to work properly.
This script will show you which configuration is next to be edited. You should not make changes, you can save the configuration if you like, the only time you have to edit the configuration is when you see
* Run menuconfig on i386/config.flavour.core2... Press a key.
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/i386/config.flavour.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. The previous release in this case is 2.6.31-14.48
cp debian.master/abi/2.6.31-14.48/i386/generic debian.master/abi/2.6.31-14.48/i386/core2 cp debian.master/abi/2.6.31-14.48/i386/generic.modules debian.master/abi/2.6.31-14.48/i386/core2.modules
Copy our flavored configuration file back.
cp ../config.flavour.core2 debian.master/config/i386/
We need to edit the following files
In the next few parts I’ll explain what you need to change
Search for the line:
getall i386 generic generic-pae 386
Change it in:
getall i386 generic generic-pae 386 core2
Search for the line:
flavours = generic generic-pae 386
Change it in:
flavours = generic generic-pae 386 core2
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.core2
You can edit the file and make it your own.
arch="i386 amd64" supported="Core2" target="Geared toward Core2 systems." desc="x86/x86_64" bootloader="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 "Core2 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 the following step whether you make changes to the configuration or not
fakeroot debian/rules clean
To start the compilation.
skipabi=true skipmodule=true fakeroot debian/rules binary-core2
Next you need to run
skipabi=true skipmodule=true fakeroot debian/rules binary-indep
After the compilation is finished we’ll have several deb files in the parent directory.
linux-doc_2.6.31-15.49_all.deb linux-headers-2.6.31-15-core2_2.6.31-15.49_i386.deb linux-source-2.6.31_2.6.31-15.49_all.deb linux-headers-2.6.31-15_2.6.31-15.49_all.deb linux-image-2.6.31-15-core2_2.6.31-15.49_i386.deb
To install the files
cd .. dpkg -i linux-headers-2.6.31-15-core2_2.6.31-15.49_i386.deb linux-headers-2.6.31-15_2.6.31-15.49_all.deb linux-image-2.6.31-15-core2_2.6.31-15.49_i386.deb
Check your bootloader if the newly installed 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 kernel.