Differences between revisions 2 and 57 (spanning 55 versions)
Revision 2 as of 2007-05-10 09:13:16
Size: 5470
Editor: ?HvWoerkom
Comment:
Revision 57 as of 2010-08-11 09:51:29
Size: 7821
Editor: ?SedatDilek
Comment: Update linux-kbuild-2.6 section: Introduce $VERSION, clarify on dch and don't forget to use orig-tarball (tested with debuild).
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
= This Page is about Rebuilding an official Debian kernel package =
There is the Kernel Handbook about this:
http://kernel-handbook.alioth.debian.org/
= Building custom kernel packages =
(this wiki page should be renamed/moved to better reflect the actual content)

This page is about rebuilding an official Debian kernel package with custom changes. There is the Kernel Handbook about this: http://kernel-handbook.alioth.debian.org/ (which explains how to "Rebuild an official Debian linux kernel package", hopefully : http://kernel-handbook.alioth.debian.org/ch-common-tasks.html ch 4.2 : "Rebuilding an official Debian kernel package").
Line 7: Line 8:
== 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.
 1.#2 Modifying the Debian configuration to change the '''preemption model'''.
 1.#3 Modifying the Debian configuration to change the '''timer frequency'''.
 1.#4 Modifying the Debian configuration to change the '''Logo'''.
 1.#5 Modifying the Debian configuration to add '''kernel timings'''.
<<Anchor(reasons)>> '''Reasons to do this:'''
Line 14: Line 10:
What you'll get is exactly the kernel that Debian releases but with those added changes.  1. Modifying the Debian configuration to change the '''preemption model'''.
 1. Modifying the Debian configuration to change the '''timer frequency'''.
 1. Add a patch fix.
 1. Add your favorite patchset.
What you'll get is exactly the kernel that Debian releases but with those added changes. The new packages will not step on the official kernel images' toes.
Line 16: Line 16:
== Presumption ==
You are just interested in building one flavor of a kernel-image.
<<Anchor(add-a-patch)>>
== Add a patch to linux-2.6 and build new kernel packages ==
 1. Create the directory where you will build the kernel package as a normal user and make sure you have all necessary packages installed: {{{
apt-get install fakeroot build-essential devscripts
apt-get build-dep linux-2.6
}}}
Line 19: Line 23:
== 10 easy (albeit time consuming) steps ==
 1. Create the directory where you will build the kernel package as a normal user.
 1.#2 Get the kernel source. You could install the kernel source package:
{{{
apt-get install linux-source-2.6
 1. Get the package source. For this to work, you need to have {{{deb-src}}} lines for the official archive in {{{/etc/apt/sources.list}}}: {{{
apt-get source linux-2.6
cd linux-2.6-*
Line 25: Line 27:
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 http://www.kernel.org and download the patch files when they become available. Then you just run a script to install the source into your directory:
{{{
#!/bin/bash
set -x
PLACE=/home/hugo/linux-2.6.20-3-build
 Now you are in the tree that holds the source and all changes Debian made to it. As an alternative, you could get a kernel tarball, e.g. from buildserver (see DebianKernel), unpack it, and get the latest Debian patches + config settings: {{{
tar xzf linux-2.6_2.6.24~rc6.orig.tar.gz
cd linux-2.6-*
svn export svn://svn.debian.org/svn/kernel/dists/trunk/linux-2.6/debian
}}}
Line 31: Line 33:
cd $PLACE
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
cd $PLACE
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
cd $PLACE
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
cd $PLACE
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
cd $PLACE
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
cd $PLACE
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
cd $PLACE
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
cd $PLACE
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
cd $PLACE
patch -p1 < /hda10/backup.files/patch-2.6.17
cd $PLACE
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
cd $PLACE
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
cd $PLACE
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
cd $PLACE
mv $PLACE/linux-2.6.19 $PLACE/linux-2.6.20
cd $PLACE/linux-2.6.20
exit
 1. Start a new stanza at the top of {{{debian/changelog}}} and use an appropriate version number. Ensure that the distribution is '''not''' set to the regular release names. Change it to something like '''UNRELEASED.''' If you are adding a single patch "foo", you might want to append "+foo.1". If you are adding multiple patches for your company or yourself, use "+somename.1". You could do this with the {{{dch}}} tool from the {{{devscripts}}} package like so: {{{
dch --local +foo.
Line 82: Line 36:
That gets the '''2.6.9 source''' from the HDD and patches it for every version up to 2.6.20.
Line 84: Line 37:
 1.#3 Download the Debian diff.gz file. That is the file that contains all the Debian changes for this kernel package. E.g http://ftp.debian.org/debian/pool/main/l/linux-2.6/linux-2.6_2.6.20-3.diff.gz
 1.#4 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
 1. Append the same string to the {{{abi.abiname}}} field in {{{debian/config/defines}}} to ensure that your custom kernel package name doesn't bite with the official ones. In our case, we're now creating {{{linux-image-2.6.xx-y+foo.1-zzz}}}.

 1. Put your patch into the {{{debian/patches}}} directory and create a new series file to match the Debian revision; assuming you are basing your work on the {{{-1}}} package, you would create a file named {{{1+foo.1}}}: {{{
cp ~/special-fix.patch debian/patches/bugfix/
echo "+ bugfix/special-fix.patch" >> debian/patches/series/1+foo.1
Line 89: Line 43:
Now your tree holds the source and all changes Debian made to it.
 1.#5 '''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.
 1.#6 '''Change the file debian/bin/abicheck.py'''. After line 18 that contains '''ret = 0''' add a line that says '''return 0'''. This will stop you from doing the abicheck.
 1.#7 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

 1. Optional : If it's not the first build attempt, and should you need to clean things in case of build failures : {{{
