This tries to document how to build custom kernel for amd64 architecture the ubuntu way.
Install dependencies
These dependencies are required for building linux 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
sudo apt-get
build-dep linux
Get kernel source code
Create a new folder/directory, this should be in a partition which has atleast 10 GB free space
mkdir Builds
cd Builds
apt-get source
linux-image-$(uname -r)
Work on copy of the kernel source
Take a copy of the kernel downloaded. By mistake some setting is changed, we can work on another fresh copy
cp linux-3.0.0
linux -r
cd linux
Create a new flavour
Here is giving execute permissions to debian build scripts before creating a new flavour
#make
debian/rules as executable
chmod -Rv +x
debian/rules
#make
debian/scripts directory executable
chmod -Rv +x
debian/scripts/
Here I create an i7 flavour (which should run on i3, i5 and i7)
#create i7
flavor
cp
debian.master/config/amd64/config.flavour.generic
debian.master/config/amd64/config.flavour.i7
#clean
fakeroot
debian/rules clean
fakeroot
debian/rules updateconfigs
Here is the place where we give kernel configuration (I changed kernel frequency from 250 HZ to 300 HZ and changed processor to CORE2)
#give y only to
i7 flavor, leave the rest untouched
fakeroot
debian/rules editconfigs
The following are to do with the ABI settings which we clone from existing Ubuntu and modify just the names to reflect our flavour
#copy the abi
entries for i7 flavor and add i7 entries in vars and amd64.mk
cp
debian.master/abi/3.0.0-12.19/amd64/generic
debian.master/abi/3.0.0-12.19/amd64/i7
cp
debian.master/abi/3.0.0-12.19/amd64/generic.modules
debian.master/abi/3.0.0-12.19/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
vi Makefile
I changed only the main makefile HOSTCC and HOSTCXX as follows
HOSTCC = gcc -march=corei7 -mtune=corei7
HOSTCXX = g++ -march=corei7 -mtune=corei7
These are other makefiles to have a look at
vi
arch/x86/Makefile
vi
arch/x86/Makefile_32.cpu
Build
Clean before doing a build
#clean and
build
fakeroot
debian/rules clean
Just build and Ubuntu will take care of creating concurrent builds based on your processor count
skipabi=true
skipmodule=true fakeroot debian/rules binary-indep
time
skipabi=true skipmodule=true fakeroot debian/rules binary-i7
Install
The built deb packages are in the parent directory, so change to previous directory
cd
..
The following installs the newly created flavour
sudo dpkg -i
linux-headers-3.0.0-12_3.0.0-12.20_all.deb
linux-headers-3.0.0-12-i7_3.0.0-12.20_amd64.deb
linux-image-3.0.0-12-i7_3.0.0-12.20_amd64.deb
Here is the i7 optimized builds which I am using and can be used on any 64bit i3, i5 or i7
Kernel Image : http://www.mediafire.com/file/tb9fo7omoaa8pxc/linux-image-3.0.0-12-i7_3.0.0-12.20_amd64.deb
Kernel Headers : http://www.mediafire.com/file/47s4dkbz5bf8ij3/linux-headers-3.0.0-12-i7_3.0.0-12.20_amd64.deb
Kernel Headers All : http://www.mediafire.com/file/ktw2d9d2qoyh3yz/linux-headers-3.0.0-12_3.0.0-12.20_all.deb
Oneiric Kernel Build Script : http://www.mediafire.com/file/pn3xmszxl9sy9cr/OneiricKernelCompilation.sh
SHA256SUMS-Oneiric.txt : http://www.mediafire.com/file/wvun5qrjim04j7q/SHA256SUMS-Oneric.txt
SHA256SUMS
ba00c0c3ee5d0875ea961f2ff4c7e54c460eb298b22c58e85d570f112ca323dd linux-headers-3.0.0-12_3.0.0-12.20_all.deb
dcf30712689180ea6bb4d7d361c6660063c3a446531313989ee968deb9aa4927 linux-headers-3.0.0-12-i7_3.0.0-12.20_amd64.deb
f587a9d5ea51c5ec39b633b2ed64e63b06b9bc34dc25137729d6e969ce424766 linux-image-3.0.0-12-i7_3.0.0-12.20_amd64.deb
ed287ac072c0ee94cc79fd274cf81659259d06b244b70664ef95acc3ea507ec9 OneiricKernelCompilation.sh
Add this lines to your ~/.bashrc so that you will never need to add any parameter any more. Every time you open the terminal you will have the 'One Time added' parameters:
ReplyDeleteexport CFLAGS="-march=core2 -Os -pipe"
export CXXFLAGS="${CFLAGS}"
export HOSTCC="gcc -march=core2 -mtune=native"
export HOSTCXX="g++ -march=core2 -mtune=native"
export CONCURRENCY_LEVEL=9
export MAKEOPTS="-j9"
is it better to have mtune=native or mtune=corei7 or core=corei7-avx ?
Deleteto use -mtune=native
ReplyDelete