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
2.6.17-10-generic
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
/.
/usr
/usr/src
/usr/src/linux-source-2.6.17.tar.bz2
/usr/share
/usr/share/doc
/usr/share/doc/linux-source-2.6.17
(trimmed)
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-2.6.17.14-ubuntu1-custom_2.6.17.14-ubuntu1-custom-10.00.Custom_i386.deb
dpkg -i linux-headers-2.6.17.14-ubuntu1-custom_2.6.17.14-ubuntu1-custom-10.00.Custom_i386.deb
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
2.6.17.14-ubuntu1-custom
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".


Didn't work. When rebooting, would break and ask for modules, or didn't find the module path?
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.
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.
This is right command:
fakeroot make-kpkg –initrd –append-to-version=-custom kernel_image kernel_headers
ahh there shoudl be 2 "-" instead of 1 "-"
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!
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.
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.
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.
root@Ian-two:/usr/src/linux#
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
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
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.
root@Ian-two:/usr/src/linux#
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.