For a nice pdf of document of the same click here
Download links are provided at the bottom of this article along with SHA256SUMS
Again thanks to
Linux Mint 11, I am enjoying it
Introduction
I faced the following with earlier kernel builds
Symlink errors while installing kernel debs in another system where the kernel build did not happen and lots of comments in the blog also reported the same
DKMS modules did not work in different systems where the kernel build did not happen
Cross compiling 32 bit kernels from my 64 bit PC was cumbersome
This kernel tries to address the above problems and give a kernel as similar to Ubuntu but with optimization. Towards the end of this document I have explained a step by step way of building the kernel Ubuntu way . Also I have made the same as a shell script which can be rerun again and again to build kernels Ubuntu way
This document is divided into two major sections, the first one is enough info about deb files and the second one is about how to build them
Info about the deb files
Requirements
This package is created in Linux Mint 11 and should install fine in all versions of Linux Mint 11 (as well Mint 10) and Ubuntu 11.04 (as well 10.10) (should as well in debian squeeze but not sure about dkms).
The build is done with march=core2 and mtune=native
This ensures the build will run on all core2 and above but will run with optimum speed on i3, i5 and i7 processors, so
The build is for 64bit i3,i5 and i7 processors
The following are the configuration settings
Processor is selected as CORE2
Makefile and Makefile_32.cpu modified to reflect march settings to core2 and mtune settings to native (my processor is i7 920)
Kernel Timer Frequency is 300 HZ
How to install
To install
sudo dpkg -i linux-headers-3.0.1-030001_3.0.1-030001.201108060905_all.deb linux-headers-3.0.1-030001-i7_3.0.1-030001.201108060905_amd64.deb linux-image-3.0.1-030001-i7_3.0.1-030001.201108060905_amd64.deb
After this reboot into the newly installed kernel from grub (use update-initramfs in case of 10.04 or older if it is not building initramfs)
Kernel Source
I downloaded the kernel source tarball from kernel.org
Version: 3.0.1
Ubuntu Oneiric Patches
How to build yourself
This kernel follows Ubuntu way of building kernel and has all ubuntu oneiric patches
The following is a documentation of building it the Ubuntu way, I used my article about
Ubuntu Maverick kernel compilation as a base for this, with some modifications. Here is a step by step of the same (and this explains the shell script commands which I created for my own reference)
Install dependencies for building Kernel
Here are the apt-get commands to install the dependencies required for building kernel the Ubuntu way
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
Get the Kernel source and Ubuntu Patches
Create a directory for the building kernel source
#Enter into Home directory of the user
cd ~
#create a kernel directory if it is not there
mkdir -p kernel3.0.1
#enter into kernel directory
cd kernel3.0.1
The following wget commands is used to fetch the Kernel source and Ubuntu Patches
#get the kernel sources and ubuntu patches
#kernel 3.0.1
#Ubuntu Oneiric Patches from kernel ppa
Create a soft link of extracted kernel folder
#unpack linux kernel 3.0.1
tar xjf linux-3.0.1.tar.bz2
#create a soft link for the kernel directory
ln -s linux-3.0.1 linux
#enter into unpacked directory
cd linux
Install Ubuntu patches we downloaded earlier
#install the ubuntu/debian patches
patch -p1 < ../0001-base-packaging.patch
patch -p1 < ../0002-debian-changelog.patch
patch -p1 < ../0003-default-configs.patch
Create and configure a new kernel flavor, here I create it as i7
After the patches are applied, we come here to create a new flavor
Before this we need to give execute permissions to debian scripts and debian rules
Give execute permissions to debian/rules and debian/scripts
#make debian/rules as executable
chmod -Rv +x debian/rules
#make debian/scripts directory executable
chmod -Rv +x debian/scripts/
Copy existing generic flavor (or use existing flavor to create new flavor, here i7)
#create i7 flavor
cp debian.master/config/amd64/config.flavour.generic debian.master/config/amd64/config.flavour.i7
Configure the newly created flavor i7
#clean
fakeroot debian/rules clean
fakeroot debian/rules updateconfigs
When calling editconfigs, say n to avoid editing any other flavor except the created flavor, here i7. When a prompt asks us to edit i7 (or any other flavor you created) give y, this will open menuconfig of the kernel, feel free to change kernel configurations to hearts wish and dont forget to save while exiting the menuconfig screen. This is the place where I gave CORE2 as the processor type and changed kernel timer frequency to 300 HZ (or whichever you prefer)
#give y only to i7 flavor, leave the rest untouched
fakeroot debian/rules editconfigs
Edit debian related abi information for newly created flavor, here i7
#copy the abi entries for i7 flavor and add i7 entries in vars and amd64.mk
cp debian.master/abi/3.0.0-7.9/amd64/generic debian.master/abi/3.0.0-7.9/amd64/i7
cp debian.master/abi/3.0.0-7.9/amd64/generic.modules debian.master/abi/3.0.0-7.9/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
Edit architecture dependent Makefiles to finetune gcc flags for compilation
Architecture dependent Makefiles for kernel compilation will reside in
arch//Makefile
For x86 architecture, the following are the two Makefiles
arch/x86/Makefile and arch/x86/Makefile_32.cpu
#edit arch/x86/Makefile and arch/x86/Makefile_32.cpu if you want to tweak the march and mtune params of gcc
vi arch/x86/Makefile
vi arch/x86/Makefile_32.cpu
After opening the Makefile search for CORE2 and change march=core2 and mtune=native
In Makefile the following will be the change
cflags-$(CONFIG_MCORE2) += \
$(call cc-option,-march=core2,$(call cc-option,-mtune=native))
In Makefile_32.cpu the following will be the change
cflags-$(CONFIG_MCORE2) += -march=core2 $(call tune,native)
Build
Clean before building
#clean
fakeroot debian/rules clean
Build source and headers debian package which is independent of architecture or flavor, hence indep
#build headers/source deb files
skipabi=true skipmodule=true fakeroot debian/rules binary-indep
Set the CONCURRENCY_LEVEL for concurrent builds which will speed up the kernel compilation tremendously
#set the CONCURRENCY_LEVEL to the number of processor cores in system to do parallel compilation and thus speed up the kernel compilation
#`cat /proc/cpuinfo | grep "cpu cores" | head -1 | cut -d":" -f2 | cut -c2-` is used to get the number of cores
export CONCURRENCY_LEVEL=`cat /proc/cpuinfo | grep "cpu cores" | head -1 | cut -d":" -f2 | cut -c2-`
cat /proc/cpuinfo gives all info about cpu in the system
grepping for “cpu cores” gives multiple lines one fore each core
head -1 takes the first line of output
cut -d”:” -f2 uses : as delimiter and gives the second field, which is the number of cores
cut -c2- skips leading space
export makes this variable exported for the coming lines
To test the CONCURRENCY_LEVEL, use echo $CONCURRENCY_LEVEL
Build the flavor
It is nice to time a build, just prefix time command before any other command, here the kernel build command. While calling debian/rules, we are invoking the newly created flavor which is
binary-i7 in this case
#build the actual kernel flavor i7 (and time it)
time skipabi=true skipmodule=true fakeroot debian/rules binary-i7