Compiling custom kernel has its own advantages and disadvantages. However, new Linux user / admin find it difficult to compile Linux kernel. Compiling kernel needs to understand few things and then just type couple of commands. This step by step howto covers compiling Linux kernel version 2.6.xx under Debian GNU Linux. However, instructions remains the same for any other distribution except for apt-get command.
Step # 1 Get Latest Linux kernel code
Visit http://kernel.org/ and download the latest source code. File name would be linux-x.y.z.tar.bz2, where x.y.z is actual version number. For example file inux-2.6.25.tar.bz2 represents 2.6.25 kernel version. Use wget command to download kernel source code:
$ cd /tmp
$ wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-x.y.z.tar.bz2
Note: Replace x.y.z with actual version number.
Step # 2 Extract tar (.tar.bz3) file
Type the following command:
# tar -xjvf linux-2.6.25.tar.bz2 -C /usr/src
# cd /usr/src
Step # 3 Configure kernel
Before you configure kernel make sure you have development tools (gcc compilers and related tools) are installed on your system. If gcc compiler and tools are not installed then use apt-get command under Debian Linux to install development tools.
# apt-get install gcc
Now you can start kernel configuration by typing any one of the command:
- $ 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.
For example make menuconfig command launches following screen:
$ make menuconfig
You have to select different options as per your need. Each configuration option has HELP button associated with it so select help button to get help.
Step # 4 Compile kernel
Start compiling to create a compressed kernel image, enter:
$ make
Start compiling to kernel modules:
$ make modules
Install kernel modules (become a root user, use su command):
$ su -
# make modules_install
Step # 5 Install kernel
So far we have compiled kernel and installed kernel modules. It is time to install kernel itself.
# make install
It will install three files into /boot directory as well as modification to your kernel grub configuration file:
- System.map-2.6.25
- config-2.6.25
- vmlinuz-2.6.25
Step # 6: Create an initrd image
Type the following command at a shell prompt:
# cd /boot
# mkinitrd -o initrd.img-2.6.25 2.6.25
initrd images contains device driver which needed to load rest of the operating system later on. Not all computer requires initrd, but it is safe to create one.
Step # 7 Modify Grub configuration file - /boot/grub/menu.lst
Open file using vi:
# vi /boot/grub/menu.lst
title Debian GNU/Linux, kernel 2.6.25 Default root (hd0,0) kernel /boot/vmlinuz root=/dev/hdb1 ro initrd /boot/initrd.img-2.6.25 savedefault boot
Remember to setup correct root=/dev/hdXX device. Save and close the file. If you think editing and writing all lines by hand is too much for you, try out update-grub command to update the lines for each kernel in /boot/grub/menu.lst file. Just type the command:
# update-grub
Neat. Huh?
Step # 8 : Reboot computer and boot into your new kernel
Just issue reboot command:
# reboot
For more information see:
- Our Exploring Linux kernel article and Compiling Linux Kernel module only.
- Official README file has more information on kernel and software requirement to compile it. This file is kernel source directory tree.
- Documentation/ directory has interesting kernel documentation for you in kernel source tree.
Featured Articles:
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- 10 Greatest Open Source Software Of 2009
- My 10 UNIX Command Line Mistakes
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- Top 20 OpenSSH Server Best Security Practices
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Linux Video Editor Software
- Email this to a friend
- Download PDF version
- Printable version
- Comment RSS feed
- Last Updated: Apr/17/2008



