红联Linux门户
Linux帮助

How-to create a custom Ubuntu Linux kernel package

发布时间:2007-10-13 21:27:28来源:红联作者:hearer
by Markus Kolb

This is a description for the unsupported official way to build your own linux-kernel-image packages. If you don't know why you should need an own, customized kernel you won't need to read this text.

For nomal users it is better to use the supported official kernel provided by Ubuntu because you'll get automatic security updates and don't have to build the kernel over and over again yourself.

But sometimes there is the need for own changes in the running kernel. Maybe some additional feature patches or important bugfixes not included in the official kernel.

Then there are a few people outside who want to have a smaller kernel optimized for their computer environment.

This how-to will NOT explain which kernel configure options you will need that everything runs fine. If you remove kernel options you should know what you do or can try-and-error.

You have to use an Ubuntu Linux installation for the procedure. You can not build a Ubuntu kernel image from the Ubuntu sources in another distribution like Debian without tricks.

Please be patient and tell me if I have made mistakes in English. I am German and of course not perfect.

These instructions apply to Ubuntu 4.10 (Warty Warthog).
Changes

Dec, 25th 2004 - Markus Kolb - publication of the howto.

Apr, 23rd 2005 - Chris Fazekas - added 'sudo apt-get install devscripts' to install required app 'dch'.
Packages needed for kernel build and Debian package build

For this procedure you must ensure that the following lines are uncommented in /etc/apt/sources.list:

deb-src http://archive.ubuntu.com/ubuntu/ warty main restricted
deb-src http://security.ubuntu.com/ubuntu/ warty-security main restricted

Now you must run:

$ sudo apt-get update

You can install all packages needed for the build using these commands:

$ sudo apt-get build-dep linux-source-2.6.8.1
$ sudo apt-get install fakeroot
$ sudo apt-get install devscripts

Download of the right Ubuntu kernel sources

Don't use the linux-source packages from the binary repository. The package build process of these sources won't make the right image which can run Ubuntu without a few manual interventions.

So you should download the real kernel package sources which Ubuntu uses for kernel package build, too.

To download the source you change to the directory where you want to save the source.

Then run:

apt-get source linux-source-2.6.8.1

Three files will be downloaded.

The source description file with extension .dsc, the gziped tarball with the original kernel source and a gziped diff file which includes the changes between original source and Ubuntu source.

The files will be extracted to the subdirectory linux-source-2.6.8.1 and patched with the diff.

You have not to do anything.

If you want to do the extraction later yourself you can use dpkg-source -x .
Create a new version entry in changelog

From now on every directory description will be relative to the extracted source directory and if no information about a change to a specific directory is given you should be in the source directory.

You must add a new entry to the changelog in debian/changelog.

For this you can use the tool dch.

$ dch -i

Will add a new entry to the changelog with incremented version number and opens the file in your texteditor. You should enter a short description what you'll change and adjust the version number to the existing one with a custom extension.

For example the last existing entry was:

linux-source-2.6.8.1 (2.6.8.1-16.5) warty-security; urgency=high

The incremented entry will be:

linux-source-2.6.8.1 (2.6.8.1-16.6) warty-security; urgency=low

If you use the version 2.6.8.1-16.6 you won't get the next security update from Ubuntu repository. So use an extension instead:

linux-source-2.6.8.1 (2.6.8.1-16.5custom) warty; urgency=low
Change the kernel configuration

The kernel configuration is in the directory debian/config.

Each archictecture and each target processor has its own config file.

So if you want to change the config for i386 architecture 686 processor you have to edit the file debian/config/386/686.

Please remember what I have told you before. You will be on your own if you change the config.

If you do something wrong some hardware of your computer might be unsupported and there can be error messages during the Linux init at startup.
Change the kernel source

Don't do this in the source itself. There are many patches which will be merged during the package build. So if you change a part where a patch will merge, the kernel package build will stop with an error.

Use dpatch files instead. It is the official way to change the source.
Dpatching the kernel source

The dpatch files are stored in the directory debian/patches.

If you have a normal patch file created with diff-tool you can make a dpatch file out of it.

Use the command:

$ dpatch patch-template -p “{patchname}” “{patch-description}” < {diff-file} > debian/patches/{patchname}.dpatch

If you must change the source you can use:

$ dpatch-edit-patch {new-patchname}

This will generate a copy of the source directory and calls a new shell. You can make any changes in this new temporary directory. After exiting this shell with “exit” the changes will be added to the new dpatch file debian/patches/{new-patchname}.dpatch.

After the changes are in place you have to tell the build that there are new patches. For this copy the latest debian/patches/00list-* file (in the example this is 00list-16.5) to debian/patches/00list-*custom (e.g. 00list-16.5custom).

Then edit this created copy and append the new dpatch name without the .dpatch extension.

For details read debian/README.NMU!
Building the kernel packages

Now you are nearly ready to start the package build. But if you will start it now the packages will be build for each processor of your architecture (386, 686, 686-smp, ...).

You can change this in editing the file debian/rules.

Search for the part defining the flavours:

#flavours := $(shell \
# find debian/config/$(arch) -maxdepth 1 -type f ! -name default \
# -printf '%f\n' \
#)

Comment out these lines and add a new definition of flavours with your wished processor:

flavours := k7

The flavours correspond to the directories in debian/config/{architecure}.

Now we can start the package build:

dpkg-buildpackage -rfakeroot -us -uc -b

This will build the binary packages if you have not make any mistake ;o)

When build has finished you will find the deb-packages in the parent directory of the source.

In the example this would be:

linux-doc-2.6.8.1_2.6.8.1-16.5custom_all.deb
linux-headers-2.6.8.1-4_2.6.8.1-16.5custom_i386.deb
linux-headers-2.6.8.1-4-k7_2.6.8.1-16.5custom_i386.deb
linux-image-2.6.8.1-4-k7_2.6.8.1-16.5custom_i386.deb
linux-patch-debian-2.6.8.1_2.6.8.1-16.5custom_all.deb
linux-source-2.6.8.1_2.6.8.1-16.5custom_all.deb
linux-tree-2.6.8.1_2.6.8.1-16.5custom_all.deb

Juhuu.
Building other module packages

There exist more kernel related packages like the linux-restricted-modules package. If you have patched the kernel and you use module-packages it can be possible that you have to rebuild them, too.

If you have to depends on the patches.

The procedure to build these module-packages should be mostly the same as the kernel-package.
More information and options

There are many more options for the different tools used for building the kernel package.

So it would be a good idea to read at least short through the manpages of the tools to know what they do.

Simply type

$ man {toolname}

for this.
Changes to this how-to

You are free to make any changes to this how-to but you must note it in the Changes section above with date, time, your name and a short description.

The note about the origin author should stay where it is.

Translations to other languages should not translate or append/change the Changes section.

Any changes to this how-to should be made first to the English version.
文章评论

共有 0 条评论