But having said that I am not trying you to get scared of it or keep you away from to get the best out of your own GNU/Linux distro as per your liking.
In this article I will step you through the process that how can build your own kernel step by step and installed it ..later use it .
I do not issue any guarantee that this will work for you.
I have pick up three distribution for this purpose; the peoples choice comes first as Ubuntu. Then a bit mid way distribution for geek and normal people ;called openSUSE. And finally the my favorite and source based one called Gentoo.
Now a very important point :why would anyone want to compile a kernel??(I have had the experience to hear from newbie administrator and GNU/Linux enthusitst that they want to compile the kernel; because they want to show the world that they know GNU/Linux more then anybody else) ,which is an absolute bogus and rubbish idea ...only expect from those who jump from different stream or just want to be highlighted by saying " I am a Linux guy".
Compiling kernel should be necessary if and only if the below thing one wants:
- The stock kernel doesn't provide the feature that they want.
- You should know what you are trying to do with the kernel.
- If you are an avid kernel developer looking inside the kernel offering.
- If you want fix some kernel related problem by enabling a debug feature in the kernel.
- Some specific hardware feature want to activate so the underlying hardware react properly.
- you should have the capability or knowledge iff something goes wrong after compilation of the kernel can bring back the system in previous pristine mode to function it properly.
Compiling kernel in Ubuntu way( Intrepid, Jaunty, and Karmic):
Get the kernel source from the www.kernel.org .Whatever the version you want to compile;stable version would be a better choice.
open a terminal and fire the below command
sudo apt-get install fakeroot kernel-wedge build-essential makedumpfile kernel-package
The linux-kernel-devel does not exists in intrepid,jaunty and newer version.For that reason to compile the kernel also need to run:
sudo apt-get build-dep linux
You might get the kernel source in ubuntu way like this:( for Hardy,intrepid Ibex,Jaunty)
sudo apt-get build-dep --no-install-recommends --only-source linux
For Kermic Koala:
sudo apt-get build-dep --no-install-recommends linux-image-$(uname -r)
apt-get source linux-image-$(uname -r)
Now you have to modify the source config file of the downloaded kernel..so lets find the that file
Ubuntu store this file /debian/config/ARCH or for newer release it is in debian.master/config/ARCH
You can get a snapshot of that particular dir like this
ls -l debian/config/i386/
-rw-r--r-- 1 root src 73962 2007-08-13 01:29 config
-rw-r--r-- 1 root root 1369 2007-08-13 01:29 config.386
-rw-r--r-- 1 root root 1330 2007-08-13 01:29 config.generic
-rw-r--r-- 1 root root 1395 2007-08-13 01:29 config.server
-rw-r--r-- 1 root root 1756 2007-08-13 01:29 config.server-bigiron
-rw-r--r-- 1 root root 8 2007-08-13 01:25 lowlatency
-rw-r--r-- 1 root root 194 2007-08-13 01:25 vars.386
If you don't find the file then search in /boot section of tree.
Now change the config file according to your choice ...once done then please do the following
yes that is a command you have to fire once you are done with the config file.That command reside in debian/scripts/misc
Now you have run the below command in the source dir of the downloaded kernel:
You have to take the current configuration file as the basis of the new one. So doing so..
cp /boot/config-`uname -r` ./.config
It will open up an tui window full of options to choose from.Once you finish the your selective session with that
dialog window( you have manuvaour to with TAB key to move and spacebar to select).
Then go to bottom of that window and select " Load an alternate configuration file" opention and enter
Then press "ok" to save the config file.
Once done the previous steps ..so you have your own custom config file for the kernel. Now time to build the kernel
Do it in the terminal:
$ make-kpkg clean
$ fakeroot make-kpkg --initrd --append-to-version=-custom kernel_image kernel_headers
Now here you need bit of explanation of the "--append-to-version" thing..which can be selected from the
previous step when the window came select it from "general section" (top of the window option) and
it should start with a "-" minus signto separate form the kernel version number.
Now please help yourself to get a cup of coffee and relax..it will take some to compile the kernel to build .deb file for your system.
After the sucessfull build you can find the .deb file in /usr/src
there should be two file ;one for linux-image and another for linux-header..install both of them
dpkg -i linux-image-188.8.131.52-custom_184.108.40.206-custom-10.00.Custom_i386.deb
dpkg -i linux-headers-220.127.116.11-custom_18.104.22.168-custom-10.00.Custom_i386.deb
You have to put an entry in the grub(the bootloader) conf file to get it booted.
You can find more detailed description of it here : http://howtoforge.com/kernel_compilation_ubuntu_p2 and here: https://help.ubuntu.com/community/Kernel/Compile
Compiling the kernel openSUSE way:
Get the kernel source from the www.kernel.org ; whatever the version you want to compile;stable version would be a better choice.
Now get the required package for kernel build
yast -i ncurses-devel
This package will help to get the "make menuconfig" dialog to appear in terminal.
Now you need to get some backup and modify the few tool to get kernel compile properly.Otherwise it
won't allow us to install the kernel rpm in the system.
cp /usr/lib/rpm/find-provides.ksyms /usr/lib/rpm/find-provides.ksyms_orig
cp /usr/lib/rpm/find-requires.ksyms /usr/lib/rpm/find-requires.ksyms_orig
cp /usr/lib/rpm/find-supplements.ksyms /usr/lib/rpm/find-supplements.ksyms_orig
Then we open each of these scripts and replace kernel-*) is_kernel_package=1 ;; with kernel*) is_kernel_package=1 ;;:
Now go to the kernel source dir(where you unpack the kernel source tree) make a symlink to the "linux"
dir with the unpacked kernel source tree.
ln -s linux-22.214.171.124 linux
cp /boot/config-`uname -r` ./.config
Select "Load an alternate configuration file" and save by pressing ok.
It is important to have different version for your custom kernel ..for that you need to the "general setup" option of and select the second entry started as default.
You must start with a "-" with your choice of name and save it when promted.
Now build the rpm for the system:
Please be patience ..it will take some time to compile the rpm( mostly about the choice you made)
You can view the source rpms here :
ls -la /usr/src/packages/SRPMS/
For the actual kernel rpm look in here:
ls -al /usr/src/packages/RPMS/i386
Get into the above dir and install the kernel;
rpm -ivh new-customized-kernel.rpm
Now create the initrd image to boot the system for the new kernel. For that
Now configure the boot loader grub to boot new kernel.
For that edit the /boot/grub/menu.lst and put a stanza like below;
root (hd0,0) ----> depend where you load the boot loader
kernel path_to_the_kernel_img_file(usually /boot/
initrd path_to_the_initrd_img_file (usually in /boot
Save it and reboot and enjoy the new kernel.
Compiling the kernel in Gentoo way:
You can get he kernel source two ways in Gentoo. First as normal to get the .bzip from the kernel.org
Second is the gentoo way
sudo emerge -av gentoo-sources
Go to the /usr/src/ dir ,where the new kernel reside and make a link to the linux dir with the new
kernel unpacked dir.
ln -s linux-new-source linux
Then as usual
select the options you need.You can stright way copy the .config file from the previous kernel source tree to the new one.
cp -v old-kernel-dir/.config new-kernel-dir/
You can compile kernel in two different way in Gentoo.
First is the tradition way and elaborate way ;like in above menthod (make menuconfig;make;make module_install, make install) or
Gentoo provide an easy way to hide the scrolling kernle compilation msg on the screen by using a tool called "genkernel",which essentially does the same thing.
For using the genkernel method ..you need to install it first like this:
sudo emerge -av genkernel
once install ... you are ready to use it.
Go to the specified kernel source dir and fire:
genkernel # without any argument
genkernel --save-config --install all
Now a bot of explanation of second command: the option "--save-config" saves a kenerl config file in
/etc/kenerl/kernel-version.config ,which you can use later and view.
Next option "--install" instruct the genkernel to install the kernel in the system .
Then option "all"...which define all the steps require to compile the kernel i.e make ,make module_install
make bzImage install make initrd or ramfs images
All will be done in the backgroud..no scrolling out put on the terminal.If you are really curious about the ongoing thing
You can have a look at the /var/log/genkernel.log file for the compilation process.
It will create less noise but it will take long .
Hope this guide will help.