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.
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)
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:
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.
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-188.8.131.52-ubuntu1-custom_184.108.40.206-ubuntu1-custom-10.00.Custom_i386.deb
dpkg -i linux-headers-220.127.116.11-ubuntu1-custom_18.104.22.168-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.
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”.
Programmer by day, geek by night, The Geek, also known as Lowell Heddings, spends all his free time bringing you fresh geekery on a daily basis. You can follow him on Google+ if you'd like.
- Published 12/27/06