{ 66 comments… read them below or add one }
According to the kernel documentation, the kernel should be compiled using gcc 2.95.x, with x >= 3. “apt-get install gcc” under debian gives you a recent gcc (version > 4).
It works with gcc version >= 4.0.
gcc –version
gcc (GCC) 4.0.3 20060212 (prerelease) (Debian 4.0.2-9)
uname -a
Linux debian 2.6.15.4 #1 PREEMPT Fri Feb 17 20:46:04 IST 2006 i686 GNU/Linux
I have compiled above kernel using gcc 4.0.2-9. INSTALL file may be not updated.
Thanks a lot Gabber Anna,
It’s works for me :-))
LOL
Note sure who are you?
But you bring back some old memories…
Take care buddy :)
any guess about boot loader?
After building the kernel and updating grub I’ve rebooted the new kernel successfully. Now I am wondering if this process includes updating the kernel header files in /usr/include/. If not, what is the best way to do that and should any new directories be added to ld.so.conf so I can update glibc?
If you also upgraded kernel-devel and headers package you should get updates. No need to upgrade ld.so.conf or cache
Info
—–
Kernel 2.6.23 has issues with kernel headers. If you have distro’s like fedora it gonna give up some wierd fixdep.c error messages.
Some forums say you need to have 2.4 headers for compiling it. Kernel header is a huge mess scattered around and well serious debates have gone down the drain…
http://kerneltrap.org/node/6536
Does this kernel support RHEL4 update 5
I am using kernel 2.6.9-55.EL can i upgade the
How much time does it take approximately?
i am trying it on mandriva 2008.i can not do “$ make menuconfig”.is there any option to do that.please help me to get out of this as soon as possible.i wonder there is no option of “make”.
Priya,
To make ‘make’ work, go inside the kernel directory ie., /usr/src/. There, u can find the make file. Now, just give “$make menuconfig”. It will work…. :)
With 2.6 kernel there is no need for make modules. make builds kernel and modules. Have you ever read the README in kernel source directory?
It will take near about 1 to 1.30 hours. for complete
installation
I tried make 2.6.25 in my desktop (FC5, kernel version 2.6.15), everything goes okay, but failed to boot the new kernel image with the follow error messages:
PCI: BIOS Bug: MCFG area at e0000000 is not E820-reserved
PCI: Not using MMCONFIG
Read Hat nash version 5.0.32 Starting
mount: error mounting /dev/root on /sysroot at ext3: No such device
….
In initrd.img file, I found no libata.ko or any other .ko modules are added before mkrootdev.
Is this problem caused by incorrect or even no HDD controller driver loaded? I did not see appropriate entry for libata in .config file. Do you guys have any suggestion on make it through?
Thanks.
-Lin
About the 4th step, as the “make help” says: you do not need to do make modules again, so when using “make” it already compiles the modules.
:D
Lin,
Did your problem sorted out?Thans
Hi.. wt if somethin goes wrong… is there any way to get OS to its former stage, say ( backup or uninstall Kernel or something ).. or will need to install whole OS again…
I followed the above steps in order to compile Linux kernel “linux-2.6.27″ but when tried to boot my system from latest compiled kernel got the Kernel Panic error which says can’t find
file system /boot/root at the start.
please suggest
This is a nice tutorial, but I have a note to make. On my installation, Ubuntu 8.04.1 64-bit, the command in Step # 6 is “mkinitramfs” instead of “mkinitrd”.
Can’t wait to try out my new kernel…
the same thing happened to me as ravi.
I have compiled custom kernel and I am missing in /boot directory config-2.6 file. What have I done wrong? I see config files from old kernel there. thanks in advance.
you have compiled a upstream kernel.How should i compile distribution specific kernels,like if i install fedora it has its kernel source in /usr/src/, fedora community might have added its own patches.Will the steps described in this article work for distribution specific kernels?
Except for step where you create the initrd img file, rest of the steps explained here worked fine. The Kernel version I tried was 2.6.27.10 and the linux box had ubuntu 8.10 installed.
On ubuntu if you try to use mkinitrd you might get the message “No command found”. Try using mkinitramfs instead. It worked perfectly fine.
There is no such thing as bz3.
It’s cool.
Thanks alot NIXTCRAFT.
I tried to cheat and copied over an older .config.. broke something and had to redo all the options by hand : /
Anyways, the instructions worked great with Gentoo. I had to emerge “mkinitrd” but otherwise everything went very quickly, maybe 20 min to compile everything (very short in Gentoo world).
I suggest everyone keep their old kernel and a lilo/grub option for it just incase :) Most of the problems in the comments seem to be from misconfiguring the kernel. If you aren’t sure what your hardware is or don’t have the time to run through every option. I suggest you pop in a live cd and copy “/proc/config.gz” to use as your base config (“gzip -d config.gz” will uncompress it).
If your system is already unusable, pop in a live cd and try the following as root:
“cd /”
“mkdir /mnt/fixme”
“mount /dev/ROOTDRIVE /mnt/fixme”
“mount /dev/BOOTDRIVE /mnt/fixme/boot”
“mount -t proc proc /mnt/fixme/proc”
“chroot /mnt/fixme /bin/bash”
That should put you back into your computer to compile/fix whatever.
i’ve just build the 2.6.28 kernel on ubuntu 8.04 LTS and it’s working like a charm. It was required, as I had some troubles installing my 500 GB Samsung drive that was attached to a Trust eSATA IF-3300 card. Thanks for this great tutorial !!
You don’t need make modules anymore. I compiled a few times the last days and just make && make modules_install will do.
Following error occured during make command of compilation step for linux 2.6.23
make: *** [.tmp_vmlinux1] Error 1
Plz provide me solution for it.
Thanks
Akash
make command error:
make: *** [.tmp_vmlinux1] Error 1
Kindly suggest solution
regards
————-
Akash
Hi
On Debian the kernel compile is much more straightforward than this describes.
First you of course need to take the kernel source. Then:
1. make menuconfig (or whatever you want)
2. make-kpkg –revision kernel_image
3. Install the resulting .deb package using dpkg.
The debian package management system then knows about your custom kernel and it handles all needed actions to get the kernel properly working. For example initrd is done automagically if needed.
I compile the root file system and the way to access it directly into kernel and customize the kernel sharply to the computer. That way you wont need initrd anymore :) and the machine boots quite fast, because the chipset drivers are active from wery beginning of booting.
I compiled the whole thing and then booted ..I see the updated version of fedora but when I try to run it ..it says kernal panic and doesn’t proceed any further
If you have multiple CPU-kernels, you’d consider using the -j option for make, for example make -j5 , which will use 5 instance of make to built the process. This will speed up things, nice tip I got on IRC :)
Hello!
got some problems while compiling new kernel using make. Error below:
{standard input}: Assembler messages:
{standard input}:745: Error: suffix or operands invalid for `mov'
{standard input}:746: Error: suffix or operands invalid for `mov'
{standard input}:950: Error: suffix or operands invalid for `mov'
{standard input}:951: Error: suffix or operands invalid for `mov'
{standard input}:1024: Error: suffix or operands invalid for `mov'
{standard input}:1025: Error: suffix or operands invalid for `mov'
{standard input}:1120: Error: suffix or operands invalid for `mov'
{standard input}:1121: Error: suffix or operands invalid for `mov'
{standard input}:1208: Error: suffix or operands invalid for `mov'
{standard input}:1220: Error: suffix or operands invalid for `mov'
make[1]: *** [arch/i386/kernel/process.o] Error 1
make: *** [arch/i386/kernel] Error 2
gcc version 4.1.2
debian etch
got some ideas? thanx
a very good clarification about kernels,i’m impressed!
Thanks, it works perfectly.
hello when i try to boot my kernel it says error file not found.
i use the following command
title Debian GNU/Linux, kernel 2.6.25 Default
root (hd0,0)
kernel /boot/vmlinuz root=/dev/hdb1 ro
initrd /boot/initrd.img-2.6.25
savedefault
boot
im pretty noob i dont know what im doing wrong.
plzz contact me or post here.
my mail is toldamtorp@gmail.com
37 ondrg, Which gcc version you used ?
Can any body tell that How to remove a previously compiled and installed kernel. So as to make space for compiling and installing a new kernel ?
NIce step-by-step process, BUT Following error occured during make command of configuration step for linux 2.6.29.2
make[1]: *** [script/kconfig/dochecklxdialog] Error 1
make: *** [menuconfig] Error 2
Plz provide me solution for it.
Thanks
J.Acevedo
Hi… Kindly help me please… i m in serious trouble…
I m trying to install RTLinux on Linux 2.6.xx
The installation guide specified to patch the linux 2.6.xx, configure and then compile. But
i m able to proceed til the configuration of the kernel…
When i give the make command, i m coming up with errors…
Also i tried to install linux 2.6.xx without patching it with RTLinux,again i m struck up while compiling……
Kindly help please…Wil be grateful to you…
It’s good, but i need your help to compile;boot from a flash drive and configure options such that the size of the kernel is max 5Mb(minimum application like terminal,usb…)
Great Tutorial .I have E8200 , Gigabyte EP43-DS3L kernel 2.6.18 that does not recognize coretemp,I compiled 2.6.30.1 kernel and it’s working.Thanks
Hey this was great, worked for me… I had some small issues where I was missing some files like ncurses etc, but after getting them it all flowed smoothly… thanks alot again :)
This is nice documentation. But I think some modification is required.
Step # 6: Create an initrd image
Type the following command at a shell prompt:
# cd /boot
# mkinitrd -o initrd.img-2.6.25 2.6.25
Instead of mkinitrd I use mkinitramfs in ubuntu 9.04
Step # 7 Modify Grub configuration file – /boot/grub/menu.lst
# update-grub
update-grub is not required in ubuntu 9.04
Can any body describe to me next: about the process0, process0 which happened in Linux kernel 2.6,
1. describe how to greate it
2. describe what they do
Hi
I am using ubuntu distribution, I like to update my kernel , my present version kernel is 2.6.28-11-generic #42-Ubuntu SMP Fri Apr 17 01:57:59 UTC 2009 i686 GNU/Linux.
i downloaded latest kernel source from kernel.org “linux-2.6.31.tar.bz2″ i followed the following steps to configure my kernel
1. i extracted the kernel source file in usr/src
2. I updated my gcc complier
root@sivakumar-desktop:/usr/src# apt-get install gcc
Reading package lists… Done
Building dependency tree
Reading state information… Done
gcc is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 228 not upgraded.
3. Then i tried to run make menuconfig, i got the following error
root@sivakumar-desktop:/usr/src# make menuconfig
make: *** No rule to make target `menuconfig’. Stop.
4. then i tried
root@sivakumar-desktop:/usr/src/linux-2.6.31# make menuconfig
*** Unable to find the ncurses libraries or the
*** required header files.
*** ‘make menuconfig’ requires the ncurses libraries.
***
*** Install ncurses (ncurses-devel) and try again.
***
make[1]: *** [scripts/kconfig/dochecklxdialog] Error 1
make: *** [menuconfig] Error 2
i am also getting the same problem …….plz suggest
after extracting there is some error when i configure the kernel
that error is make: *** No rule to make target ‘menuconfig’, Stop.
Hello,
Can Any One Solve My Problem That Is
after extracting there is some error when i configure the kernel
that error is make: *** No rule to make target ‘menuconfig’, Stop.
plz tell me the fast it is urgent friends….
plz
Mukesh – seems like you need to cd into the extarcted directory to run the make.
Has anyone made a suggestion as to how to fix the kernel panic issue that was pointed to several time here? I have the same issue. After installing the new kernel and trying to boot into it, I see the kernel panic since it doesn’t see any of my drives ( “/”, “/usr”, etc). Anyideas where I went amiss?
Hi!!
i am using Redhat 4 – kernel 2.6.9 and now i build kernel 2.7.13. it was sucessfully and after reboot i can see my new kernel in the grub.. but when i select .and proceed . i am getting the following error:
“Enforcing mode requested but no policy loaded. Halting now.
Kernel panic – not syncing: Attempted to kill init!”
please tell me wht might the problem and suggest me how to load the kenel 2.7.13..
Thanx in advance….
problem occur on booting…
mount: unknown file system type ‘devfs’
Kernel panic – not syncing: Attempted to kill init!”
In the process make install .there are two files created in the direction /boot
Kernel image: /boot/vmlinuz-2.6.31.4-smp
Initrd image: /boot/initrd-2.6.31.4-smp
However,One file config is missed.
I update the menu.list
Then ,reboot.
On the way booting,there is no error.
but when I inter the X-window ,my keyboard and mouse doesn’t work.
Hi everybody,
I have followed all the steps above and succeeded in every step. But when I choose in the grub to run the 2.6.31.6 kernel I have the following message:
Unable to find a suitable fs in /proc/mounts, is it mounted ?
Use –subdomainfs to override.
I have installed the linux kernel from Ubuntu 9.10. I am not sure, but I think because I have installed ubuntu with ext4 file system, the kernel could not recognize it. The kernel is residing in /usr/src which is in the same partition as ubuntu.
Have anyone an idea out there ?
Thx,
if you want people to do your survey you should make it accessable for us lynx users
I need help.I follow stepbystep all is done.And but at the reboot say “error 16: inconsistent filesystem structure” what wrong whit it? My kernel is 2.6.24-16 want to upgrade kernel 2.6.31.6 plz help me thx
Does it work for SUSE?
hey guys…….can anyone help me……….in my /boot i am not getting config file for newly compiled and installed kernel and also after successful installation of kernel.2.6.32 , i am not able to boot from this kernel as it says file system not detected , /dev/hda not detected……..and kernel panic……….
Nice.
Came in handy as I needed to recompile kernel in order to remove KVM virtualization support. VirtualBox won’t run with KVM modules loaded.
Why am I telling you this?
Some of the instructions are kind of outdated on modern systems, could you perhaps update the article?
- Some systems now use GRUB 2, which doesn’t have a menu.lst.
- Modern systems tend to use mkinitramfs or yaird, not mkinitrd.
Thanks a lot for the article, though. Off to test out my new kernel.
This article actually very usefull. It helped me to kompile linux kernel after my resultles
attemtions for a long period. The only issue I had was creating initrd image.
My Ubuntu 8.10 interpid (also 8.4 hardy) do not have mkinitrd command so instead
I used next steps to compile linux kernel(2.6.27.7).Here they are.
1. first copy your /boot folder to somewhere , home folder
2. go to top of your linux source tree and run(root prev required)
#make-kpkg clean && make-kpkg –initrd –revision=custom.1.0 kernel_image
and after its finished with no errors run
#dpkg -i .deb
the latest command will update your /boot also /boot/grub/menu.lst file , but this is not what
do we want , and after reboot you may find your pc not booting at all.
what do we need is new kernel and new initrd image .
our new kernel is vmlinuz-2.6.27.7 and image is initrd.img-2.6.27.7
so we have to copy these files to some temp folder , then restore our old /boot folder
from backup and copy back again our fresh kernel and image from temp folder to /boot.
to finish we need edit /boot/grub/menu.lst file.
here we can simply copy our generic boot items and make no change except names
of kernel and image to new ones. reboot and enjoy.
it really worked .. clean .. thanks .. a lot
> Step # 2 Extract tar (.tar.bz3) file
I lol’d.