How-To Geek

How to Customize Your Ubuntu Kernel

Kernel customization is not for everyone. Please note before you try any of this that it can break your system.

There’s a bunch of reasons that you’d want to customize your kernel. You may want to trim down your kernel to only the necessary services, especially if you are running a server or dedicated device that only requires the essentials. You also may need to patch your kernel to support hardware that isn’t currently supported with the kernel you are running on.

This article will not explain how to patch your kernel, just how to customize your current one. I’ll have another followup article that explains how to patch your kernel, and some practical reasons why you’d want to do so.

To start, we need to figure out what version of the kernel we are currently running. We’ll use the uname command for that

$ uname -r


Now we need to Install the linux source for your kernel, note that I’m running the 2.6.17-10 kernel, so the installer line reflects that. For the purposes of this article, you can substitute the kernel number for whatever you are running. We also need to install the curses library and some other tools to help us compile.

sudo apt-get install linux-source-2.6.17 kernel-package libncurses5-dev fakeroot

If you are curious where the linux source gets installed to, you can use the dpkg command to tell you the files within a package. Here’s the output on my system:

$ dpkg -L linux-source-2.6.17

We can see that the source has been installed to the /usr/src directory in a zipped file.

To make things easier, we’ll put ourselves in root mode by using sudo to open a new shell. There’s other ways to do this, but I prefer this way.

sudo /bin/bash

Now change directory into the source location so that we can install. Note that you may need to install the bunzip utility if it’s not installed. (it was on mine)

cd /usr/src

bunzip2 linux-source-2.6.17.tar.bz2

tar xvf linux-source-2.6.17.tar

ln -s linux-source-2.6.17 linux

