Wednesday, September 10, 2008

Compiling the newest Linux kernel

This semester I'm taking an advance operating system course and as part of my first assignment I have to hack the newest Linux kernel to provide a new system call that based on Intel architecture (32 bits). I have never hacked a Linux kernel before and this assignment has opened a quite unique experience for me.

How do you compile Linux kernel 2.6.26.6

0. Before starting check whether your /boot file system is ext3. If not you might end up with a lot of custom configurations, which I haven't mentioned here.

1. Get latest Linux kernel code.
Visit http://kernel.org/
wget http://kernel.org/pub/linux/kernel/v2.6/linux-2.6.26.5.tar.bz2


2. Extract tar (.tar.bz2)
tar xvjz linux-2.6.26.5.tar.bz2 -C /usr/src/linux-2.6.26.5

3. Configure kernel

Before doing anything else, you need to have development tools on your system. If you are using a Debian distribution you need lib6c-dev and libncursesw5-dev

Change the directory to /usr/src/linux-2.6.26.5

You have three options to get started
* make menuconfig - Text based color menus, radiolists & dialogs. This option also useful on remote server if you wanna compile kernel remotely.
* make xconfig - X windows (Qt) based configuration tool, works best under KDE desktop
* make gconfig - X windows (Gtk) based configuration tool, works best under Gnome Dekstop.

I like,
make menuconfig

4. Compile kernel

Start compiling to create a compressed kernel image
make

Start compiling to kernel modules
make modules

Install kernel modules
make modules_install

5. Install kernel

So far we have compile module and installed kernel. Let's install kernel,
make install

After that change directory to /boot, you will be able to observer,
System.map-2.6.26.5
config-2.6.26.5
vmlinuz-2.6.26.5

6. Create initrd image
cd /boot

mkinitramfs -o initrd.img-2.6.26.5 2.6.26.5

7. Modify Grub configuration file - /boot/grub/menu.lst
cd /boot/grub

update-grub

Update grub is a cool way to edit the file automatically. One could use LILO instead of GRUB. Though the update utility do the job for us, it wont set the initrd. Hence,

vi /boot/grub/menu.lst

## ## End Default Options ##

title Ubuntu, kernel 2.6.26.6 Default
root (hd0,0)
kernel /vmlinuz root=UUID=c45bb5a8-11b8-4d03-aec4-4c4f070edae6 ro quiet splash
quite

...

and change it to

## ## End Default Options ##

title Ubuntu, kernel 2.6.26.6 Default
root (hd0,0)
kernel /vmlinuz root=UUID=c45bb5a8-11b8-4d03-aec4-4c4f070edae6 ro
initrd /initrd.img-2.6.26.5
savedefault
boot

...

Please note that "root" will change according to your configuration

8. Reboot computer and boot into your new kernel

reboot

Next time I'll tell you how to add a system call with a little bit of theory. Have fun!

No comments: