Differences between revisions 17 and 18
Revision 17 as of 2008-04-08 15:51:59
Size: 4708
Editor: madduck
Comment: line break notice
Revision 18 as of 2008-04-08 17:22:07
Size: 4374
Editor: madduck
Comment: reorg
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:
= Building custom kernel packages =

This page is about rebuilding an official Debian kernel package with custom
changes. There is the Kernel Handbook about this:
Line 14: Line 16:
What you'll get is exactly the kernel that Debian releases but with those added changes. 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 20:
== Add a Patch to linux-2.6 == == Add a patch to linux-2.6 and build new kernel packages ==
Line 18: Line 22:
First get the orig tar ball from buildserver, see [DebianKernel], unpack it:
{{{
~/src$ tar xzf linux-2.6_2.6.24~rc6.orig.tar.gz
}}}
  1. Create the directory where you will build the kernel package as a normal user.
Line 23: Line 24:
Get latest Debian patches + config settings:
{{{
~/src/linux-2.6-2.6.24-rc6$ svn export svn://svn.debian.org/svn/kernel/dists/trunk/linux-2.6/debian
}}}
  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-*
  }}}
Line 28: Line 31:
Now you can start adding patches inside the patches dir. To have them applied don't forget to add them to the series file.   Now you are in the tree that holds the source and all changes Debian made to it.
Line 30: Line 33:
{{{
~/src/linux-2.6-2.6.24~rc6$ cp ~/special-fix.patch debian/patches/bugfix/
~/src/linux-2.6-2.6.24~rc6$ echo "+ bugfix/special-fix.patch" \
  >> debian/patches/series/1~experimental.1
}}}
  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 36: Line 42:
Do not forget to document the new patch in a new stanza at the top of {{{debian/changelog}}}. You will likely want to append some string to the version, using {{{~}}} or {{{+}}} to ensure your change does not conflict with existing or future official kernel packages.   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.
  }}}
Line 38: Line 51:
Now check that your patchset still applies and fix any conflicts
{{{
~/src/linux-2.6-2.6.24~rc6$ make -f debian/rules source-all
}}}
  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}}}.
Line 43: Line 56:
Then build with appropriate DEBIAN_KERNEL_JOBS according to the box core cpu number:
{{{
~/src/linux-2.6-2.6.24~rc6$ DEBIAN_KERNEL_JOBS=${NR_CPUS} debuild
}}}
  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
  }}}
Line 48: Line 64:
== 8 easy (albeit time consuming) steps ==
Assuming you are just interested in building one flavor of a kernel-image.
  Now check that your patchset still applies and fix any conflicts
  {{{
  make -f debian/rules source-all
  }}}
Line 51: Line 69:
 1. Create the directory where you will build the kernel package as a normal user.
 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
}}}
  1.#6 Document the addition of this patch in the new stanza in {{{debian/changelog}}}.
Line 57: Line 71:
Now your tree holds the source and all changes Debian made to it. === Building all kernel-related packages ===
Line 59: Line 73:
 1.#3 Add your patch into the {{{debian/patches}}} directory, as per the above. It may be a good idea to name the new series accordingly. For instance, when adding the "foo" patch, you might want to add a reference to the patch (see above) to {{{debian/patches/series/1+foo.1}}}, assuming {{{debian/patches/series/1}}} is the latest file. By ''abusing'' the ABI field for this, one guards against possible confusion when such custom kernel packages are installed on otherwise pristine Debian systems.   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$ DEBIAN_KERNEL_JOBS=${NR_CPUS} debuild
  }}}
Line 61: Line 80:
 1.#4 If you haven't yet, document your change in {{{debian/changelog}}}, e.g. with the {{{dch}}} tool from the {{{devscripts}}} package, and append the same string ("+foo.1") to the package version as you appended to the ABI field. === Building only a single kernel variant ===
Line 63: Line 82:
{{{
dch --local +foo.
}}}
Line 67: Line 83:
 1.#5 Now 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 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.#6 Change the .config file. Do:
{{{
make menu
config
}}}
and make any changes you had in mind. E.g the changes mentioned above in '''Reasons for doing this'''. An alternative is to run
{{{
make oldconfig
}}}
which uses the currently running configuration of the machine on which you are building.
Also this is the time to add additional patches, e.g. the Debian Logo patch.
 1.#7 Compile the kernel and generate the image and headers debs. 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 DEBIAN_KERNEL_JOBS=${NR_CPUS}
}}}
or:
{{{
fakeroot make -f debian/rules.gen binary-arch_i386_none_686 DEBIAN_KERNEL_JOBS=${NR_CPUS}
}}}
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
}}}
 1.#8 Install them with dpkg and now you have installed the stock Debian kernel with your changes in it. Congratulations ;-)
  7.#7 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 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 2 package 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
  }}}

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/

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. Modifying the Debian configuration to change to Pata.

    4. Add an 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.

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.
  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.

  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$ DEBIAN_KERNEL_JOBS=${NR_CPUS} debuild

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 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.

  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 2 package 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