Saturday, February 2, 2008

Linux 2.6 kernel compilation for ubuntu

This is the procedure for compiling the Linux 2.6 kernel in Ubuntu 7.10. But in almost all systems, it is almost same procedure. In ubuntu , by defaull there is no root user. So, always use sudo -s before executing the following commands.

First step is to get the latest kernel source (or whichever you want) from kernel.org to /usr/src. I used linux-2.6.23. Now untar the source using:

tar -xjvf linux-2.6.23.tar.bz2 -C /usr/src/linux-2.6.23.


Go inside the source foder : cd /usr/src/linux-2.6.23. Assuming that you have installed gcc already. Now we have to conbfigure the kernel for building. There are different commands for that. But the easy and useful one is make menuconfig. Ubuntu uses a configuration mechanism using ncurses package. So, it may give some errors. We have to install ncurses and the depending packages.

sudo apt-get install ncurses
sudo apt-get install ncurses-developer
sudo apt-get install libncurses5-dev

Then make menuconfig will result in the menu based configuration. Here we have to select all configuration carefully. But help is very good. So, it is easy.

Now, compile the kernel using make command. it will take about 1 hour, depending on our configuration. Now install all the modules using make modules_install.

Finally, we can install the kernel using make install. It will install three files in the /boot directory.

System.map-2.6.23
config-2.6.23
vmlinuz-2.6.23

So, kernel is built. So, now we have to create the initrd image( This is needed to load the rest of the OS in some systems) using the command mkinitrd -o initrd.img-2.6.23 2.6.23.

mkinitrd is replaced with mkinitramfs in the latest systems. In that case use the command mkinitramfs -o initrd.img-2.6.23 2.6.23.

Now, bootloader should be configured to detect our new kernel. If you are using GRUB, update-grub command will update it automatically. But from my experience it is better to update manually. Because i used update-grub. But it is updating the kernel root device using the UUID instead of /dev/sda6 in menu.lst file.But after rebooting my system did not boot, because some GRUB versions will not understand UUID. I had to change UUID to the corresponding root device. In my case it was hd0,5. So changed it as /dev/sda6, by manual editing by pressing 'e', when GRUB menu appears.

So, better change the Grub configuration file as follows.

vi /boot/grub/menu.lst

Add the following lines in the file( Depending n your root device and kernel name.
title           Debian GNU/Linux, kernel 2.6.23 Default
root (hd0,5)
kernel /boot/vmlinuz-2.6.23 root=/dev/sda6 ro
initrd /boot/initrd.img-2.6.23
savedefault
boot
Now just reboot. Hopefully, our new kernel should be detected by GRUB and it should boot up ptoperly( Hopefully..). But not sure. But if the make menuconfig was correct and we added all needed device drivers into the kernel( Especially SATA driver), it will come up. Otherwise change some boot options manually, boot in to the system. Compile one more time with the correct make menuconfig.

No comments: