Differences between revisions 81 and 82
Revision 81 as of 2012-08-20 12:26:20
Size: 10067
Editor: ?SedatDilek
Comment: Add linux-kbuild-2.6 to last proposal
Revision 82 as of 2012-10-12 00:56:42
Size: 8239
Editor: BenHutchings
Comment: Refresh for 3.x, source package renaming, quilt, current i386 flavours
Deletions are marked like this. Additions are marked like this.
Line 5: Line 5:
'''+++ 16-Aug-2012: NOTE: With >=3.2 Debian kernel stuff is maintained in linux package. +++''' <<BR>>
[ Proposal: This wiki page should be renamed/moved to better reflect the actual content (linux-2.6/linux-kbuild-2.6)? ]
Line 20: Line 18:
<<Anchor(ulimit-problem)>>
== Caveat: ulimit -n problem ==
If patch series are silently(!) not applied, that may be because the total number of patches to apply is too high to work with the default “ulimit -n” value (usually 1024). This has been fixed in 2.6.32-26 in squeeze.
Line 25: Line 19:
== Add a patch to linux-2.6 and build new kernel packages == == Add a patch to linux and build new kernel packages ==
Line 28: Line 22:
apt-get build-dep linux-2.6 apt-get build-dep linux
Line 32: Line 26:
apt-get source linux-2.6
cd linux-2.6-*
apt-get source linux
cd linux-*
Line 36: Line 30:
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
tar xzf linux_3.0.0~rc6.orig.tar.gz
cd linux-*
svn export svn://svn.debian.org/svn/kernel/dists/trunk/linux/debian
Line 43: Line 37:
 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. 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-3.x.0-y+foo.1-zzz}}}.
Line 45: Line 39:
 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
}}}
 1. Use quilt to add your patch
