Mar 9, 2013

How to customize and build Ubuntu server 12.04 LTS kernel

1. Prepare building environment

sudo apt-get build-dep linux-image-$(uname -r) 
2. Install required packages
sudo apt-get install libncurses5-dev kernel-package fakeroot build-essential crash kexec-tools makedumpfile kernel-wedge libelf-dev asciidoc binutils-dev

3.  Create a source directory and get kernel source
mkdir ~/ubuntu-kernel-src
cd ~/ubuntu-kernel-src
apt-get source linux-image-$(uname -r)
4. Config your kernel
Now, I have a directory "~/ubuntu-kernel-src/linux-lts-quantal-3.5.0" You can do "make menuconfig"/"make oldconfig" in this directory if you want.
5. Paralleling the building tasks
You have several options here. You can either 
a) export CONCURRENCY_LEVEL=n 
b) DEB_BUILD_OPTIONS=parallel=n
c) make -jn 
where n is generally the number of processors the building machine has. 
You can do a) now or use b) or c) later as building options. We will demonstrate b) and c) in the next step
6. Build the kernel
Suppose the machine has 16 cores. You can do 
fakeroot debian/rules clean
fakeroot debian/rules DEB_BUILD_OPTIONS=parallel=16 binary-headers binary-generic
Or
make-kpkg clean
fakeroot make-kpkg -j16 --initrd --append-to-version=-test00 kernel-image kernel-headers


If you need vmlinux for profiling or debugging. You may use skipdbg=false or install_vmlinux=true.
For example,
fakeroot make -f debian/rules binary-generic skipdbg=false
7. Install and test your new kernel
The deb files is saved in parent folder, which is "~/ubuntu-kernel-src" in this case. So,
sudo dpkg -i ../linux-*-test00*.deb
if you built vmlinux, you can
sudo dpkg -i ../linux-image-debug-*.ddeb
Now, reboot the system and type "uname -r" to verify it is the kernel you built.


References:
http://linuxtweaking.blogspot.com/2012/08/ubuntu-1204-lts-kernel-compile-guide.html
https://help.ubuntu.com/community/Kernel/Compile
https://wiki.ubuntu.com/Kernel/BuildYourOwnKernel
http://www.howtoforge.com/kernel_compilation_ubuntu
http://www.howtogeek.com/howto/ubuntu/how-to-customize-your-ubuntu-kernel/

Ending picture today:
The Space Shuttle Enterprise at Smithsonian's National Air and Space Museum's Steven F. Udvar-Hazy Center. (Discovery replaced Enterprise to display at this museum since April 2012. Enterprise is at the Intrepid Sea, Air & Space Museum now.) [courtesy of my dear wife - Claire Huang]


No comments:

Post a Comment