Tuesday, May 13, 2008

Compiling Linux Kernel 2.6

A Google search on “HOWTO compile linux kernel” will give you 1,160,000 pages in 0.23 seconds. Yet when I was stuck with one of my assignments, none of those pages (that is, top 20 of them.. nobody goes beyond that anyway!) contained everything that I was looking for. This simple-how-to (S-HOWTO) aims to summarize the basic minimum steps required, leaving the details to the interest of an individual.

The example taken here is to add NTFS support (read/write) to the linux kernel. The kernel version I’ve worked on is 2.6.19.1, on i386 architecture (though this should be fine for any 2.6.x and other architectures)

1. You can either work on your existing kernel, provided you’ve installed it with source; or you can download the latest kernel tar ball from www.kernel.org

2. In case you’ve downloaded, untar the package in the /usr/src dir, using the command -

$> tar xvjf linux-2.6.19.1.tar.bz2

3. This step is not required in your first try, but in the subsequent experiments, you should probably clean up your earlier changes by using -

$> make mrproper

4. To enable NTFS support, type -

$> make menuconfig

In the menu display that comes up, navigate through - File Systems ---> DOS/FAT/NT Filesystems. Select NTFS file system support and press ‘Y’. Press ‘Y’ for debugging support and/or write support based on your requirements.

5. In general, you can navigate though all the options and make whatever changes that you want. To know about a particular option, select it and press ‘?’ to see the description.
Or use 'make defconfig' to get the default configuration (according to some rumours, these are Linus Torvalds' configuration :) )

6.
Use to come out of the menu. Press “Yes” when it prompts to save the changes.

7.
The next step is – make

8.
If you have not added/removed/modified any module (that is, if you have not touched anything with a ‘M’ on it) you can simply write – $> make vmlinux (this would just compile the kernel)

Conversely, if you have just modified the modules, and not changed anything with a ‘*’ marked on it, write –

$> make modules (this would just compile the modules)

A simple ‘make’ does ‘make vmlinux’ followed by ‘make modules’.
Note: ‘make dep’ is not required (as it was with 2.4.x kernels)

9. If you have touched the modules (i.e. used ‘make’ or ‘make modules’) write –

$> make modules_install (This installs the modules in /lib/modules/2.6.x.y directory)

10. Last step is -

$> make install


This step does the following things:

a.
Creates a bzImage of the compiled kernel (in arch/i386/boot/ dir)
b.
Copies that iamge to /boot dir (renames it as vmlinuz-2.6.x.y)
c.
Creates the initrd (initial RAM disk) image and stores it in the /boot dir
d. Creates the System.map file (mapping modules to their memory location) in the /boot dir
e.
Modifies the grub.conf/lilo.conf


Reboot, and select the new kernel version while booting. Tathastu!
Xtra:
What is initrd?
Why is initrd required?

No comments: