How to build your own custom kernel (Ubuntu/Debian style)
This topic can be found on the net with the millions, but this doesn’t mean I can’t write about it.
In this post I will try to explain or give a HOW-TO on building your own custom kernel, exactly how I do it myself. To do this you do not really need a lot of knowledge, but still you need to know what you want from you newly build kernel.
Usually when someone tries to build a custom kernel, he/she does it for improving the speed, stability of its own system and of course maybe to enable some new features and fix some bugs which weren’t or aren’t done in the original kernel which came with the distro. For each distro there is a way to build the kernel, for example if you wanna build your own custom kernel for Fedora, the way which I will write here wont work at all for Fedora and most likely for any non-Debian distro. So this means that for each mainstream distro you will have to do it differently or using other tools, at least.
Before we even start we need to make sure that we have the necessary tools and package to be able to build our own kernel. This means that we need to first install some packages from the Ubuntu/Debian repositories and then download the latest version of kernel (the kernel source). After this steps are done, we will need to configure our new kernel, well we don’t really need to, but we should, otherwise building a custom kernel wouldn’t have a lot of point, besides bug fixing…
Lets say, we did all the steps above, now it remains only the build of the kernel and installation. This last two steps are easy, as we just need to wait for the build and installation package generation. The newly generated packages which come from the build we will install them using dpkg.
Start (install necessary packages using apt-get):
sudo apt-get install fakeroot build-essential makedumpfile libncurses5 libncurses5-dev kernel-package
Setup the environment (remove sh link, setup /etc/kernel-pkg.conf):
sudo rm -f /bin/sh; sudo ln -s /bin/bash /bin/sh (in case of Ubuntu this is a good idea, as by default sh is linked to dash, which can create some issues)
sudo nano /etc/kernel-pkg.conf ( edit this file and modify maintainer and email to your own information, this is not mandatory)
Get the kernel source (get the kernel source code from kernel.org and unpack it):
wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.30.tar.bz2
sudo mv linux-2.6.30.tar.bz2 /usr/src
cd /usr/src
sudo tar -xjvf linux-2.6.30.tar.bz2
sudo ln -s linux-2.6.30 linux
Get config file for the new kernel:
cd /usr/src/linux
cp -v /boot/config-$(uname -r) .config
Reconfigure the kernel (this is not necessary, only if you want to disable/enable some parts of the kernel):
cd /usr/src/linux
sudo make menuconfig
sudo nano Makefile (to set a new version, you can edit SUBLEVEL and EXTRAVERSION, only in case you want to, as we do not use the version with make-kpkg)
Build the kernel:
- set concurrency level (useful when u have multiple cores/cpus for faster kernel build):
export CONCURRENCY_LEVEL=`expr $(cat /proc/cpuinfo |grep -i ‘MHz’|wc -l) + 1`
- clean up the kernel source code:
cd /usr/src/linux
sudo make-kpkg clean- build the kernel:
export REV=1 (set the revision number, can be any number from 1..10000000)
sudo fakeroot make-kpkg –initrd –revision=${REV} kernel-image kernel-headers kernel-source
Install the new kernel:
cd /usr/src
sudo dpkg -i linux-headers-2.6.`you own version`_`your own revision`_`ARCH`.deb linux-image-2.6.`you own version`_`your own revision`_`ARCH`.deb
As you can see, it’s not a big deal, it will take quite some time until all the build goes thru, as it depends on the speed of your network (downloading the kernel source) and the speed or specs of your computer. Anyway, this small explanation works for me, this is the way I build a new kernel and it just works perfectly. Of course this doesn’t mean you need to do the same, but let’s say it can help you, if you are a beginner in the kernel building ![]()
Wish you good luck and let me know if you are missing something… or if I made some mistakes ![]()