• Sign in to Neowin Faster!

    Create an account on Neowin to contribute and support the site.

Sign in to follow this  

Compiling the kernel with additional patches

Recommended Posts

Mathiasdm    2

(I know there's already a thread on this subject, but this one is also about extra kernel patches. Mods, do with it as you wish :p )

Compiling the kernel and adding patches

---------------------------------------

There are many possible reasons for wanting to compile a kernel with additional patches. One can try new features, hope for a speed increase, require a security fix... In my case, I wanted to try the latest bcm43xx driver (I would like to run some tests and give feedback to the developers, and on top of that, the new driver is said to work better with my wireless card).

On request of h3xis, and keeping in mind that others might want to add patches before compiling their kernel, I've written this guide. I've recompiled my kernel on Ubuntu 6.10, so instructions for other distributions might be slightly different!

IMPORTANT NOTICE!! Compiling your kernel could cause damage to your system, especially if you use conflicting packages! So be very careful, and don't forget to make a back-up!

I've based this guide on this page, with a few differences.

If a command does not work, try it again with 'sudo' added at the beginning!

Note: if anything goes wrong, it's your own responsibility!

1. Installing the required packages for compiling the kernel:

sudo apt-get install build-essential bin86 kernel-package libqt3-headers libqt3-mt-dev wget libncurses5 libncurses5-dev && cd /usr/src

2. Downloading and unpacking the kernel:

First, go to http://kernel.org/pub/linux/kernel/v2.6/, and choose the kernel you wish to compile (normally, you'll need the most recent one). Download it and unpack it in /usr/src. You will then have a folder /usr/src/linux-VERSION.

3. Changing links:

Make sure you're in /usr/src right now.

We're going to remove the current symbolic link at /usr/src/linux, and replace it by a link to our new kernel (soon to be compiled). Then, we'll move into the /usr/src/linux directory.

It's possible you don't have a /usr/src/linux directory. In that case, you don't need to remove the symbolic link (however, you still need to do the rest of the step).

We'll do this by using the following code.

sudo rm -rf linux && sudo ln -s /usr/src/linux-VERSION linux && cd /usr/src/linux

4.A. Adding official kernel patches

It's possible that you already have the source of kernel 'VERSION.smallversion' on your computer, but would like to use kernel 'VERSION.smallversion+X' instead. You could download the entire source to kernel 'VERSION.smallversion+X' (over 50 MB), or you could download 'patch-VERSION.smallversion+1', 'patch-VERSION.smallversion+2' and so on (could be a few kB up to a few MB).

Suppose you already have the source of an earlier kernel. You could download a kernel patch 'patch-VERSION.smallversion', decompress it in /usr/src/linux, and type the following code to add it to the kernel source:

patch -p1 < patch-VERSION.smallversion-DECOMPRESSED

By doing this, you will have patched your kernel!

4.B. Adding other kernel patches

If you have a kernel patch you wish to add, you simply decompress the patch into the /usr/src/linux folder, and type the following code:

patch -p1 < patch-DECOMPRESSED

5. Importing your previous kernel configuration and configuring the kernel

In this step, you'll use the previous kernel configuration, followed by answering lots of questions (if you're unsure about these, it's easiest to just keep pressing enter -- but if you need to set additional options: don't! I pressed enter, and I'll have to compile again to enable a debug-option on my bcm43xx-driver.).

sudo cp /boot/config-`uname -r` .config && sudo make oldconfig && sudo make xconfig

6. Compiling the kernel

Debian (and distributions based on it) has a configuration utility, called make-kpkg. It replaces a combination of commands and makes compiling the kernel easier.

[TO-DO: add explanation for non-Debian-based systems]

make-kpkg clean

Then, we'll do the actual compiling. Grab yourself a book, type the following code, and wait a few hours...

make-kpkg -initrd --revision=386 kernel_image kernel_headers modules_image

7. Finishing the job

Last, but not least, we need to install the created kernel packages.

There should be 2 .deb-packages in your /usr/src (one is a kernel image, the other a kernel header), so type:

cd /usr/src

Then, to install them:

dpkg -i KERNELIMAGE.deb && dpkg -i KERNELHEADER.deb

8. You made it!?

Now simply reboot, and that's it!

(If you have any comments, improvements, or have noticed errors, please do mention!)

Share this post


Link to post
Share on other sites
Barney T.    2,335

Looks great... thanks for the great post!

Barney

Share this post


Link to post
Share on other sites
Mathiasdm    2

No problem :)

I just hope I didn't post any mistake :blush:

Share this post


Link to post
Share on other sites
La-CocaCola    0
MESSAGE

I would like to know if this will fix the Segmentation Fault on Ubuntu that I get when playing Urban Terror.

Share this post


Link to post
Share on other sites
Mathiasdm    2

I have absolutely no idea. ;)

To be fair, I don't see the link between your issue and my 'compiling the kernel'.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.