Differences between revisions 4 and 5
Revision 4 as of 2007-07-20 21:01:29
Size: 6936
Editor: ?MarcinOwsiany
Comment: formatting fix
Revision 5 as of 2007-08-18 21:22:27
Size: 6287
Editor: ?MarcinOwsiany
Comment: easier command to create flavour-inspecific header packages; introduce -j2
Deletions are marked like this. Additions are marked like this.
Line 91: Line 91:
script -c 'time fakeroot make -f debian/rules.gen binary-arch-i386-xen-686 binary-arch-i386-none-686' ../typescript.2007072001 script -c 'DEBIAN_KERNEL_JOBS=2 time fakeroot make -f debian/rules.gen binary-arch-i386-xen-686 binary-arch-i386-none-686 binary-arch-i386-xen-real binary-arch-i386-none-real' ../typescript.2007072001
Line 94: Line 94:
which is nice, as it saves the typescript of the build for later investigation in case it fails for some reason. which is nice, as it saves the typescript of the build for later investigation in case it fails for some reason. The environment variable setting DEBIAN_KERNEL_JOBS=2 causes a parallel build, which is more efficient if you have more than one CPU.
Line 96: Line 96:
After a (long) while, it produced the following files, as expected: After a (long) while, it produced the following files (grouped with according to targets which produced them):
Line 98: Line 98:
binary-arch-i386-none-686
Line 101: Line 102:
}}}
Line 102: Line 104:
binary-arch-i386-none-real
{{{
linux-headers-2.6.18-4_2.6.18.dfsg.1-12etch2.0.mactel_i386.deb
}}}

