Tag Archives: how-to upgrade kernel

How-to build a new kernel – linux

Building akernel is not as hard as many may think it is actually pretty easy and stright forward of course if you know what you are doing, but after doing this a few times(even if you don’t get it right from the first time) you will see that everything looks easy.

In order to be able to build a new kernel you may need some extra packages like make, kernel-headers(if rebuilding) or C++ so if you get any errors that a package is needed or not installed just install it even by using apt-get(debian) or yum(redhat based) or by simply downloading and installing the package(harder way) .

If you want to build a new kernel(like build the latest kernel) you will need the new kernel source and this can be downloaded from kernel.org as the latest patches(if any or needed).

Lets say that we want to have the latest stable kernel(at this time installed on the server:

1. Download the kernel to the server:

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

2. Unpack the archive and create a symlink:

tar -zxvf linux-
cd linux-
ln -s /usr/src/linux- /usr/src/linux

3. You may need to apply some patches:

Download the patch(es) from http://www.kernel.org/pub/linux/kernel/v2.6/ :

cd /usr/src
wget http://www.kernel.org/pub/linux/kernel/v2.6/patch-

Apply the patch:

cd /usr/src/linux
bzip2 -dc /usr/src/patch- | patch -p1 --dry-run
bzip2 -dc /usr/src/patch- | patch -p1

First command will test the patch against the kernel files, don’t worry if you get a message saying that the patch is already existing as that just means that this is already applied and you did not need to do this step so just jump over the patching step.

4. Configure the new kernel and make modifications:

To make everything more simple we will use the already existing and working configuration of the kernel we are currently running and make modifications on it if needed, like adding extra hardware support or modules(for example adding Tarpit support).

cd /usr/src/linux
make clean && make mrproper
cp /boot/config-`uname -r` ./.config
make menuconfig

Running make menuconfig will open a new window where you will be able to see all available modules and make modifications if needed.
A good idea is to add another name to the kernel like “custom” and also remember to save the config at the end.

5. Build the new kernel:

5.1 If you want to build the kernel and also install it on the server follow this path:

make bzImage
make modules && make modules_install
make install
vi /boot/grub/grub.conf
default=1 -> default=0

5.2 If you just want to create an rpm and to install it later:

make rpm

5.2.1 You now have to install the kernel:

cd /usr/src/redhat/RPMS/i386/
rpm -ivh --nodeps kernel-
mkinitrd /boot/initrd-
vi /boot/grub/grub.conf
default=1 -> default=0

6. Reboot

If you want to make sure that your server will boot up even if the kernel crashes try and do the following instead of editing grub.conf (last 2 commands on 5.1 and 5.2.1):

savedefault --default=0 --once

Now reboot the server shutdown -r now and make sure everything is fine.
To check which kernel was booted run uname -r on the server.

If everything was done right you should have the latest available kernel installed on the server.