I decided to make a post on recompiling your Ubuntu kernel after after taking a look at the instructions on the Ubuntu wiki. Although the instructions were correct it was a big jumbled mess and almost impossible to figure out what was what from the instructions. This post will cover recompiling the kernel that comes with Ubuntu. The reasons for doing this are to keep the current Ubuntu patches and configs and simply add some stuff of your own. This would be useful for adding a patch of some sort or adding support in the kernel .config for a piece of hardware or software which may not be enabled by default.

For this article I will be using Ubuntu 10.10. these instructions should also work for 9.10 and 10.04 but earlier versions had a slightly different process.

Ok so lets get started:

NOTE: I do every thing as root but I will add sudo to the commands for the people that are not comfortable working as root.

1. Install the required packages

sudo apt-get install fakeroot kernel-wedge build-essential makedumpfile kernel-package libncurses5 libncurses5-dev

2. Next issue the following command

sudo apt-get build-dep --no-install-recommends linux-image-$(uname -r)

3. Next e need to create a working directory and download the Ubuntu image which correspond’s with our running kernel.

mkdir ~/source
cd ~/source
apt-get source linux-image-$(uname -r)
cd linux-2.6.35

4. Now, since we are just rebuilding the current kernel we can use the current .config file as a starting point.

cp -vi /boot/config-`uname -r` .config

5. At this point if we have any patch’s we can add those. Generally a patch come in the form of a .patch file and needs to be applied in the top level directory of the source which in this case would be ~/source/linux-2.6.35

patch -p1 < example.patch

Do this for all patch’s you may need to apply.

6. Next we will open the ncurses editor for the .config file. This is where all the support is defined for the kernel.

make menuconfig

I’m going to assume you know what kernel options you need. This is also a good chance to remove support for anything you do not need. Smaller kernel with less bloat can greatly improve performance.

7. Save the menu file and exit the interface.

8. At this point you should be in the ~/source/linux-2.6.35 directory again

9. A little trick you can do is to set the CONCURRENCY_LEVEL variable to speed up the compile of the kernel. The number should be the number of processors you have plus one. So in my case I have a dual core processor so I will add one which would be three.

export CONCURRENCY_LEVEL=3

10. Lets build it! You need to add a custom string to the end to mark your new kernel. In this case I added “-QD” to the end but you can add what ever you want

make-kpkg clean
fakeroot make-kpkg --initrd --append-to-version=-QD kernel-image kernel-headers

11. At this point you should go grab some food because the kernel compile can take a while

12. Once the kernel is built it will be one directory up in the ~/source file we were originally working in.

cd ~/source
sudo dpkg -i linux-image-2.6.35.(This part will be whatever name you gave it).deb
sudo dpkg -i linux-headers-2.6.35.(This part will be whatever name you gave it).deb

There will only be these 2 debs so use tab complete to get the correct names. The dpkg commad will do the actual installing of the kernel.

13. Now we need to make a initramfs.

sudo update-initramfs -c -k 2.6.35-QD

You will need to add your kernel version + the custom string you added on the end.

14. Now lets update grub

sudo update-grub

15. Reboot and you should be rocking with your new kernel!


List Price: $49.99 USD
New From: $27.81 USD In Stock
Used from: $14.96 USD In Stock


List Price: $24.99 USD
New From: $15.98 USD In Stock
Used from: $6.44 USD In Stock