Make a copy of your existing kernel configuration to use for the custom compile process. Note that the ` character is the one below the tilde ~

cp /boot/config-`uname -r` /usr/src/linux/.config

Now we will launch the utility that will let us customize the kernel:

cd /usr/src/linux

make menuconfig

First, go down to Load an Alternate Configuration File, and load the .config file. (just hit enter)

Now that we are inside the utility, we can set the options for our custom kernel. Navigation is pretty simple, there’s a legend at the top if you get lost. I decided to select Networking and hit the Enter key to go down into that category.

Amateur Radio Support?  What in the hell is that installed for? You’ll note by the * that it’s built-in to the kernel.

By pressing the ? key, we can see the help for that particular item. Here’s the explanation:

Well, I’m going to disable that immediately. Why on earth is that installed in my kernel anyway? I hit Esc to exit the help screen, and then hit N to exclude that from my kernel.

When you are finished making whatever choices you want, hit Exit and save the configuration when prompted.

Now we have a configuration ready for compile. First we’ll do a make clean, just to make sure everything is ready for the compile.

make-kpkg clean

Next we’ll actually compile the kernel. This will take a LONG FREAKING TIME, so go find something interesting to do.

fakeroot make-kpkg –initrd –append-to-version=-custom kernel_image kernel_headers

This process will create two .deb files in /usr/src that contain the kernel. The linux-image****  file is the actual kernel image, and the other file contains the You can install both with dpkg. The filenames will probably be different on your system.

Please note that when you run these next commands, this will set the new kernel as the new default kernel. This could break things! If your machine doesn’t boot, you can hit Esc at the GRUB loading menu, and select your old kernel. You can then disable the kernel in /boot/grub/menu.lst or try and compile again. 

dpkg -i linux-image-

dpkg -i linux-headers-

Now reboot your machine. If everything works, you should be running your new custom kernel. You can check this by using uname. Note that the exact number will be different on your machine.

uname -r


I plan to write a series of articles on kernel customization, so subscribe to the RSS feed for updates.

Also, In the interests of full disclosure, I learned how to do this from the article at HowtoForge, which is a great website for some very advanced tutorials on linux. You’ll note that many of the steps in this article are similar, although I tried to make this article more “Ubuntu”.

Lowell Heddings, better known online as the How-To Geek, spends all his free time bringing you fresh geekery on a daily basis. You can follow him on if you'd like.

  • Published 12/27/06

Comments (42)

  1. Joerg

    Didn’t work. When rebooting, would break and ask for modules, or didn’t find the module path?

  2. The Geek

    Did you disable something required by your system? It’s usually best to go slow at first, disable only a few things at a time.

  3. Joerg

    I tried to, but maybe I switched something experimental on because it sounded cool :)
    Well, maybe it’s better to try and not change much or anything at first, maybe only the amateur radio support off…I’ll try that.

  4. Johan Sajfrt

    This is right command:
    fakeroot make-kpkg –initrd –append-to-version=-custom kernel_image kernel_headers

  5. Johan Sajfrt

    ahh there shoudl be 2 “-” instead of 1 “-“

  6. Motin

    Great man! Thanks, this was much easier for a first-timer to follow than the howtoforge-version – Would be great if you’d change the typo with -initrd instead of –initrd (2 ‘-‘s as mentioned earlier in the comments) – it threw me of for a while.

    One problem I encountered was that I couldn’t find the option that I wanted to enable. I searched for it using ‘/’, found the option but it just wasn’t where it should be. The solution for this is to be sure that the option’s dependancy is enabled (and it’s depencancy etc). If the feature might be experimental, also make sure that you have enabled “Code maturity level options” -> “Prompt for development and/or incomplete code/drivers”.

    For applying patches to the kernel – see the howtoforge version.

    Wow this is great – now I can finally try out some newer features without having to start out from the vanilla sources and configuration!

  7. Motin

    Running on my customized kernel now!

    One problem you didn’t mention is the one with missing firmware. This made my ipw2200 wireless produce the following error upon initialization:

    [ 24.577000] ipw2200: Intel(R) PRO/Wireless 2200/2915 Network Driver, 1.2.0kmprq
    [ 24.577000] ipw2200: Copyright(c) 2003-2006 Intel Corporation
    [ 24.605000] ipw2200: Detected Intel PRO/Wireless 2200BG Network Connection
    [ 24.646000] ipw2200: ipw2200-bss.fw request_firmware failed: Reason -2
    [ 24.646000] ipw2200: Unable to load firmware: -2
    [ 24.646000] ipw2200: failed to register network device
    [ 24.646000] ipw2200: probe of 0000:06:05.0 failed with error -5

    This can be solved if you have a working firmware folder (any previous should do) in /lib/firmware. Copy it in the following manner:
    sudo cp /lib/firmware/ /lib/firmware/`uname -r`
    …while you are booted into your new kernel. Then either restart or if it’s only the wireless:
    sudo rmmod ipw2200;
    sudo modprobe ipw2200;

    So now I am finally up with CONFIG_TASK_IO_ACCOUNTING compiled in, making it possible to track the IO activity on a per-process basis using sysstat 7.1.5 or newer.

    Thanks for the guide once again.

  8. Ian

    I got as far as;-

    fakeroot make-kpkg –initrd –append-to-version=-custom kernel_image kernel_headers

    this could not find the target. I was also following an article in linux journal so I ran simple “make”. und it’s taking a long time too. It’s only my old system so not too bad if it bombs.

    Regards Ian.

  9. ian

    Sorry you need this to figure out what I’m doing wrong.

    root@Ian-two:/usr/src/linux# fakeroot make-kpkg –initrd –append-to-version=-custom kernel_image kernel_headers
    Error: Unknown target –initrd Unknown target –append-to-version=-custom
    use –targets to display help on valid targets.

  10. Harsh Vadgama

    fakeroot make-kpkg –initrd –append-to-version=-custom kernel_image kernel_headers
    will not work because as johan mentioned he left out a –
    it should be
    fakeroot make-kpkg –initrd –append-to-version=-custom kernel_image kernel_headers
    try it and it will work

  11. Harsh Vadgama

    sorry seems this website is converting the 2 minus to 1 minus
    Replace EACH ** with a minus (-).
    fakeroot make-kpkg **initrd **append-to-version=-custom kernel_image kernel_headers

  12. ian

    The two negs were okay on the email but not the web site like you said.
    This is on an older PC with Ubuntu Edgy and I was looking to make it run with more snap. Maybe it would be better to us a different distro made for weaker PCs with socket 7, 450Mhz and 250Mbytes? Anyway this is what I got with two negs.
    Regards Ian.

    This is what it tells me with two negs
    root@Ian-two:/usr/src/linux# fakeroot make-kpkg -–initrd -–append-to-version=-custom kernel_image kernel_headers
    Unknown option: –initrd
    Unknown option: –append-to-version
    use –help to display command line syntax help.

  13. nino

    i can anyboyd help?
    when i compile mine and boot i dont have sound nor wireless…

    i think those are also part of the restricted drivers. in the normal kernel the “HardwareDrivers” window hows “Atheros HAL” and “Support for Atheros Wireless cards”.. in my custom theres nothing in that window.

  14. Leandru Daniel

    Great Article

  15. Don

    For anyone having sound issues, make sure you install ALSA from the menuconfig.

  16. Danilo

    Wow…great howto.. =P

  17. tomas

    shouldnt the config file being copied from /boot/config-`uname -r` include all the settings already used in the current kernel? then why should i need to add any extra module to enable alsa? im puzzled.

  18. madness70

    I’ve this error:

    make[2]: *** No rule to make target `arch/x86/kernel/asm-offsets.c’, needed by `arch/x86/kernel/asm-offsets.s’. Stop.
    make[1]: *** [prepare0] Error 2
    make[1]: Leaving directory `/usr/src/linux-headers-2.6.24-21-eeepc’
    make: *** [debian/stamp-kernel-conf] Error 2

    :-( ??

  19. Feelin'Art

    I have the same error as madness70. :(.

    So why??

  20. Damon

    One thing I noticed is that this takes far longer, maybe 3 or 4 times longer to do than it did under Gentoo. I’m guessing it’s because the ubuntu kernal I started with had heaps more options selected.

  21. Jan

    Hi Ian,
    I had the same problem here. I erased the long “-” and retyped it, worked. Good luck. Jan

  22. Jonathan Birge

    Did you have a problem with the firmware being installed in a directory not specific to the kernel? When I use the make-dpkg command to compile the kernel, the package it creates puts the firmware code in /lib/firmware. Thus, if you make two custom kernels, they conflict. Any idea how to get around this?

  23. AC

    Hi, How do you compile just for x86? I keep getting this error:

    Makefile:526: /usr/src/linux-source-2.6.24/arch/xen/Makefile: No such file or directory
    make[1]: *** No rule to make target `/usr/src/linux-source-2.6.24/arch/xen/Makefile’. Stop.
    make: *** [conf.vars] Error 2

  24. Robert Nicholson

    When you get that error you simply go into .config and make sure it says CONFIG_XEN is not set
    instead of CONFIG_XEN=y

  25. Steve

    Everything went fine until I hit a post install step while building which I copied below. I have a Dell E6400 which needs an nvidia proprietary driver for my video card. Do I have to add this driver somewhere in the kernel tree or something? Is there a good article that you could point me to and any info about this error would be helpful. Thanks.

    Examining /etc/kernel/postinst.d.
    run-parts: executing /etc/kernel/postinst.d/dkms
    run-parts: executing /etc/kernel/postinst.d/nvidia-common
    run-parts: /etc/kernel/postinst.d/nvidia-common exited with return code 20
    Failed to process /etc/kernel/postinst.d at /var/lib/dpkg/info/linux-image- line 1186.
    dpkg: error processing linux-image- (–install):
    subprocess post-installation script returned error exit status 2
    Errors were encountered while processing:

  26. Master

    here is my advice: If everything works – dont do it. You’ll never feel the difference ;) except for placebo ;P

  27. Navin

    to compile ur source try this

    dont use this, use the second one
    fakeroot make-kpkg –initrd –append-to-version=-custom kernel_image kernel_headers

    the below works for me
    fakeroot make-kpkg -initrd -append-to-version=-custom kernel_image kernel_headers

    the diference between the two is the minus sign, luk closer u ll figure out


  28. Vivek Dubey

    Very nie and helpful article. I have a quetion about costumization linux so i can make my linux os

  29. vamsi

    very useful information especially in the light that latest distros are stopping support for usbfs, with the help of your article I could boot into my kernel with usbfs.

  30. jfg69

    What happens if you allow updates? You lose all your work?
    I’m looking to rewrite WITHOUT IPv6 support built in. For whatever reason, I can not connect to my wireless router in any of the latest kernels and I want to see if this fixes the issue.

  31. Leon

    Thanks v. much. I also need usbfs support back in the kernel

  32. Heinz hoetger

    i got as far as :
    cd /usr/src

    bunzip2 linux-source-2.6.17.tar.bz2
    with that command i got the following reply:
    Input file linux-source-2.6.35.tar.bz2 is not a normal file.
    I searched the internet and couldn’t find anything usable to continue.
    I appreciate your article on this subject and it is really understandable for a newbie.
    Could you somehow help me on.l
    The required file is in /usr/src
    thank you sincerely

  33. Ralph

    if you compile a custom kernel; will my nvidia driver stop working? I know the one from Ubuntu many people like it. Not me. Can you please tell me how to compile the kernel and not brake my Nvidia vidio driver?

    Thank you!

  34. Nancy Poekert

    You don’t need bunzip2
    Just append .bz2 to the filename after the tar command:

    # tar xvf linux-source-2.6.17.tar.bz2

  35. Rajesh Shanker

    @Heinz…iam facing with the same problem as yours…Hi,
    When i execute the following command at

    root@rajesh-desktop:/usr/src# bunzip2 linux-source-2.6.35.tar.bz2
    bunzip2: Input file linux-source-2.6.35.tar.bz2 is not a normal file.

    any help is appreciated..


  36. Name

    Same issue as Rajesh Shanker…

  37. user friendly

    Rajesh Shanker, type:
    tar -jxfv linux-source-2.6.35.tar.bz2

  38. Arshavin

    Many people having trouble with this command :
    fakeroot make-kpkg –initrd –append-to-version=-custom kernel_image kernel_headers
    should make sure that the long dash before ‘initrd” and “append” is a couple of hyphens,which,for some reason appears to be a dash on this webpage.

  39. Arshavin

    Compilation fails with following output:
    drivers/usb/mon/mon_text.c: In function ‘mon_text_read_t’:
    drivers/usb/mon/mon_text.c:403:1: internal compiler error: Segmentation fault
    Please submit a full bug report,
    with preprocessed source if appropriate.
    See for instructions.
    make[4]: *** [drivers/usb/mon/mon_text.o] Error 1
    make[3]: *** [drivers/usb/mon] Error 2
    make[2]: *** [drivers/usb] Error 2
    make[1]: *** [drivers] Error 2
    make[1]: Leaving directory `/usr/src/linux-source-2.6.38′
    make: *** [debian/stamp/build/kernel] Error 2

    Any idea why I am getting this error?

  40. Warlok

    Wow, sweet walkthrough… can now set the nvidia framebuffer to built-in and disable the vesa crap.. To make advmame advmenu work.

    Thanks so much.

  41. Mass Profit Formula

    Hi, nice tutorial,having good information, i like that

  42. Rajan Lakshmanan

    I tried this process and did not create initrd file so manually I created and ll good on lucid.

    mkinitramfs -o /boot/initrd.img-

More Articles You Might Like

Enter Your Email Here to Get Access for Free:

Go check your email!