Kernel 3.1
I built the 64bit kernel 3.1 for my Kubuntu 11.10 desktop optimized for i7. Here is the screenshot of the kernel in action
Feel of the new kernel 3.1 seems to be very exciting. Kubuntu booted to login screen within 10 seconds. (With default kernel it took more than 20 seconds to boot Kubuntu 11.10 unlike ubuntu 11.10 which was faster to boot)
Here is how I built the kernel 3.1 Ubuntu way (in short 7 steps)
In brief
- Install build dependencies
- Download kernel source and ubuntu patches
- Extract and apply ubuntu patches
- Create a new flavour and tweak kernel config
- Modify Makefile for optimization
- Build
- Reboot and Enjoy
In detail
Install build dependencies
Open terminal/konsole and execute the following apt-get commands if you don't have essential build packages necessary for building kernel from source in Ubuntu
#Install Build essential to build kernel
sudo apt-get install fakeroot build-essential crash kexec-tools makedumpfile kernel-wedge libncurses5 binutils-dev libelf-dev libdw-dev libnewt-dev libncurses5-dev
sudo apt-get --no-install-recommends install asciidoc xmlto
Download kernel source and ubuntu patches
Download the source of newly released linux kernel 3.1. The following wget -c makes it simple to download from commandline
#Download kernel source
wget -c http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.1.tar.bz2
Here is how to download the 3.1 ubuntu patches
#Download ubuntu patches
wget -c http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.1-oneiric/0001-base-packaging.patch
wget -c http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.1-oneiric/0002-debian-changelog.patch
wget -c http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.1-oneiric/0003-default-configs.patch
Extract and apply ubuntu patches
Extract downloaded kernel source and apply patches. Here I used tar to unzip the bzip tarball and patch to apply the patch
#Extract kernel source
tar xjvf linux-3.1.tar.bz2
#Create a soft link
ln -s linux-3.1 linux
#Enter linux directory
cd linux
#Apply the patches
patch -p1 < ../0001-base-packaging.patch
patch -p1 < ../0002-debian-changelog.patch
patch -p1 < ../0003-default-configs.patch
Create a new flavour and tweak kernel config
Before creating a new flavor, give execute permissions to debian build scripts for building the kernel properly
#make debian/rules as executable
chmod -Rv +x debian/rules
#make debian/scripts directory executable
chmod -Rv +x debian/scripts/
To create a new flavour, just clone from generic flavor, here is how
#create i7 flavor
cp debian.master/config/amd64/config.flavour.generic debian.master/config/amd64/config.flavour.i7
Do the kernel configuration, I selected processor type as CORE2 and kernel frequency to 1000HZ (just give y only to the newly created flavor when executing editconfigs)
#clean
fakeroot debian/rules clean
fakeroot debian/rules updateconfigs
#give y only to i7 flavor, leave the rest untouched
fakeroot debian/rules editconfigs
Copy the abi related files from existing generic flavor and tweak to reflect the newly created flavor
#copy the abi entries for i7 flavor and add i7 entries in vars and amd64.mk
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
sed -i s/getall\ amd64\ generic\ server\ virtual/getall\ amd64\ generic\ server\ virtual\ i7/g debian.master/etc/getabis
sed -i s/\=\ generic\ server\ virtual/\=\ generic\ server\ virtual\ i7/g debian.master/rules.d/amd64.mk
cp debian.master/control.d/vars.generic debian.master/control.d/vars.i7
sed -i s/\"Generic\"/\"core\ i7\"/g debian.master/control.d/vars.i7
Modify Makefile for optimization
This is the place where we apply the optimizations. Ubuntu 11.10 comes with gcc 4.6 which has added new architectue corei7
#edit arch/x86/Makefile and arch/x86/Makefile_32.cpu if you want to tweak the march and mtune params of gcc
vi Makefile
vi arch/x86/Makefile
vi arch/x86/Makefile_32.cpu
In the main makefile, I changed HOSTCC and HOSTCXX to look as follows
HOSTCC = gcc -march=corei7 -mtune=corei7 -pipe
HOSTCXX = g++ -march=corei7 -mtune=corei7 -pipe
In other makefiles, replace lowercased core2 with corei7 (simple isn't it?)
Build
Do a clean build
#clean and build
fakeroot debian/rules clean
The following builds the common header and source debs
skipabi=true skipmodule=true fakeroot debian/rules binary-indep
The following builds the newly created flavor. Note I added no_dumpfile=yes as it was not building the dumpfile.
time skipabi=true skipmodule=true no_dumpfile=yes fakeroot debian/rules binary-i7
Wait for sometime (depends on speed of your processor). No need to tweak concurrency settings, which are taken care automatically. Install the newly built debs as follows after going one directory above
cd ..
sudo dpkg -i linux-headers-3.1.0-030100_3.1.0-030100.201110241006_all.deb linux-headers-3.1.0-030100-i7_3.1.0-030100.201110241006_amd64.deb linux-image-3.1.0-030100-i7_3.1.0-030100.201110241006_amd64.deb
Reboot and Enjoy
To test the newly built kernel, reboot and select the newly installed kernel from grub. If the newly installed kernel does not boot for some reason, do not panic, select the old ubuntu kernel and boot. (Grub2 does not wait beyond 3 seconds if there is no other OS present and very annoying, press escape within first 3 seconds to display the grub menu if it does not display) Follow this to know more about how to customize grub2 http://maketecheasier.com/mastering-grub-2-the-easy-way/2009/11/19
or
https://wiki.ubuntu.com/Grub2
or
https://wiki.ubuntu.com/Grub2
sudo reboot
Download links
I have uploaded the kernel 3.1 debs which I built and use. If you don't want to build yourself you can try these.
Here are the SHA256SUM checksum
8d1c58d614056b3cb2e05562d1108cd0a25aa7900ea02f602e8da7a6ead00c83 buildscript.sh
3cbd100b33734330f6b4da7a25cce5c0a45db9cee16bf609c554cbc9cd7b3f98 linux-headers-3.1.0-030100_3.1.0-030100.201110241006_all.deb
6ad9338017182590ef791ed12bbcaf0857090fb6028ec90b6d81ea04c38948f5 linux-headers-3.1.0-030100-i7_3.1.0-030100.201110241006_amd64.deb
e1d62da1add7bfc0b9976fac7d8be32512da8eb09c5b41a6ab66b8c43d12b52e linux-image-3.1.0-030100-i7_3.1.0-030100.201110241006_amd64.deb
Here are the download links