Get in touch:
01524 851 877
07718 896 553

Building A Kernel In Ubuntu

Posted on May 01 2008 by Matthew Jakeman

As I mentioned in a previous blog entry, I have started using Ubuntu for pretty much all of my Linux needs over the past few years. However, up until now all of my kernel development work has been done using other distros.

Yesterday I decided to start doing some kernel development in Ubuntu for a project I am working on. The kernel compilation process is a bit different to the traditional method and this post simply lists how to compile a kernel using the Ubuntu tools. Please note that a lot of the commands listed hereafter will need to be executed as root.

First of all you need to grab the source of the kernel version you wish to compile. For me this is the Mobile IP version of the kernel from The Nautilus6 working group. This should be done from the directory in which you want the source directory to be, usually this would be /usr/src.

#cd /usr/src
#apt-get source linux-image-2.6.22-10-mip6
This should grab all of the source for you and put it in the directory /usr/src/linux-source-2.6.22-2.6.22.

Often it is a good idea to use the configuration file from the currently running kernel as a base for the kernel you are going to build. This should ease the transition from a stock kernel to one you have customised. This is done as follows :

#cp /boot/config-`uname -r` ./.configNow you are ready to start configuring your kernel.

#make menuconfigThis will bring up an ncurses based menu system that will allow you to configure your kernel options. If you prefer a more graphical environment in which to perform the configuration you can use the following :

#make xconfigNote that if you are using xconfig you should run it with either `gksudo` or `kdesudo` rather than just `sudo`. Although this shouldn’t be an issue in this case it is a good habit to get into as described here.

Once you have decided what configuration options you want for your kernel you are ready to build it. This is done using the following two commands.

#make-kpkg clean
#fakeroot make-kpkg --initrd --append-to-version=-your_kernel_name
kernel_image kernel_headers
The string after `–append-to-version`can be anything you want to distinguish this kernel from the others on the system.. Note that it must begin with a `-` and must not contain any whitespace.

Now you might want to go grab a coffee as this compilation will take quite a while, obviously the amount of time is dependent on your machine spec and your kernel configuration.

Once the compilation has successfully completed you should find two new .deb files in /usr/src. The name of these will vary depending on which kernel source you are using and what you appended to the kernel name. On my build they are named :

linux-headers-2.6.22.9-custom_2.6.22.9-custom-10.00.Custom_i386.deb
linux-image-2.6.22.9-custom_2.6.22.9-custom-10.00.Custom_i386.deb
All that is left to do now is to install these files using dpkg :

#dpkg -i linux-headers-2.6.22.9-custom_2.6.22.9-custom-10.00.Custom_i386.deb
#dpkg -i linux-image-2.6.22.9-custom_2.6.22.9-custom-10.00.Custom_i386.deb
Your new kernel should now be installed and ready to go if all the above steps went smoothly so just restart your machine and you should be running your home built kernel. To check this is the case once the machine has restarted just do the following in a terminal.

#uname -rThis should display to you the name of your home built kernel and you are ready to start experimenting with different configurations or why not start hacking about with the code and see what happens :)

This blog entry went on for a bit longer than i anticipated so for the impatient here is a quick fire list of commands for compiling the kernel in Ubuntu (change names in dpkg commands as necessary) :)

#cd /usr/src
#apt-get source linux-image-2.6.22-10-mip6
#cp /boot/config-`uname -r` ./.config
#make menuconfig
#make-kpkg clean
#fakeroot make-kpkg --initrd --append-to-version=-your_kernel_name
kernel_image kernel_headers
#dpkg -i linux-headers-2.6.22.9-custom_2.6.22.9-custom-10.00.Custom_i386.deb
#dpkg -i linux-image-2.6.22.9-custom_2.6.22.9-custom-10.00.Custom_i386.deb
Hope you found this useful and good luck with your new kernel.

1 Comment

  1. Shlomi says:

    After upgrading linux krneel, I always got problems of graphic that was showed when I booted to system You are running in a low graphic mode . I could not log in at all.For a Dell system with ATI AMD 6400.

Leave a comment