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