如何制作Ubuntu自定义的内核

参与到Ubuntu的翻译中来
回复
头像
oneleaf
论坛管理员
帖子: 10441
注册时间: 2005-03-27 0:06
系统: Ubuntu 12.04

如何制作Ubuntu自定义的内核

#1

帖子 oneleaf » 2005-06-07 15:24

How-to create a custom Ubuntu Linux kernel package

by Markus Kolb <ubuntu-ml -at- tower-net.de>

December 25th 2004

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 <source-description.dsc>.
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.
上次由 oneleaf 在 2005-06-08 20:34,总共编辑 1 次。
当净其意如虚空,远离妄想及诸取,令心所向皆无碍
cocos
帖子: 19
注册时间: 2005-06-05 11:40
来自: pku

#2

帖子 cocos » 2005-06-07 18:49

How-to create a custom Ubuntu Linux kernel package

by Markus Kolb <ubuntu-ml -at- tower-net.de>

December 25th 2004

如何制作Ubuntu自定义的内核

Markus Kolb <ubuntu-ml -at- tower-net.de>

2004年12月25日


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.
对于一般用户,使用ubuntu提供的官方内核可能更好,因为这样你可以自动并且安全的获得更新,也没有必要一次又一次的自己去编译内核。

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.
这篇how-to并不会讲怎样的内核配置选项才能使你所有的东西完美运行.如果你想要移除某些内核选项,你必须明白你在做什么或者敢于尝试和犯错误.

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.
你必须使用Ubuntu Linux系统进行以下程序。 你不能在其他的发行版中,比如Debian,来通过Ubuntu的源码来编译Ubuntu内核,除非使用某些技巧.

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).
这份指南适用于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:
你首先需要确认 /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
下载正确的Ubuntu内核源码

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.
不要使用二进制库(binary repository)中的linux源码包(linux-source packages).这些包产生的进程不能产生正确的映像,Ubuntu将不能正常运行,除非人为介入.

So you should download the real kernel package sources which Ubuntu uses for kernel package build, too.
所以你还必须下载Ubuntu使用的正确的内核源码包.

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.
源码的描述文件,extension.dsc,gzip打包的原始的内核源码和gzip打包的diff文件,里面包括原始源码和Ubuntu源码的差别。

The files will be extracted to the subdirectory linux-source-2.6.8.1 and patched with the diff.
这些文件将会被解压到linux-source-2.6.8.1的子目录,并打上diff的补丁.

You have not to do anything.
你并不需要做任何事情.

If you want to do the extraction later yourself you can use dpkg-source -x <source-description.dsc>.
如果你想要之后自己解压,你可以使用 dpkg-source-x <source-description.dsc>

Create a new version entry in changelog
在更改日志(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.
你必须在debian/changelog中添加一条新的记录.

For this you can use the tool dch.
此时你可以使用工具dch

$ dch -i
$ 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.
将会在changelog中添加一条新的记录,包括添加增量后的版本号.并在你的文本编辑器中打开这个文件.你可以输入简短的描述说明你希望更改的内容,也可以调整版本号使之包括一个自定义的扩展.

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:
如果你使用版本号 2.6.8.1-16.6 ,你将不能从Ubuntu的软件库中获得下次安全的升级.所以使用扩展替换为:

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.
内核配置在目录 debian/config 下

Each architecture 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.
所以如果你想为i386架构 686处理器更改设置,你必须修改文件 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
如果你做错了某些事情,你电脑的某些硬件可能不会被支持,Linux启动时会有出错信息.

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.
但可以使用dpatch文件.这个文件通过官方途径来修改源码.

Dpatching the kernel source
Dpatching内核源码.

The dpatch files are stored in the directory debian/patches.
dpatch文件在 debian/patches目录下.

If you have a normal patch file created with diff-tool you can make a dpatch file out of it.
如果你有通过diff-tool工具创建的通常的patch文件,你可以用它来制作一个dpatch 文件.

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.
这将会生成一个源文件目录的副本,并打开一个新的shell.你可以对这个新的暂时的目录作任何更改.通过"exit"退出这个shell之后,所有的更改将会添加到新的dpatch文件( 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).
在作出更改之后你必须在编译时声明存在新的补丁.对此,你可以复制最新的debian/patches/00list-* file(样例中为00list-16.5)到 debian/patches/00list-*custom(例如 00list-16.5custom).

Then edit this created copy and append the new dpatch name without the .dpatch extension.
然后修改这个副本并添加新的dpatch名称,名称中不含.dpatch的扩展.

For details read debian/README.NMU!
更多的细节请阅读 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, ...).
现在你几乎已经做好准备编译源码了,但是如果你现在开始,源码将会对你架构上的每个处理器都编译(386,686,686-smp,...)
You can change this in editing the file debian/rules.
你可以在 debian/rules中作出更改.

Search for the part defining the flavours:
搜索定义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:
注释以下几行并添加你希望的处理器新的flavour定义

flavours := k7

The flavours correspond to the directories in debian/config/{architecure}.
flavours和 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)
如果你没有任何失误,这将会编译二进制源码;o)

When build has finished you will find the deb-packages in the parent directory of the source.
编译结束后,你可以在源文件目录的上一级目录中找到 deb包.

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.
有更多与内核相关的包,像 linux-restricted-modules. 如果你修改过内核并且你会使用这些模块,很可能你还还要将它们也重新编译.

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.
头像
oneleaf
论坛管理员
帖子: 10441
注册时间: 2005-03-27 0:06
系统: Ubuntu 12.04

#3

帖子 oneleaf » 2005-06-08 20:33

当净其意如虚空,远离妄想及诸取,令心所向皆无碍
头像
millenniumdark
论坛版主
帖子: 4159
注册时间: 2005-07-02 14:41
系统: Ubuntu 14.04 (Kylin)
联系:

#4

帖子 millenniumdark » 2006-07-31 18:35

适用于4.10,而且编译内核的文章也不少了
先放着
wsh9308
帖子: 15
注册时间: 2007-03-27 13:18

#5

帖子 wsh9308 » 2007-04-10 18:49

支持楼主,就当是学习一下英语了谢谢!
头像
东方不坏
帖子: 843
注册时间: 2007-04-05 3:09
系统: Deepin
来自: 身后某处
联系:

#6

帖子 东方不坏 » 2007-05-22 0:07

不错,强烈支持这种精神
[color=#FFFF00]东方不败[/color] 写了:
  • OS:Ubuntu14.10
  • CPU:Athlon II 651K
  • RAM:威刚DDR3 1600 4GX2双通道
  • 主板:GA-A75M-DS2
  • 硬盘:西数64M版 2T
  • 显卡:迅景6790
  • 显示器:LG W2242TP
头像
1900
帖子: 36
注册时间: 2007-05-21 22:30
来自: BIT

#7

帖子 1900 » 2007-07-07 23:04

积极响应,赞
△q△p=h/4π
yuyumen
帖子: 10
注册时间: 2007-07-21 23:17

#8

帖子 yuyumen » 2007-07-26 19:10

好多的英文呢,但是翻译了我野不知道再说什么
yyhero01
帖子: 29
注册时间: 2007-06-22 10:47

#9

帖子 yyhero01 » 2007-08-16 11:13

记号。
xxsun
帖子: 4
注册时间: 2007-09-13 10:36

#10

帖子 xxsun » 2007-09-13 15:50

不错! :wink:
回复