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 126.96.36.199) installed on the server:
1. Download the kernel to the server:
2. Unpack the archive and create a symlink:
tar -zxvf linux-188.8.131.52.tar.gz
ln -s /usr/src/linux-184.108.40.206 /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/ :
Apply the patch:
bzip2 -dc /usr/src/patch-220.127.116.11.bz2 | patch -p1 --dry-run
bzip2 -dc /usr/src/patch-18.104.22.168.bz2 | 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).
make clean && make mrproper
cp /boot/config-`uname -r` ./.config
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 modules && make modules_install
default=1 -> default=0
5.2 If you just want to create an rpm and to install it later:
5.2.1 You now have to install the kernel:
rpm -ivh --nodeps kernel-22.214.171.124custom.i386.rpm
mkinitrd /boot/initrd-126.96.36.199-custom.img 188.8.131.52-custom
default=1 -> default=0
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.