I run Ubuntu Intrepid 8.10 on Dual Core 2 laptop with 4 GB of memory. The default kernel supplied by Ubuntu doesn’t support the 4GB memory, I could choose to run the server kernel but I also want to take advantage of the Core2 support in the kernel so I took it upon myself to compile a custom kernel.
Unfortunately the Ubuntu developers thought it was better to change the way kernel is build in Intrepid and the official Ubuntu How to compile a kernel on the Wiki isn’t set up for Intrepid yet. Most of the stuff I had to discover myself and to make sure I remember for the next time, but also to help benefit others for when they want to compile their own custom kernel, I decided to write it all down.
Updated: Nov 7, 2008
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
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 apt-get which this article is using or by using git. If you prefer to use git follow my other article I have written.
To get the source of your current running kernel, in my case it’s 2.6.27-7
apt-get build-dep linux-image-$(uname -r) apt-get source linux-image-$(uname -r)
The source code is installed in the directory linux-2.6.27.
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. I create a copy of the kernel source to edit the config file.
cp linux-2.6-27 linux -r cd linux cp /boot/config-$(uname -r) . make menuconfig
When you’re done we make a backup of the config file.
mv .config ../config.core2 cd ..
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.
cd linux-2.6.27 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.
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.
For an overview of all articles on how to compile a kernel for Ubuntu check out the Compile a kernel for Ubuntu overview page