How to recompile kernel?

How to compile a kernel on a CentOS server?

Compiling a kernel on a CentOS server is probably easy than other Operating Systems but still you should take care while selecting modules else the server won’t boot up on the new kernel. New System admins find it difficult to compile a kernel, however, the following steps should help them a bit.

1) Download the kernel:

cd /usr/local/src/
wget http://www.kernel.org/pub/linux/kern…x.xx.xx.tar.gz

2) Extract the kernel:

tar -zxf linux-2.xx.xx.tar.gz

3) Here you can use previous config during compilation and select the new required modules:

cd linux-*
cp /boot/config-`uname -r` .config

This will copy the current kernel config in the extracted directory of the new kernel.

4) Now configure the kernel using “make menuconfig”. It will present a graphical display with all the available modules.

make menuconfig

Most of them are already selected since you are using the previous config. You need to make sure you select the new modules for example, the ones related to iptables. Each module provides a HELP module which will help you to understand what the module is all about.

5) Compile the kernel:

make

6) Compile the modules:

make modules

7) Install the modules:

make modules_install

8 ) Install the kernel:

make install

This will place the required files of the new kernel under the /boot directory.

Now, the /etc/grub/grub.conf file will have “default=1” where, ‘1’ is the old kernel. You now need to change “default” value to ‘0’ i.e. from

default=1
to
default=0

Save the file and reboot the server. The server will boot up with the new kernel. However, if the kernel is not compiled properly, your server won’t come online and you will have to change the “default” value back to ‘1’ to boot the server using a single usermode and investigate the issue further.

To overcome this issue, you can use the following steps to test the new kernel.  Once you complete the kernel installation using the “make install” command, execute the command:

root@server[#]# grub

At the grub prompt, execute:

savedefault –default=0 –once
quit

You now need to reboot the server to pick up the new kernel just once i.e. even if the server won’t boot up on the new kernel, you just need another reboot and the server will come online on the old kernel. This will save time and will allow you to work immediately on the issue.

This entry was posted on Friday, November 20th, 2009 and is filed under Linux Administration. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

Comments are closed.