Differences between revisions 37 and 39 (spanning 2 versions)
Revision 37 as of 2009-01-22 16:18:40
Size: 6895
Editor: ?HansVanKranenburg
Comment: run gencontrol.py before dch -i, else: "Missing file debian/control"
Revision 39 as of 2009-02-12 16:03:31
Size: 6566
Editor: GeoffSimmons
Comment: Formatting.
Deletions are marked like this. Additions are marked like this.
Line 2: Line 2:
Line 5: Line 4:
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").
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 11: Line 8:
[[Anchor(reasons)]]
'''Reasons to do this:'''
  1.#1 Modifying the Debian configuration to change the '''preemption model'''.
  1.#2 Modifying the Debian configuration to change the '''timer frequency'''.
  1.#3 Modifying the Debian configuration to change to '''Pata'''.
  1.#4 Add an patch fix.
  1.#5 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.
[[Anchor(reasons)]] '''Reasons to do this:'''

 1. Modifying the Debian configuration to change the '''preemption model'''.
 1. Modifying the Debian configuration to change the '''timer frequency'''.
 1. Modifying the Debian configuration to change to '''Pata'''.
 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 25: Line 19:
 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 26: Line 24:
  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
  }}}
 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-*
}}}
 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 33: Line 34:
  1.#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-*
  }}}
 1. Start a new stanza at the top of {{{debian/changelog}}} and use an appropriate version number. 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 40: Line 38:
  Now you are in the tree that holds the source and all changes Debian made to it.  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}}}.
Line 42: Line 40:
  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
  }}}
 1. Put your patch into the {{{debian/patches}}} directory and add it to the series file (assuming {{{debian/patches/series/1}}} is the latest file in there): {{{
cp ~/special-fix.patch debian/patches/bugfix/
echo "+ bugfix/special-fix.patch" >> debian/patches/series/1+foo.1
}}}
 Now check that your patchset still applies and fix any conflicts: {{{
make -f debian/rules source-all
}}}
Line 51: Line 48:
  1.#3 Start a new stanza at the top of {{{debian/changelog}}} and use an
  appropriate version number. 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.
  }}}

  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-2.6.xx-y+foo.1-zzz}}}.

  1.#5 Put your patch into the {{{debian/patches}}} directory and add it to
  the series file (assuming {{{debian/patches/series/1}}} is the latest file
  in there):
  {{{
  cp ~/special-fix.patch debian/patches/bugfix/
  echo "+ bugfix/special-fix.patch" >> debian/patches/series/1+foo.1
  }}}

  Now check that your patchset still applies and fix any conflicts
  {{{
  make -f debian/rules source-all
  }}}

  1.#6 Document the addition of this patch in the new stanza in {{{debian/changelog}}}.
 1. Document the addition of this patch in the new stanza in {{{debian/changelog}}}.
Line 82: Line 52:

  7.#7
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}
  }}}
 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}
}}}
Line 92: Line 58:
 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.
Line 93: Line 66:
 1. Change the {{{.config}}} file, using e.g. {{{
make menuconfig
}}}
Line 94: Line 70:
  7.#7 Prepare the rules file for the one build you want to make:
  {{{
  fakeroot make -f debian/rules.gen setu
p_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.

  Go to that directory.

  1.#8 Change the {{{.config}}} file, using e.g.
  {{{
  make menuconfig
  }}}

  1.#9 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
 
[http://lists.debian.org/debian-kernel/2008/04/msg00190.html this thread].
 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}
}}}
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 [http://lists.debian.org/debian-kernel/2008/04/msg00190.html this thread].
Line 149: Line 90:
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}}}.
Line 150: Line 92:
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.
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.
Line 158: Line 95:


Fetch the sources from SVN:

{{{
Fetch the sources from SVN: {{{
Line 165: Line 98:

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

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

Now, you can prepare the package:

{{{
Now, you can prepare the package: {{{
Line 176: Line 103:
Line 178: Line 104:
Line 180: Line 105:
Line 182: Line 106:
Line 184: Line 107:
Line 186: Line 108:
Line 188: Line 109:

dch -i 
dch -i
Line 191: Line 111:

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

{{{
Now adjust the version, and add a comment like "New upstream version" or something, and build the package itself, after you installed eventually missing build-dependencies: {{{
Line 196: Line 113:
Line 198: Line 114:
Line 201: Line 116:
Line 205: Line 119:
CategoryKernel  . 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

?Anchor(reasons) 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. Modifying the Debian configuration to change to Pata.

  4. Add a patch fix.
  5. 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.

?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
  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. 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 add it to the series file (assuming debian/patches/series/1 is the latest file in there):

    cp ~/special-fix.patch debian/patches/bugfix/
    echo "+ bugfix/special-fix.patch" >> debian/patches/series/1+foo.1

    Now check that your patchset still applies and fix any conflicts:

    make -f debian/rules source-all
  6. Document the addition of this patch in the new stanza in debian/changelog.

?Anchor(build-all)

  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

  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.

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

    make menuconfig
  3. 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 [http://lists.debian.org/debian-kernel/2008/04/msg00190.html this thread].

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):

wget http://ftp.de.kernel.org/pub/linux/kernel/v2.6/linux-2.6.27.tar.bz2

Now, you can prepare the package:

cd linux-kbuild-2.6
./debian/bin/genorig.py ../linux-2.6.27.tar.bz2
cd ..
tar xzf orig/linux-kbuild-2.6_2.6.27.orig.tar.gz
cd linux-kbuild-2.6-2.6.27/
cp -a ../linux-kbuild-2.6/* ./
./debian/bin/gencontrol.py
dch -i

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

make -f debian/rules clean
dpkg-checkbuilddeps
dpkg-buildpackage -us -uc

and you are done.