Saturday, April 09, 2011

Local Kernel Repository

Beside to clone the kernel development tree directly from its git repository, I want to create repository from a stable kernel and its patches, I will have commit for each subversion patch. The last stable kernel at this time is 2.6.38.

First download the 2.6.38 first release (not the subversion releases) named linux-2.6.38.tar.bz2, extract it with (my favourite bzip2 - tar style)

$ bzip2 -dc linux-2.6.38.tar.bz2 | tar xf -

Initialize git repository, add files and do initial commit.

$ cd linux-2.6.38
$ git init && git add .
$ git commit -m 'Linux 2.6.38'


Time to download the patches, please note that the kernel patch system is not a increment patch, this means when we got version 2.6.38.3 patch this must be applied to the first version in this case 2.6.38, not any of its subversion, eg. 2.6.38.2 or 2.6.38.1. At this time, I have these following patch files

patch-2.6.38.1.bz2
patch-2.6.38.2.bz2


After we got out desired patches, so now lets create another branch for patching purposes, still at our master branch.

$ git branch 2.6.38
$ git branch 2.6.38.1
$ git checkout 2.6.38.1


Issue patch command with (also my favourite bzip2 - patch command style)

$ bzip2 -dc /path_to/patch-2.6.38.1.bz2 | patch -p1
$ git commit -m 'Linux 2.6.38.1'


Now we have 2.6.38.1 version at 2.6.38.1 branch, then lets create 2.6.38.2 branch for 2.6.38.2 patch as well, remember that we must have first version to apply a patch, so create this branch based the first version branch.

$ git checkout 2.6.38
$ git branch 2.6.38.2
$ bzip2 -dc /path_to/patch-2.6.38.2.bz2 | patch -p1
$ git commit -m 'Linux 2.6.38.2'


Lets describe what we have in our repository, we already have 4 branches with its branch's name as its version, except for master branch, it has 2.6.38 version. I want to have each version has its commit on the master branch, but I don't have increment path for version 2.6.38.1 to 2.6.38.2, it is impossible to just merging 2.6.38.1 and 2.6.38.2 branch, so we must result a diff file from version 2.6.38.1 to 2.6.38.2, those commands simply do the magic.

$ git checkout 2.6.38.2
$ mkdir /path_to/2.6.38.2
$ cp -r . /path_to/2.6.38.2/
$ git checkout 2.6.38.1
$ diff -ur . /patch_to/2.6.38.2 | bzip2 -zc > /path_to/patch-inc-2.6.38.2.bz2


The 2.6.38.1 to 2.6.38.2 patch is now generated in bz2 format, this an increament patch, we can now apply this patch to the master branch.

$ git checkout master
$ bzip2 -dc /path_to/patch-inc-2.6.38.2.bz2 | patch -p1
$ git commit -m 'Linux-2.6.38.2'
$ git log


As you can see the master branch log is now have increment version for each commit, this will be helpfull if we want to trace patches for every subversion.