binary-arch-i386-xen-686
{{{
Line 108: Line 117:

=== Build the common header packages ===

FIXME: it might be possible to build these and the above packages in one go.

Since the header packages for each flavor depend on common header packages for each subarch, you need to invoke the following cryptic commands if you want to use the linux-headers packages for the above flavors:
binary-arch-i386-xen-real
Line 116: Line 119:
script -c "time fakeroot make -f debian/rules.real SOURCEVERSION='2.6.18.dfsg.1-12etch2.0.mactel' LOCALVERSION_HEADERS='' MAJOR='2.6' VERSION='2.6.18' KERNEL_HEADER_DIRS='i386 x86_64' ABINAME='-4' SUBARCH='none' UPSTREAMVERSION='2.6.18' ARCH='i386' install-headers-i386-none" ../typescript.2007072010 linux-headers-2.6.18-4-xen_2.6.18.dfsg.1-12etch2.0.mactel_i386.deb
Line 118: Line 121:
{{{
script -c "time fakeroot make -f debian/rules.real SOURCEVERSION='2.6.18.dfsg.1-12etch2.0.mactel' LOCALVERSION_HEADERS='-xen' MAJOR='2.6' VERSION='2.6.18' KERNEL_HEADER_DIRS='i386' ABINAME='-4' SUBARCH='xen' UPSTREAMVERSION='2.6.18' ARCH='i386' install-headers-i386-xen" ../typescript.2007072011
}}}

They were composed by getting the commands called by `binary-arch-i386-none-real` and `binary-arch-i386-xen-real` targets and substituting `binary-arch-subarch` in them with `install-headers-i386-(xen|none)`.

This page describes how to compile your own modified kernel from the linux-2.6 source package, rather than the debianized source tarball provided in linux-source-2.6.xx. Hopefully it will be integrated into the kernel handbook someday.

Purpose

My initial purpose was to build two images, very similar to linux-image-2.6.18-4-686 and linux-image-2.6.18-4-xen-686, but patched to properly support an Intel-based [MacBookPro].

The first image would be easy to produce by using the method to [http://kernel-handbook.alioth.debian.org/ch-common-tasks.html#s-common-building build a custom kernel from the debian kernel source]. However the second one would be a little more difficult, since there is no xen patch which is easily applyable to a debian kernel source. So I decided to reuse the linux-2.6 source package.

Actions

This method mostly follows the instructions detailed in the [http://kernel-handbook.alioth.debian.org/ch-common-tasks.html#s-common-official rebuilding an official Debian kernel package] section of the debian kernel handbook. The only modification is showing how to apply your patch in the build process.

Here's how I did it.

Get the source and tools

Follow the initial steps detailed in the handbook. Stop before invoking debian/rules. Additionally install package devscripts. In this example I will assume that the version of the downloaded source package was 2.6.18.dfsg.1-12etch2

Add changes in a new revision

It is good to create a new revision when you change the package, to distinguish it from the original. You also get a place to document your changes - in the changelog, which will subsequently be available in /usr/share/doc/linux-image-*/changelog.Debian.gz - for free. No need for long cryptic version strings which try to document all applied changes by themselves.

Add a patch

First, copy the patch you require into the debian/patches directory - it should be possible to apply it from within the root of the source tree, using patch -p1. In my case the filename was debian/patches/mactel.patch

Make the patch apply during build

Then, add a new patch series file, which contains the name of the patch, and is named after the revision we are creating. I usually add a suffix, which makes the version larger than the original (this way APT will not try to reinstall the package from the archive), but smaller than the new official package, which will let me notice when I need to update my package.

In this case, I created a file called debian/patches/series/12etch2.0.mactel with the following contents:

+ mactel.patch

that is, the name of the patch to apply, relative to the debian/patches directory

Add any config options

The kernel config file is created dynamically from a number of snippets scattered around the debian/arch/ directory. I needed to add two new config options together with the patch. Since I was going to build only a 686 and xen-686 flavors on the i386 architecture, it was suficient to add the following two lines at the end of the debian/arch/i386/config.686 file:

CONFIG_SENSORS_APPLESMC=m
CONFIG_USB_APPLEIR=m

since this file is used by both flavours I needed to build.

Create a new revision

We need the revision and the name of the series file to match, so invoke the following command when in the debian/ directory:

dch -v 2.6.18.dfsg.1-12etch2.0.mactel

And describe the changes in the editor which gets invoked.

Prepare for the build

First, since we modified some key files in the debian directory, we need to regenerate the control file. Do this using:

fakeroot debian/rules debian/control

The command fails, but that's on purpose, as described in the message which is produced.

Subsequently, as described in the handbook, you need to invoke the following command to prepare the build environment:

fakeroot debian/rules debian/build debian/stamps

Build the packages

I was then able to build the packages using:

script -c 'DEBIAN_KERNEL_JOBS=2 time fakeroot make -f debian/rules.gen binary-arch-i386-xen-686 binary-arch-i386-none-686 binary-arch-i386-xen-real binary-arch-i386-none-real' ../typescript.2007072001

which is nice, as it saves the typescript of the build for later investigation in case it fails for some reason. The environment variable setting DEBIAN_KERNEL_JOBS=2 causes a parallel build, which is more efficient if you have more than one CPU.

After a (long) while, it produced the following files (grouped with according to targets which produced them):

binary-arch-i386-none-686

linux-image-2.6.18-4-686_2.6.18.dfsg.1-12etch2.0.mactel_i386.deb
linux-headers-2.6.18-4-686_2.6.18.dfsg.1-12etch2.0.mactel_i386.deb

binary-arch-i386-none-real

linux-headers-2.6.18-4_2.6.18.dfsg.1-12etch2.0.mactel_i386.deb

binary-arch-i386-xen-686

linux-image-2.6.18-4-xen-686_2.6.18.dfsg.1-12etch2.0.mactel_i386.deb
linux-modules-2.6.18-4-xen-686_2.6.18.dfsg.1-12etch2.0.mactel_i386.deb
linux-headers-2.6.18-4-xen-686_2.6.18.dfsg.1-12etch2.0.mactel_i386.deb
xen-linux-system-2.6.18-4-xen-686_2.6.18.dfsg.1-12etch2.0.mactel_i386.deb

binary-arch-i386-xen-real

linux-headers-2.6.18-4-xen_2.6.18.dfsg.1-12etch2.0.mactel_i386.deb

Additional notes

ABI changes

The patch I needed to apply was relatively unintrusive, but if your changes modify the kernel's ABI (Binary Interface), by modifying some data structures or function declarations, then the build procedure is going to detect it and fail (possibly in a very verbose manner). You then need to copy the new ABI description file and create a new custom abi-ID.FLAVOR file in your arch directory. FIXME: possibly some more changes will be needed.

Patch clashes

In my case, the debian-provided xen patch had a small and luckily easy to fix clash with the mactel patch in the drivers/Makefile file. I was able to fix it by modifying the xen patch by hand to insert the necessary line at the end of the file, instead right next to the line which the mactel patch needed to modify.