This Page is about Rebuilding an official Debian kernel package

There is the Kernel Handbook about this:

We are following section 4.2: Rebuilding an official Debian kernel package

Reasons to do this

  1. Modifying the Debian configuration to enable the Nvidia closed source driver creation. Specifically in 2.6.20 if CONFIG_PARAVIRT is set, the Nvidia driver won't build, you might want to change that setting.

  2. Modifying the Debian configuration to change the preemption model.

  3. Modifying the Debian configuration to change the timer frequency.

  4. Modifying the Debian configuration to change the Logo.

  5. Modifying the Debian configuration to add kernel timings.

What you'll get is exactly the kernel that Debian releases but with thos added changes.


You are just interested in building one flavor of a kernel-image.

10 easy (albeit time consuming) steps

  1. Create the directory where you will build the kernel package as a normal user.
  2. Get the kernel source. You could install the kernel source package:

apt-get install linux-source-2.6

But that will get the entire kernel source. Very large. A better approach is to keep up to date on the latest stable kernels from and download the patch files when they become available. Then you just run a script to install the source into your directory:

set -x

tar -xjvf /hda10/backup.files/linux-2.6.9.tar.bz2
cd $PLACE/linux-2.6.9
patch -p1 < /hda10/backup.files/patch-2.6.10
mv $PLACE/linux-2.6.9 $PLACE/linux-2.6.10
cd $PLACE/linux-2.6.10
patch -p1 < /hda10/backup.files/patch-2.6.11
mv $PLACE/linux-2.6.10 $PLACE/linux-2.6.11
cd $PLACE/linux-2.6.11
patch -p1 < /hda10/backup.files/patch-2.6.12
mv $PLACE/linux-2.6.11 $PLACE/linux-2.6.12
cd $PLACE/linux-2.6.12
patch -p1 < /hda10/backup.files/patch-2.6.13
mv $PLACE/linux-2.6.12 $PLACE/linux-2.6.13
cd $PLACE/linux-2.6.13
patch -p1 < /hda10/backup.files/patch-2.6.14
mv $PLACE/linux-2.6.13 $PLACE/linux-2.6.14
cd $PLACE/linux-2.6.14
patch -p1 < /hda10/backup.files/patch-2.6.15
mv $PLACE/linux-2.6.14 $PLACE/linux-2.6.15
cd $PLACE/linux-2.6.15
patch -p1 < /hda10/backup.files/patch-2.6.16
mv $PLACE/linux-2.6.15 $PLACE/linux-2.6.16
cd $PLACE/linux-2.6.16
patch -p1 < /hda10/backup.files/patch-2.6.17
patch -p1 < /hda10/backup.files/patch-2.6.17
mv $PLACE/linux-2.6.16 $PLACE/linux-2.6.17
cd $PLACE/linux-2.6.17
patch -p1 < /hda10/backup.files/patch-2.6.18
mv $PLACE/linux-2.6.17 $PLACE/linux-2.6.18
cd $PLACE/linux-2.6.18
patch -p1 < /hda10/backup.files/patch-2.6.19
mv $PLACE/linux-2.6.18 $PLACE/linux-2.6.19
cd $PLACE/linux-2.6.19
patch -p1 < /hda10/backup.files/patch-2.6.20
mv $PLACE/linux-2.6.19 $PLACE/linux-2.6.20
cd $PLACE/linux-2.6.20

That gets the 2.6.9 source from the HDD and patches it for every version up to 2.6.20.

  1. Download the Debian diff.gz file. That is the file that contains all the Debian changes for this kernel package. E.g

  2. Patch the source with that. Cd into the tree of where you put the source, e.g. /home/hugo/linux-2.6.20-3-build/linux-2.6.20. You created linux-2.6.20-3-build and your script put linux-2.6.20 into it, cd into the latter and then:

zcat <path>linux-2.6_2.6.20-3.diff.gz| patch -p1

Now your tree holds the source and all changes Debian made to it.

  1. Make debian/rules executable. In your tree there is a directory named debian, in there is a file called rules, that has to be made executable, because it is executed.

  2. Change the file debian/bin/ After line 18 that contains ret = 0 add a line that says return 0. This will stop you from doing the abicheck.

  3. Prepare the tree for build. Still in the tree directory where you patched, do:

fakeroot debian/rules debian/build debian/stamps
fakeroot make -f debian/rules.gen setup-i386-none-k7

This presumes you are only interested in building a k7 AMD processor image! If you where interested in a 686 processor image do:

fakeroot make -f debian/rules.gen setup-i386-none-686

This will build a tree in the debian/build/build-i386-none-k7 or debian/build/build-i386-none-686 directory. Cd to that directory.

  1. Change the .config file. Do:

make menuconfig

and make any changes you had in mind. E.g the changes mentioned above in Reasons for doing this. Also this is the time to add additional patches, e.g. the Debian Logo patch.

  1. Compile the kernel and generate the image and headers debs. Do:

fakeroot make -f debian/rules.gen binary-arch-i386-none-k7


fakeroot make -f debian/rules.gen binary-arch-i386-none-686

And on a 2.0GHz CPU the compile will take 1 hour and 20 minutes and 2 deb files will be generated: the image file and the headers file, e.g.

  1. Install them with dpkg and now you have installed the stock Debian kernel with your changes in it. Congratulations ;-)