How to Compile and Add a Kernel in Linux

 

* There is no warranty or such on these instructions, as always, each system is different and although these steps have worked time and time again, the token disclaimer is that this must be used at one's own risk.

Steps

1). Visit http://www.kernel.org and download a kernel of your choice (I use tar.bz2 files) and save it to a directory of your choice. I will use /home/kernel for this example.

Note - There have been issues with certain kernels and compatibility with certain compilers. If you are using an up to date compiler, please consider using a recent kernel if you are having issues with compiling the kernel itself.

2). Now you need to copy the kernel over to the /usr/src directory or wherever you would like to do your kernel builds. In order to do this, you need to open your terminal and get root permissions. Then you can use the cp command to move the kernel over:

cp /home/kernel/nameofkernel /usr/src

3). Once the kernel is copied over to that directory you can then extract it. To extract it, this command can be used:

cd /usr/src/
tar -xvjf nameofkernel

*you should then see a lot of scrolling in the terminal, showing that files are being extracted. If you do not see this then you need to go back and verify the previous steps.

4). The you can enter the directory of the kernel itself:

cd /usr/src/nameofkerneldirectory

*Option - you can copy over a config file if you like (if you don't know what I mean, then just proceed)

5). Next, you need to select the options for your kernel menu. You can do this by entering the menu using this command:

make menuconfig

* You should see a small menu open within your terminal. I cannot go into what selections you should make as everyone has different hardware. Some things of note are: selecting the correct filesystem (ext3, reiser etc.), selecting the correct sound card drivers and network interface drivers. There are a lot more factors to consider but those are some that very common.

*for the 2.6 series kernel, you do not need to include any scsi emulation for your burner unless you want to use cdrdao (disk at once mode which is needed for bin/cue files for example).
*also in the 2.6 series, I had to include the following options under file systems - pseudo file systems or else it would not boot fully (kernel panic):

[*] /proc file system support
[*] /dev file system support (OBSOLETE)
[*] Automatically mount at boot
[ ] Debug devfs
[*] /dev/pts file system for Unix98 PTYs
[*] /dev/pts Extended Attributes
[*] /dev/pts Security Labels
[*] Virtual memory file system support (former shm fs)
[ ] HugeTLB file system support

Yours may work without those options, but mine would not. I am especially referring to the top two options there.

Also, with 2.6 if you get error when you are trying to use your terminal, it may be fixed by inserting this line into your /etc/fstab:

none /dev/pts devpts defaults 0 0



A special feature to this page is THE INTERACTIVE KERNEL MENU - check it out:





It gives lots of examples of what you can compile in so that you can get your kernel working - * it is for the 2.6.0 kernel. NOTE - More specific notes will be made soon on the individual menus.


6). Once you have finished making your selections, you can press the esc key until it asks you to save your configuration. When that is done, it is time to actually compile and make the kernel.

7). In order to compile and make the kernel (steps may differ and some may be unnecessary, but I will provide them all and if some are not required, the output of the terminal will indicate as such usually. So here are the commands:

*I am doing these all separately to ensure accuracy

make dep (not always necessary)
make clean
make bzImage
make modules
(sometimes not necessary with newer kernels)
make modules_install (sometimes not necessary with newer kernels)

*next comes a very important step - copying the kernel to your /boot directory. The most important thing to remember about this is that you do NOT want to overwrite your other working kernel if you are adding a kernel to your system. So you need to choose a different kernel name for this new kernel. The following is an example of one I recently did:

cp /usr/src/linux-2.6-test7/arch/i386/boot/bzImage /boot/linux-2.6-test7

*One way to make sure you are copying the right bzImage is to use the tab key to autocomplete the directories in the first part of that command. If something does not autocomplete, then double check to make sure you are going into the right directory.

8). Once that is done, you will then need to add lines in your bootloader in order to be able to boot the kernel. If you are using lilo make sure you run it afterwards for the changes to take effect. I use grub so I do not need to run it, changes take effect as soon as I save the file. Here is an example of what I added to my grub configuration (may be found in /etc/grub.conf or /boot/grub/menu.lst):

title Linux Distro Name
root (hd0,2)
kernel (hd0,2)/boot/linux-2.6-test7 ro root=/dev/hda3

*this is just a sample.

9). Reboot your computer and try to boot your kernel.

10). Parts A and B

A) If it doesn't work, you are likely missing something from your make menuconfig. Make a note of any errors that the kernel gives you when trying to boot so you can get assistance and troubleshoot.

B) If it works fine... GLOAT! :)