0

Compiling A Kernel

Posted by Ennosuke Ajibana on Thursday, November 09, 2006
Meant to post this a couple of days ago but got caught up into some heavy loads of workzzz...

This is just an another style of updating/compiling the kernel. It's based on Ubuntu (btw, I've just received my free ubuntu cds today!) so basically, other debian-based distros could use the same steps. Why do we have to compile/update our kernel? Just simply to look more 'macho' and bring out the real man in us. So, here goes..

1st thing's 1st:

$su
#apt-get update


Then, the toolz

#apt-get install kernel-package libncurses5-dev fakeroot wget bzip2


After that, the KERNEL. Select your desired kernel version (for my example 2.6.18.1 which is in the
.bz2 format). Change to /usr/src and wget your kernel.

#cd /usr/src
#wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.18.1.tar.bz2


Unpack the package, create a symlink (optional for easy 'cd'ing)

#tar xjf linux-2.6.18.1.tar.bz2
#ln -s linux-2.6.18.1 linux
#cd /usr/src/linux


Now, if you have to patch your kernel with some err... patches, you do it like this : (make sure the patch is in the /usr/src/ dir)

#bzip2 -dc /usr/src/patch.bz2 | patch -p1 --dry-run
#bzip2 -dc /usr/src/patch.bz2 | patch -p1

ok, you don't have to run both of the above commands. the 1st one is just to test if everything will be ok. if it doesn't return any error, then you can proceed to the second command (without the --dry-run)

The first command is just a test, it does nothing to your sources. If it doesn't show errors, you can run the second command which actually applies the patch. Don't do it if the first command shows errors!

You can also apply kernel prepatches to your kernel sources. For example, if you need a feature that is available only in kernel 2.6.19-rc4, but the full sources haven't been released yet for this kernel. Instead, a patch-2.6.19-rc4.bz2 is available. You can apply that patch to the 2.6.18 kernel sources, but not to kernel 2.6.18.1 or 2.6.18.2, etc. This is explained on http://kernel.org/patchtypes/pre.html

Prepatches are the equivalent to alpha releases for Linux; they live in the testing directories in the archives. They should be applied using the patch(1) utility to the source code of the previous full release with a 3-part version number (for example, the 2.6.12-rc4 prepatch should be applied to the 2.6.11 kernel sources, not, for example, 2.6.11.10.)

So if you want to compile a 2.6.19-rc4 kernel, you must download the 2.6.18 kernel sources (http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.18.tar.bz2) in step 3 instead of kernel 2.6.18.1!

This is how you apply the 2.6.19-rc4 patch to kernel 2.6.18:

#cd /usr/src
#wget http://www.kernel.org/pub/linux/kernel/v2.6/testing/patch-2.6.19-rc4.bz2
#cd /usr/src/linux
#bzip2 -dc /usr/src/patch-2.6.19-rc4.bz2 | patch -p1 --dry-run
#bzip2 -dc /usr/src/patch-2.6.19-rc4.bz2 | patch -p1


It's a good idea to use the configuration of your current working kernel as a basis for your new kernel. Therefore we copy the existing configuration to /usr/src/linux:

#cp /boot/config-`uname -r` ./.config


Then we run

#make menuconfig


which brings up the kernel configuration menu. Go to Load an Alternate Configuration File and choose .config (which contains the configuration of your current working kernel) as the configuration file.

Then browse through the kernel configuration menu and make your choices. When you are finished and select Exit, answer the following question (Do you wish to save your new kernel configuration?) with 'Yes'.

This is the fun part - build your kernel:

#make-kpkg clean
#fakeroot make-kpkg --initrd --append-to-version=-dreamb0x kernel_image kernel_headers


After --append-to-version= you can write any string that helps you identify the kernel, but it must begin with a minus (-) and must not contain whitespace.

Now be patient, the kernel compilation can take some hours, depending on your kernel configuration and your processor speed.

After the successful kernel build, you can find two .deb packages in the /usr/src directory. After that, you can 'cd' to that dir and do your installation (#dpkg -i bla..bla..bla) of both the linux-image and the linux-headers. You can also transfer both the .deb packages to other computer.

Reboot your system and do a 'uname -r' to show the world how macho you are now with your new kernel freshly baked in your own room...

Ok, so more than half of this tutorial I've actually snatched from here. Enjoy it anyway...!

0 Comments

Copyright © 2009 ~/blog All rights reserved. Theme by Laptop Geek. | Bloggerized by FalconHive.