Line 78: Line 69:
~/src/linux-2.6-2.6.24~rc6$ debuild -e DEBIAN_KERNEL_JOBS=${NR_CPUS} ~/src/linux-3.2.31$ debuild -e DEBIAN_KERNEL_JOBS=${NR_CPUS}
Line 87: Line 78:
 1. Prepare the rules file for the one build you want to make: {{{
fakeroot make -f debian/rules.gen setup_i386_none_k7
 1. Prepare the rules file for the one build you want to make, e.g.: {{{
fakeroot make -f debian/rules.gen setup_i386_none_686-pae
Line 90: Line 81:
 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.
 This will build a tree in the {{{debian/build/build_i386_none_686-pae}}} directory. Go to that directory.
Line 100: Line 88:
 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 \
 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 e.g. {{{
fakeroot make -f debian/rules.gen binary-arch_i386_none_686-pae binary-indep \
Line 107: Line 92:
 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
 Some time later the package files will be generated, e.g.: {{{
linux-image-3.2.0-4+foo.1-686-pae_3.2.31-1+foo.1_i386.deb
linux-image-3.2.0-4+foo.1-686-pae-dbg_3.2.31-1+foo.1_i386.deb
linux-headers-3.2.0-4+foo.1-686-pae_3.2.31-1+foo.1_i386.deb
xen-linux-system-3.2.0-4+foo.1-686-pae_3.2.31-1+foo.1_i386.deb
Line 117: Line 98:
 '''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]].  '''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 (RT) and flavours to be generated, and obviously takes a lot longer. See [[http://lists.debian.org/debian-kernel/2008/04/msg00190.html|this thread]].
Line 122: Line 103:
 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
 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. e.g. {{{
rm debian/stamps/build_i386_none_686-pae_plain
Line 128: Line 107:
== The story of linux-kbuild-2.6 ==
'''+++ 16-Nov-2011: NOTE: linux-kbuild stuff moved to linux-tools package with >=3.2-rcX. +++'''
== The story of linux-tools ==
Line 131: Line 109:
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}}}. The {{{linux-headers-*}}} packages created with the above method depend on {{{linux-kbuild-*}}}, which is a '''not''' built from the {{{linux}}} source package, but from {{{linux-tools}}}.
Line 133: Line 111:
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. Often, when a new kernel comes around, {{{linux-kbuild-3.xx}}} isn't yet available in the archive, so you either have to build it yourself, or wait.
Line 137: Line 115:
=== How to build linux-kbuild-2.6 yourself ===
NOTE: The instructions which follow are implemented by the attached shell script - [[attachment:build-linux-kbuild.sh]] - edit it to suit your needs (e.g., change VERSION to your kernel version).
=== How to build linux-tools yourself ===
Line 141: Line 118:
svn co svn://svn.debian.org/kernel/dists/trunk/linux-kbuild-2.6 svn co svn://svn.debian.org/kernel/dists/trunk/linux-tools
Line 143: Line 120:
Then, download 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
Then, download the vanilla kernel tarball (usually the 3.x version, no 3.x.y version): {{{
VERSION="3.6"
wget http://ftp.de.kernel.org/pub/linux/kernel/v3.x/linux-${VERSION}.tar.bz2
Line 149: Line 126:
cd linux-kbuild-2.6 cd linux-tools
Line 152: Line 129:
tar -xzf orig/linux-kbuild-2.6_${VERSION}.orig.tar.gz
cd linux-kbuild-2.6-${VERSION}
cp -a ../linux-kbuild-2.6/* ./
tar -xzf orig/linux-tools_${VERSION}.orig.tar.gz
cd linux-tools-${VERSION}
cp -a ../linux-tools/* ./
Line 158: Line 135:
NOTE: Optionally, you have to change Debian-version in debian/changelog if $VERSION of Linux-kernel is higher, think of 2.6.35 (latest version in linux-kbuild-2.6 SVN-branch) is smaller than 2.6.36-rcX (version of tarball), otherwise the genorig.py line fails. NOTE: Optionally, you have to change Debian-version in debian/changelog if $VERSION of Linux-kernel is higher, think of 3.5 (latest version in linux-tools SVN-branch) is smaller than 3.6-rcX (version of tarball), otherwise the genorig.py line fails.
Line 164: Line 141:
cp -av ../orig/linux-kbuild-2.6_${VERSION}.orig.tar.gz ../ <--- Necessary to get a diff file. cp -av ../orig/linux-tools_${VERSION}.orig.tar.gz ../ <--- Necessary to get a diff file.

Translation(s): English - Italiano

(!) ?Discussion

Building custom kernel packages

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 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. 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
    cd linux-*

    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_3.0.0~rc6.orig.tar.gz
    cd linux-*
    svn export svn://svn.debian.org/svn/kernel/dists/trunk/linux/debian
  3. Look at the top of debian/changelog and think of an appropriate version number. You cannot dch yet, though. 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".

  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-3.x.0-y+foo.1-zzz.

  5. Use quilt to add your patch
  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. Now that the above error message has occured after the first “debian/rules clean”, dch will work because debian/control has been (re-)generated. (Note that, after editing debian/changelog, “debian/rules clean” must again be run because its hash changes.) 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. You could do this with the dch tool from the devscripts package like so:

    dch --local +foo.
  9. 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-3.2.31$ debuild -e DEBIAN_KERNEL_JOBS=${NR_CPUS}

If you plan to do multiple rebuilds you might want to use ccache by adding the --prepend-path=/usr/lib/ccache option to the above debuild command.

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, e.g.:

    fakeroot make -f debian/rules.gen setup_i386_none_686-pae

    This will build a tree in the debian/build/build_i386_none_686-pae 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 e.g.

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

    Some time later the package files will be generated, e.g.:

    linux-image-3.2.0-4+foo.1-686-pae_3.2.31-1+foo.1_i386.deb
    linux-image-3.2.0-4+foo.1-686-pae-dbg_3.2.31-1+foo.1_i386.deb
    linux-headers-3.2.0-4+foo.1-686-pae_3.2.31-1+foo.1_i386.deb
    xen-linux-system-3.2.0-4+foo.1-686-pae_3.2.31-1+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 (RT) and flavours to be generated, and obviously takes a lot longer. See this thread. Solution:

    fakeroot make -f debian/rules.gen binary-arch_i386_none_real
  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. e.g.

    rm debian/stamps/build_i386_none_686-pae_plain

The story of linux-tools

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

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

A Mini-Howto from Sedat (dileks) gives detailed instructions how to build linux-kbuild-3.5. An integration here would blow-up this wiki unnecessarily.

How to build linux-tools yourself

Checkout the source from SVN repository:

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

Then, download the vanilla kernel tarball (usually the 3.x version, no 3.x.y version):

VERSION="3.6"
wget http://ftp.de.kernel.org/pub/linux/kernel/v3.x/linux-${VERSION}.tar.bz2

Now, you prepare the Debian package:

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

NOTE: Optionally, you have to change Debian-version in debian/changelog if $VERSION of Linux-kernel is higher, think of 3.5 (latest version in linux-tools SVN-branch) is smaller than 3.6-rcX (version of tarball), otherwise the genorig.py line fails.

Finally, adjust the Debian version and add comments like "Non-maintainer upload" plus "New upstream version" via dch command. Last but not least, build the package itself after you installed eventually missing build-dependencies:

dch -i
make -f debian/rules clean
dpkg-checkbuilddeps
cp -av ../orig/linux-tools_${VERSION}.orig.tar.gz ../ <--- Necessary to get a diff file.
dpkg-buildpackage -us -uc (or debuild)

and you are done.