DeliciousStumbleUponDiggTwitterFacebookRedditLinkedInEmail
Tags: , , , , , , , , , ,
38 Responses to “How to Recompile Your Ubuntu 10.10 Kernel for Patching or to add Support for a Specific Device”
  1. Alexandre Santos says:

    Excellent post! congrats!

    It helped me a lot.

    I would also like permission to translate it for my blog …. thanks

    [Reply]

    purehate Reply:

    Sure you can translate it and use it as long as you leave question-defense as the original authors and maybe a link to the original article.

    [Reply]

  2. Prince101 says:

    Hello.

    This is not working for me. i follow the guide exactly, and without errors.

    i install the deb packages, do a update initram without errors too, and at last a sudo update-grub.

    when i restart to boot into the kernel, i get errors.
    Target filesystem doesn’t have /sbin/init.tes]
    No init found. Try passing init= bootarg

    this is a great guide! but i have gotten myself into trouble ><

    help?…

    [Reply]

    alex Reply:

    Hello Prince101,

    Try booting to the Live CD and running fsck on the Ubuntu partitions.

    Let us know if that works or if you resolved the issue in another way.

    Thanks.
    alex

    [Reply]

  3. ikalce says:

    Tnx alote for this guide. But when i come to patch -p1 < example.patch
    when i use command i got folowing error :

    root@ikalce:~/source# patch -p1 < genius-islim-310-webcam-test.patch
    patching file linux/drivers/media/video/gspca/pac7302.c
    Hunk #1 FAILED at 96.
    Hunk #2 FAILED at 1220.
    Hunk #3 FAILED at 1239.
    3 out of 3 hunks FAILED — saving rejects to file linux/drivers/media/video/gspca/pac7302.c.rej

    pls help me how do i solw this error!

    [Reply]

    purehate Reply:

    Most likely you are not patching from the correct directory. I would review the code in the patch and see if there are any clues as to where to run it from.

    [Reply]

  4. ikalce says:

    BTW it is great guide i`m beginner and find this very helpfull tnx again !

    [Reply]

    alex Reply:

    Hello ikalce,

    No problem. Glad to hear the article was helpful to you. Thanks for taking the time to post feedback.

    Thanks.
    alex

    [Reply]

  5. Anna says:

    Thanks, I was having problems following the Ubuntu wiki article, this made a lot more sense.

    [Reply]

  6. purehate says:

    Great stuff! Glad we could help out.

    [Reply]

  7. Mario says:

    After the installation I do not have the mouse and keyboard control ? ?
    the kernel is 2.6.37-rc6.
    Any suggestion ?

    Thanks

    [Reply]

    purehate Reply:

    you could try to reload the modules.

    modprobe psmouse && modprobe keyboard

    [Reply]

  8. Explict Hax0r says:

    Thank you!!! For such a Wonderful post…
    It is perfect..
    But i’d like to point out one suggestion…
    If you could explain why we are using these methods and With some more explanations…

    Thnx

    [Reply]

    purehate Reply:

    I would be happy to explain any portion of the tutorial that you do not understand. Just let us know what we need to be more clear on and we will try to help.

    [Reply]

  9. Hallo32 says:

    Nice straight forward guide.

    Good work

    [Reply]

    purehate Reply:

    Thanks for the feedback. I alway appreciate people taking the time to thank us.

    [Reply]

  10. yeikiu says:

    can i remove the ~/source directory now?

    thx a lot!

    [Reply]

    Salih Emin Reply:

    Yes yeikiu, you can ! There is no particular reason to keep it. Exept if you want to re-try some other options in the “menuconfig” and don’t want to re-download the source files again.

    [Reply]

  11. storm says:

    Great write-up AND it worked for me.

    Could you explain though how to re-compile and install the kernel WITHOUT making clean on subsequent builds?

    I will be making changes to a single kernel file (not part of a module) and need to just recompile, install, reboot and test until it works for me. Making clean as part of the build process takes way to long on the machine I’m using.

    [Reply]

    purehate Reply:

    Just do not issue the make clean command

    [Reply]

  12. Divaniti says:

    i have BCM4312 wireless adapter and it’s not capable with packet injection in aircrack-ng i did a lot of search and they recommended me to patch my wireless driver or update my kernel
    i’m using ubuntu 10.10
    would these mentioned steps help?

    [Reply]

    purehate Reply:

    Yes this method is for adding kernel patches

    [Reply]

  13. Jean-Paul says:

    I just recompile my Ubuntu 10.0 system. The directions were right on. Just boot up and everything works fine. No more freezes with some apps.

    Thanks

    [Reply]

    purehate Reply:

    Good to hear, thanks for leaving feedback

    [Reply]

  14. None says:

    At what point in these directions do I modify the kernel code?

    [Reply]

    alex Reply:

    Hello None,

    It would be in steps 4,5, and 6. Depending on what you want to modify will depend on what you exactly you need to do.

    Thanks.
    alex

    [Reply]

  15. LAMA says:

    That is a good step-by-step guide, purehate, I’ve been looking for something like that.
    The only problem I have is that linux-image-$(uname -r) in steps 2 and 3 gets me only the newest kernel (there’s a comment: Picking ‘linux’ as source package instead of ‘linux-image…).
    Do you think you could advise?

    [Reply]

  16. asdasdsd says:

    sudo update-initramfs -c -k 2.6.35+QD
    should be
    sudo update-initramfs -c -k 2.6.35-QD

    note te minus at the end.

    [Reply]

    alex Reply:

    Hello asdasdsd,

    Thanks for noting. I have updated the article.

    Thanks.
    alex

    [Reply]

  17. Akshay says:

    Hi,
    i tried this
    i m stuck at the fakeroot step!
    its showing the follwing error:

    Error: The extended version may only contain
    lowercase alphanumerics and the characters – + .
    The current value is: -QD
    Aborting.

    [Reply]

    Akshay Reply:

    okay my bad..
    its just that i have to make it in lowercaps! :D
    sorry :)

    [Reply]

  18. Akshay says:

    step 11 is taking too long. is it okay?

    and by too long i mean 2-3 hrs!

    [Reply]

  19. Akshay says:

    Hi,

    How to go back to the previous kernel?

    [Reply]

  20.  
Leave a Reply

*Type the letter/number combination in the abvoe field before clicking submit.

*