make -f debian/rules clean
Line 97: Line 47:
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

 1. Now check that your patchset still applies and fix any conflicts:
 Note: on the first run, the target fails. Make sure you run it twice.
 {{{
This target is made to fail intentionally, to make sure
that it is NEVER run during the automated build. Please
ignore the following error, the debian/control file has
been generated SUCCESSFULLY.
Line 101: Line 56:
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.#8 Change the .config file. Do:
{{{

 {{{
make -f debian/rules source-all
}}}

 1. Document the addition of this patch in the new stanza in {{{debian/changelog}}}.

<<Anchor(build-all)>>
=== Building all kernel-related packages ===
 0. Make sure you have at least 40 GB of disk space free (version 2.6.32-17 took 30 GB).

 1. Assuming you want to build '''all''' kernel-related packages, build with the appropriate {{{DEBIAN_KERNEL_JOBS}}} parameter (the number of processors you can use for the build): {{{
~/src/linux-2.6-2.6.24~rc6$ debuild -e DEBIAN_KERNEL_JOBS=${NR_CPUS}
}}}

<<Anchor(build-one)>>
=== Building only a single kernel variant ===
 0. Make sure you have at least 10 GB of disk space free (setup_amd64_none_amd64 took 7.3 GB in version 2.6.32-17).

 1. Prepare the rules file for the one build you want to make: {{{
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 were 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. Go to that directory.

 1. Change the {{{.config}}} file, using e.g. {{{
Line 105: Line 85:
cd ../../..
Line 106: Line 87:
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.#9 Compile the kernel and generate the image and headers debs. Do:
{{{
fakeroot make -f debian/rules.gen binary-arch-i386-none-k7

 1. Compile the kernel and generate the kernel packages. Replace {{{$NR_CPUS}}} with the number of CPUs of the build machine (keeping it all on the same line) and run either: {{{
fakeroot make -f debian/rules.gen binary-arch_i386_none_k7 binary-indep \
DEBIAN_KERNEL_JOBS=${NR_CPUS}
}}} ''or'' {{{
fakeroot make -f debian/rules.gen binary-arch_i386_none_686 binary-indep \
DEBIAN_KERNEL_JOBS=${NR_CPUS}
Line 111: Line 95:
or:
{{{
fakeroot make -f debian/rules.gen binary-arch-i386-none-686
 On a 2.0GHz CPU the compile will take 1 hour and 20 minutes and 8 package files will be generated, e.g.: {{{
linux-image-2.6.24-1+foo.1-686_2.6.24-5+foo.1_i386.deb
linux-headers-2.6.24-1+foo.1-686_2.6.24-5+foo.1_i386.deb
linux-support-2.6.24-1+foo.1-686_2.6.24-5+foo.1_i386.deb
linux-tree-2.6.24_2.6.24-5+foo.1_i386.deb
linux-patch-debian-2.6.24_2.6.24-5+foo.1_i386.deb
linux-source-2.6.24_2.6.24-5+foo.1_i386.deb
linux-manual-2.6.24_2.6.24-5+foo.1_i386.deb
linux-doc-2.6.24_2.6.24-5+foo.1_i386.deb
Line 115: Line 105:
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.
{{{
linux-image-2.6.20-1-k7_2.6.20-3_i386.deb
linux-headers-2.6.20-1-k7_2.6.20-3_i386.deb
 '''Problem''': In this case, {{{linux-headers-2.6.24-1+foo.1-common}}} will be missing. One needs to invoke the {{{binary-arch_i386}}} target, which will yield all feature sets (Xen, VServer) and flavours to be generated, and obviously takes a lot longer. See [[http://lists.debian.org/debian-kernel/2008/04/msg00190.html|this thread]].

 1. If you apply further changes to the source package and need to rebuild the binary packages without rebuilding each and every binary objects, you can remove the build stamp before running the above mentioned building command. {{{
rm debian/stamps/build_i386_none_k7_plain
}}} ''or'' {{{
rm debian/stamps/build_i386_none_686_plain
Line 120: Line 112:
 1.#10 Install them with dpkg and now you have installed the stock Debian kernel with your changes in it. Congratulations ;-)
== The story of linux-kbuild-2.6 ==
The {{{linux-headers-*}}} packages created with the above method depend on {{{linux-kbuild-*}}}, which is a '''not''' built from the {{{linux-2.6}}} source package, but from {{{linux-kbuild-2.6}}}.

Often, when a new kernel comes around, {{{linux-kbuild-2.6.xx}}} isn't yet available in the archive, so you either have to build it yourself, or wait.

=== How to build linux-kbuild-2.6 yourself ===
Fetch the sources from SVN: {{{
svn co svn://svn.debian.org/kernel/dists/trunk/linux-kbuild-2.6
}}}
Then, fetch the vanilla kernel tarball (important: the 2.6.x version, no 2.6.x.y version): {{{
VERSION="2.6.35"
wget http://ftp.de.kernel.org/pub/linux/kernel/v2.6/linux-${VERSION}.tar.bz2
}}}
Now, you can prepare the package: {{{
cd linux-kbuild-2.6
./debian/bin/genorig.py ../linux-${VERSION}.tar.bz2
cd ..
tar -xzf orig/linux-kbuild-2.6_${VERSION}.orig.tar.gz
cd linux-kbuild-2.6-${VERSION}
cp -a ../linux-kbuild-2.6/* ./
./debian/bin/gencontrol.py
}}}
Now adjust the version, and add a comment like "New upstream version" or something via dch command, and build the package itself, after you installed eventually missing build-dependencies: {{{
dch -i
make -f debian/rules clean
dpkg-checkbuilddeps
cp -av orig/linux-kbuild-2.6_2.6.35.orig.tar.gz ../
dpkg-buildpackage -us -uc (or debuild)
}}}
and you are done.

-----
 . CategoryKernel

Building custom kernel packages

(this wiki page should be renamed/moved to better reflect the actual content)

This page is about rebuilding an official Debian kernel package with custom changes. There is the Kernel Handbook about this: http://kernel-handbook.alioth.debian.org/ (which explains how to "Rebuild an official Debian linux kernel package", hopefully : http://kernel-handbook.alioth.debian.org/ch-common-tasks.html ch 4.2 : "Rebuilding an official Debian kernel package").

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

Reasons to do this:

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

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

  3. Add a patch fix.
  4. Add your favorite patchset.

What you'll get is exactly the kernel that Debian releases but with those added changes. The new packages will not step on the official kernel images' toes.

Add a patch to linux-2.6 and build new kernel packages

  1. Create the directory where you will build the kernel package as a normal user and make sure you have all necessary packages installed:

    apt-get install fakeroot build-essential devscripts
    apt-get build-dep linux-2.6
  2. Get the package source. For this to work, you need to have deb-src lines for the official archive in /etc/apt/sources.list:

    apt-get source linux-2.6
    cd linux-2.6-*

    Now you are in the tree that holds the source and all changes Debian made to it. As an alternative, you could get a kernel tarball, e.g. from buildserver (see DebianKernel), unpack it, and get the latest Debian patches + config settings:

    tar xzf linux-2.6_2.6.24~rc6.orig.tar.gz
    cd linux-2.6-*
    svn export svn://svn.debian.org/svn/kernel/dists/trunk/linux-2.6/debian
  3. Start a new stanza at the top of debian/changelog and use an appropriate version number. Ensure that the distribution is not set to the regular release names. Change it to something like UNRELEASED. If you are adding a single patch "foo", you might want to append "+foo.1". If you are adding multiple patches for your company or yourself, use "+somename.1". You could do this with the dch tool from the devscripts package like so:

    dch --local +foo.
  4. Append the same string to the abi.abiname field in debian/config/defines to ensure that your custom kernel package name doesn't bite with the official ones. In our case, we're now creating linux-image-2.6.xx-y+foo.1-zzz.

  5. Put your patch into the debian/patches directory and create a new series file to match the Debian revision; assuming you are basing your work on the -1 package, you would create a file named 1+foo.1:

    cp ~/special-fix.patch debian/patches/bugfix/
    echo "+ bugfix/special-fix.patch" >> debian/patches/series/1+foo.1
  6. Optional : If it's not the first build attempt, and should you need to clean things in case of build failures :

    make -f debian/rules clean
  7. Now check that your patchset still applies and fix any conflicts: Note: on the first run, the target fails. Make sure you run it twice.
    This target is made to fail intentionally, to make sure
    that it is NEVER run during the automated build. Please
    ignore the following error, the debian/control file has
    been generated SUCCESSFULLY.
    make -f debian/rules source-all
  8. Document the addition of this patch in the new stanza in debian/changelog.

  1. Make sure you have at least 40 GB of disk space free (version 2.6.32-17 took 30 GB).
  2. Assuming you want to build all kernel-related packages, build with the appropriate DEBIAN_KERNEL_JOBS parameter (the number of processors you can use for the build):

    ~/src/linux-2.6-2.6.24~rc6$ debuild -e DEBIAN_KERNEL_JOBS=${NR_CPUS}

Building only a single kernel variant

  1. Make sure you have at least 10 GB of disk space free (setup_amd64_none_amd64 took 7.3 GB in version 2.6.32-17).
  2. Prepare the rules file for the one build you want to make:

    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 were 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. Go to that directory.

  3. Change the .config file, using e.g.

    make menuconfig
    cd ../../..
  4. Compile the kernel and generate the kernel packages. Replace $NR_CPUS with the number of CPUs of the build machine (keeping it all on the same line) and run either:

    fakeroot make -f debian/rules.gen binary-arch_i386_none_k7 binary-indep \
    DEBIAN_KERNEL_JOBS=${NR_CPUS}

    or

    fakeroot make -f debian/rules.gen binary-arch_i386_none_686 binary-indep \
    DEBIAN_KERNEL_JOBS=${NR_CPUS}

    On a 2.0GHz CPU the compile will take 1 hour and 20 minutes and 8 package files will be generated, e.g.:

    linux-image-2.6.24-1+foo.1-686_2.6.24-5+foo.1_i386.deb
    linux-headers-2.6.24-1+foo.1-686_2.6.24-5+foo.1_i386.deb
    linux-support-2.6.24-1+foo.1-686_2.6.24-5+foo.1_i386.deb
    linux-tree-2.6.24_2.6.24-5+foo.1_i386.deb
    linux-patch-debian-2.6.24_2.6.24-5+foo.1_i386.deb
    linux-source-2.6.24_2.6.24-5+foo.1_i386.deb
    linux-manual-2.6.24_2.6.24-5+foo.1_i386.deb
    linux-doc-2.6.24_2.6.24-5+foo.1_i386.deb

    Problem: In this case, linux-headers-2.6.24-1+foo.1-common will be missing. One needs to invoke the binary-arch_i386 target, which will yield all feature sets (Xen, VServer) and flavours to be generated, and obviously takes a lot longer. See this thread.

  5. If you apply further changes to the source package and need to rebuild the binary packages without rebuilding each and every binary objects, you can remove the build stamp before running the above mentioned building command.

    rm debian/stamps/build_i386_none_k7_plain

    or

    rm debian/stamps/build_i386_none_686_plain

The story of linux-kbuild-2.6

The linux-headers-* packages created with the above method depend on linux-kbuild-*, which is a not built from the linux-2.6 source package, but from linux-kbuild-2.6.

Often, when a new kernel comes around, linux-kbuild-2.6.xx isn't yet available in the archive, so you either have to build it yourself, or wait.

How to build linux-kbuild-2.6 yourself

Fetch the sources from SVN:

svn co svn://svn.debian.org/kernel/dists/trunk/linux-kbuild-2.6

Then, fetch the vanilla kernel tarball (important: the 2.6.x version, no 2.6.x.y version):

VERSION="2.6.35"
wget http://ftp.de.kernel.org/pub/linux/kernel/v2.6/linux-${VERSION}.tar.bz2

Now, you can prepare the package:

cd linux-kbuild-2.6
./debian/bin/genorig.py ../linux-${VERSION}.tar.bz2
cd ..
tar -xzf orig/linux-kbuild-2.6_${VERSION}.orig.tar.gz
cd linux-kbuild-2.6-${VERSION}
cp -a ../linux-kbuild-2.6/* ./
./debian/bin/gencontrol.py

Now adjust the version, and add a comment like "New upstream version" or something via dch command, and build the package itself, after you installed eventually missing build-dependencies:

dch -i
make -f debian/rules clean
dpkg-checkbuilddeps
cp -av orig/linux-kbuild-2.6_2.6.35.orig.tar.gz ../
dpkg-buildpackage -us -uc (or debuild)

and you are done.