Patching a kernel

From LQWiki
Jump to navigation Jump to search

Patching a kernel

There can be several reasons to apply a patch:

  • To upgrade the kernel to a newer version
  • To use patches (e.g. bugfixes) not yet merged into the kernel
  • To add functionality using code from external sources

This last reason could be unsafe and should be avoided

Upgrading the kernel

Rather than distribute the full kernel source every time there's a new stable release (roughly once a month), it is more efficient to distribute just the changes. This is done in the form of a patch. So instead of going to and downloading the full source, go there and just download the changes since the last time you downloaded the full source.

For instance, if I have linux-2.6.0.tar.bz2 already downloaded and I want to have linux-2.6.3, I need to download the patch to go from 2.6.0 to 2.6.1, the patch to go from 2.6.1 to 2.6.2 and the patch to go from 2.6.2 to 2.6.3. The patch files are called "patch-2.6.2.bz2", etc (patch-2.6.2.bz2 is the patch file that gets you from version 2.6.1 to version 2.6.2). Once one has these four files, one should untar the full source for 2.6.0 somewhere, and then apply the patches, one by one, in order. Assuming source and patch are in your home directory, for example:

$ cd
$ mkdir build
$ cd build
$ bunzip2 -dc ~/linux-2.6.0.tar.bz2 | tar -x
$ cd linux-2.6.0
$ bunzip2 -dc ~/patch-2.6.1.bz2 | patch -p1
$ bunzip2 -dc ~/patch-2.6.2.bz2 | patch -p1
$ bunzip2 -dc ~/patch-2.6.3.bz2 | patch -p1
$ cd ..
$ mv linux-2.6.0 linux-2.6.3 # since the dir now represents the 2.6.3 kernel

if you downloaded a .gz patch, use instead:

gzip -cd ~/patch-2.6.xx.gz | patch -p1

if it's not zipped:

 patch -E -p1  < ~/sound_patch

Purely an example and you would type whatever the file name is in replace of sound_patch.

See also

external sources