From Wiki

Linux: KernelDerleme


How to Compile a Kernel

First and foremost, THIS ( may pertain to you so read that first and then you can proceed and here ( is a similar site. Both links are for those migrating to a 2.6 series kernel from a 2.4.x kernel. [edit] Obtaining and installing the Kernel Source [edit] Getting the kernel source

To compile a kernel, you will need the kernel source. You can get it from ( Your distribution may also already come with the kernel source, somewhere on the cd. [edit] Installing the kernel source

You can install the kernel source by either installing the package that came with your distribution, or extracting the tarball you downloaded from .

1. Change Directory To /usr/src

cd /usr/src

2. Check for symlink (ex. /usr/src/linux->/usr/src/linux-2.4.18)

ls -alc

3. Double check with this command (output ex.) linux: symbolic link to linux-2.4.18-14

file linux

4. Remove the symlink

rm linux

5. Unpack the tarball (new kernel)

tar -zxvf linux-x.x.x.tar.gz tar -jxvf linux-x.x.x.tar.bz2

6. Make a new link to the new kernel

ln -s /usr/src/linux-x.x.x /usr/src/linux

7. Type this to change to the directory

cd linux

[edit] Installing the tool chain and header files needed to compile

Not all Linux distributions come with all of the components needed to build a kernel. You'll need a C compiler, make, and system header files installed before you can begin to build the kernel. [edit] Now Comes The Fun Part~! (compiling)

We will now compile the kernel.

First, clean up anything we don't need, like the current .config and other files

make mrproper

Do this is if you want to use your old configuration from the 2.4 kernel with the 2.6 kernel:

cp /usr/src/linux-2.4.x/.config /usr/src/linux

Now you configure your kernel using any one of these commands, whichever you like best:

Basic config from terminal, a long list of questions you answer

make config

For ncurses GUI in the terminal

make menuconfig

For X-based GUI with modular explanations (QT Based)

make xconfig

Same as above, but for 2.6.x kernel only (GTK Based, and might be still buggy)

make gconfig

Note: Don't forget to add module support and kernel support for future hardware. Do not compile your hard drive and file system type as a module. The configure program enables you to specify an enormous number of features. It is advisable to skim through all the sections to get a feel for the different things you can do. Most options are about specifying whether you want a feature [*] compiled into the kernel image, [M] compiled as a module, or [ ] not compiled at all. You can also turn off module support altogether from Loadable module support -->. The kernel configuration is one LINUX program that offers lots of help--select < Help > on any feature. The raw help file is /usr/src/linux/Documentation/ can be also worth reading. When you're done with the config, click exit and save current configuration. Your file is now known as .config . >SKIP THE FOLLOWING IF DOING A 2.6.x KERNEL<------

make dep "Ensures dependancies such as include files are in place"

(vi, pico, emacs) Makefile "Want A Unique Kernel Name? Edit /usr/src/linux/Makefile and change EXTRAVERSION"

make clean "To clean your sources so they compile correctly" >START HERE IF COMPILING A 2.6.x KERNEL<------

make bzImage "To make the kernel image (compile and creates compressed image of kernel)"

make modules "Compile your selected modules"

make modules_install "To install newly compile modules (installs to /lib/modules/linux.x.x.x)" [edit] Now It's Time To Install Your New Kernel~!

Remove the following links: rm -rf /boot/ rm -rf /boot/vmlinuz

Then copy the newly created kernel and to /boot cp /usr/src/linux/arch/i386/boot/bzImage /boot/vmlinuz-x.x.x cp /usr/src/linux/ /boot/

Make the new links: ln -s /boot/vmlinuz-x.x.x /boot/vmlinuz ln -s /boot/ /boot/

Next, if present, remove existing initrd.img file: rm -rf /boot/initrd.x.x.x.img

And create the new one: /sbin/mkinitrd /boot/initrd-x.x.x.img x.x.x (Note: ) The last set of x.x.x is the eqivalent to your new kernel version and it looks to /lib/modules for that version.

Use The Steps That Pertain To You If You Use Grub Then Edit grub.conf If You Use Lilo Then Edit lilo.conf

remember to leave the entry to your old kernel image just in case, so modify what is in the config originally to point to the old image and make a new entry for you new image you just made ....

<-> And Finally Edit Your /etc/grub.conf file <-> <-> Note some distros now use menu.lst, so if you can't find grub or lilo, then you know what to look for <->

title New Kernel :D kernel /vmlinuz-x.x.x ro root=LABEL=/

       initrd /initrd-x.x.x.img

(Note: ) Look at the previous parameters in the grub.conf file and note what "root=" and use what is existing.

Exit and Save grub.conf type "/sbin/grub-install"


<-> And Finally Edit Your /etc/lilo.conf file <-> image = /boot/vmlinuz-x.x.x

          label = New Kernel :D
          root = /dev/hdx

(Note: ) look at the previous parameters in the lilo.conf file and note what "root =" and use what exists.

Exit and Save lilo.conf type "/sbin/lilo"


/EDIT By request: the instructions on how to apply patches to your kernel. END EDIT/

read this ( or look below ...

This step comes after untarring your kernel source. When you download the patch, place it in the folder where you untarred your new kernel. Then type: patch -E -p1 < sound_patch Purely an example and you would type whatever the file name is in replace of sound_patch.

Regarding having alternative boot options, this is no problem. The stuff above that I tell you to add to your lilo or grub file above could just be appended to the file, and you could just add ".old" to the title of your original kernel name for you will know the difference. Whether it's grub or lilo, add "read-only" to the end of the original entries in the lilo.conf, or grub.conf, file. [edit] Special notes for Debian Users

Debian has some utilities to make your life a little easier. The kernel-package set of utilities allows to to create your own kernel package. For most users, this just means that your kernel shows up like all other debian packages. However, if you have multiple machines running the same kernel, it allows an easy way to install it on all of them. So let's get started.

First, make sure you have the kernel-package tools. You can install them with the command apt-get install kernel-package.

The initial steps are the same, make clean, make menuconfig (or xconfig etc...). Once your kernel is configured, type make-kpkg kernel_image and it will make your kernel.

Assuming the compile was successful, it will create a .deb in /usr/src which you can then install by typing dpkg -i kernel-package-filename, follow the instructions and reboot.

You can also create a custom kernel name (to avoid overwriting other kernels you have made) by typing something like: make-kpkg kernel_image --revision=custom.1.

This is just a quick review of the commands you need, for more information check out this guide ( to compiling using the kernel package program.

Retrieved from
Page last modified on March 23, 2006, at 11:11 PM