Eu buntu nix

Google
 
Web Eu Buntu nix

Tuesday, May 09, 2006

How-To: Compile a Linux Kernel

Author: Puru Govind
Date: Monday, 08 May 2006
Topic: Featured Story

(Review) - According to Wikipedia.org, "the kernel is the core piece of most operating systems. It is a piece of software responsible for the communication between hardware and software components. As a basic component of an operating system, a kernel provides abstraction layers for hardware, especially for memory, processors and communication between hardware and software. It also provides software facilities such as process abstractions and makes interprocess communication easier."

Now that I have written so much about Linux kernel, I realize that many people reading those articles do not even know how to compile them. There are obviously many reasons why you need to compile your Linux kernel, such as:

- To patch your kernel.
- You have a university assignment.
- You are doing a course "Linux Kernel" as an undergraduate.
- You have coded your own device driver a device that isn’t supported yet.
- You think that there is some better way of process scheduling or memory management technique and you want to implement it.
- To try a new version of Linux kernel.

To start, you should have kernel code to compile (a fairly logical step). You can download it or copy it from /usr/src directory, make modifications and save it back to some directory.

Then, if you have ncurses installed on your system and working on normal console, type in "make menuconfig," or "make xconfig" if you are using X server.

Whatever you type in, you will be presented with a box with numerous yeses, so to speak, but no options. It asks the user to input a number of options. If he chooses yes, then that functionality would be compiled right into the kernel. This makes its execution quite faster. If you choose module as your option, then that functionality will be compiled as a module. For example: you can make your sound card or printer drivers as modules, but you can’t make your memory manager or file system a module. These things must be compiled into the compiler. After you get over with this, save the configuration and run make dep. These will resolve all dependencies needed to compile the Linux kernel. According to James Andrews in one of his articles, make dep builds the tree of interdependencies in the kernel sources. These dependencies may have been affected by the options you have chosen in the configuration step.

After make dep, you need to type in ‘make clean.’ This will remove all old object files and will take little time compared to other steps.

After this, you need to do make bzImage. This will rename your kernel to bzImage and gets stored in /usr/src/linux/arch/i386/boot/bzImage. The current kernel is generally /boot/vmlinuz. You must copy your new kernel to the /boot directory and give it a new name. For example, you can put the following:

cp /usr/src/linux/arch/i386/boot/bzImage /boot/vmlinuz-2.6.xx

Make bzImage will take lot of time compared to other steps. On my AMD 2100+ system with 256MB of RAM, it took 18 minutes.

You are coming near the final destination. You now need to "make module" and "make module_install" after this. This statement will install all modules in directory /lib/modules. Next, edit /etc/lilo.conf to add a section:

image = /boot/ vmlinuz-2.6.xx

label =MyKernel

read-only

Run LILO after this. This will update your LILO boot loader. At the next reboot, select the kernel ''MyKernel" from the LILO list; and it will load your new kernel.

So, isn’t it easy to recompile your kernel? I advice you to make a boot disk before you do anything silly with your kernel. And also remember to never modify or recompile kernel at /usr/src/linux kernel version.

0 Comments:

Post a Comment

<< Home