I'm developing kernel modules right now, and the build times are starting to get under my skin. As a side effect I'm taking way too many "coffee" breaks during builds.
So I was looking for a way to build only the stuffs I need for my platform. Chapter 7 and 8 of "linux kernel in a nutshell" gave a good detail of how to do that by hand. Its a good read : http://www.kroah.com/lkn/
But Although I understand the stuffs, this is still a lot of tweaks to make that work.
2.6.32 and later kernels added a new target make localmodconfig. which scans through lsmod and change the .config appropriately. So I thought I found my "automation". But this perl script has some problem too.
This thread describes the problems : https://bbs.archlinux.org/viewtopic.php?pid=845113
There was also a proposed solution which apparently worked for others , is to run the script directly instead of using make's target.
Although for me, make localmodconfig does not work at all. its because of the following :
make clean
make mrproper
cp /boo/config-'uname -r' .config
make localmodconfig
and it halts with
vboxguest config not found!!
nf_defrag_ipv6 config not found!!
vboxsf config not found!!
vboxvideo config not found!!
The thing is my kernel development environment is inside virtualbox. These vbox modules were installed when I chose to install "virtualbox guest addtion".
And the netfilter module might be a Distribution specific module(Lot of netfilter modules are not part of the mainline kernel, so its not a shock to me), which is not included in mainline kernel.
Now the workaround this obviously unloading these module and trying again. But I'm thinking if there is patch for the streamline_config.pl which will enable the user to exclude certain modules if s/he wants. Problem is I have zero knowledge about perl and I like it that way.
So my problems in nutshell
Patching streamline_config.pl so I can give a list of module name as argument which it will exclude from processing the config file.
The script is located at kernel.org
EDIT: Removed the stuff about perl script not running. As mugen kenichi pointed out (How dumb I can be?). But still make localmodconfig does not work because of not having some modules code under source tree. patching streamline_config.pl still valid requirement.
解决方案
Anyone else trying to build a minimum kernel image also looking for reducing build time, should do the following:
1) copy distribution kernel config in your source tree. It can be done with either command given below:
$zcat /proc/config.gz > .config
or
$cp /boot/config-'uname -r' .config
2) Use localmodconfig target.
$make localmodconfig
It will use lsmod to find which modules are loaded at this moment. Then it will search through distribution's .config to enable them and disable others.
Its important to know that it does not always work flawlessly. So you should tweak your config further using make menuconfig. You will see some modules are still marked to be built which is in reality unnecessary for your system.
Sometimes out of tree modules may cause make localmodconfig to fail. If that's the case you can work around that issue in two ways :
a) unload the out of tree modules and try make localmodconfig again. b) Run the perl script directly:
3) Install ccache[1]. It will improve your build time dramatically. It caches objects. So it will reduce subsequent builds.
Its possible that ccache is included in the distribution's repository so that you can install it through apt-get or yum. In CentOS its available in EPEL repo.[2]
4) Give as many cores as possible for the build job
I'm developing kernel modules right now, and the build times are starting to get under my skin. As a side effect I'm taking way too many "coffee" breaks during builds.
So I was looking for a way to build only the stuffs I need for my platform. Chapter 7 and 8 of "linux kernel in a nutshell" gave a good detail of how to do that by hand. Its a good read : http://www.kroah.com/lkn/
But Although I understand the stuffs, this is still a lot of tweaks to make that work.
2.6.32 and later kernels added a new target make localmodconfig. which scans through lsmod and change the .config appropriately. So I thought I found my "automation". But this perl script has some problem too.
This thread describes the problems : https://bbs.archlinux.org/viewtopic.php?pid=845113
There was also a proposed solution which apparently worked for others , is to run the script directly instead of using make's target.
Although for me, make localmodconfig does not work at all. its because of the following :
and it halts with
The thing is my kernel development environment is inside virtualbox. These vbox modules were installed when I chose to install "virtualbox guest addtion".
And the netfilter module might be a Distribution specific module(Lot of netfilter modules are not part of the mainline kernel, so its not a shock to me), which is not included in mainline kernel.
Now the workaround this obviously unloading these module and trying again. But I'm thinking if there is patch for the streamline_config.pl which will enable the user to exclude certain modules if s/he wants. Problem is I have zero knowledge about perl and I like it that way.
So my problems in nutshell
Patching streamline_config.pl so I can give a list of module name as argument which it will exclude from processing the config file.
The script is located at kernel.org
EDIT: Removed the stuff about perl script not running. As mugen kenichi pointed out (How dumb I can be?). But still make localmodconfig does not work because of not having some modules code under source tree. patching streamline_config.pl still valid requirement.
Anyone else trying to build a minimum kernel image also looking for reducing build time, should do the following:
1) copy distribution kernel config in your source tree. It can be done with either command given below:
or
2) Use localmodconfig target.
It will use lsmod to find which modules are loaded at this moment. Then it will search through distribution's .config to enable them and disable others.
Its important to know that it does not always work flawlessly. So you should tweak your config further using make menuconfig. You will see some modules are still marked to be built which is in reality unnecessary for your system.
Sometimes out of tree modules may cause make localmodconfig to fail. If that's the case you can work around that issue in two ways :
a) unload the out of tree modules and try make localmodconfig again. b) Run the perl script directly:
3) Install ccache[1]. It will improve your build time dramatically. It caches objects. So it will reduce subsequent builds.
Its possible that ccache is included in the distribution's repository so that you can install it through apt-get or yum. In CentOS its available in EPEL repo.[2]
4) Give as many cores as possible for the build job
My results are :
我现在正在开发内核模块,构建时间已经开始深入人心了.作为副作用,我在构建过程中占用了太多的"咖啡"时间.
因此,我一直在寻找一种仅构建平台所需材料的方法."简而言之,Linux内核"的第7章和第8章详细介绍了如何手动执行该操作.很好阅读: http://www.kroah.com/lkn/
但是,尽管我了解其中的内容,但仍然需要进行很多调整才能使其正常工作.
2.6.32和更高版本的内核添加了一个新的目标 make localmodconfig .它会扫描 lsmod 并适当地更改.config.所以我以为我找到了"自动化".但是这个perl脚本也有一些问题.
此线程描述了问题: https://bbs.archlinux.org/viewtopic.php?pid = 845113
还有一个提议的解决方案显然对其他人有用,它是直接运行脚本而不是使用make的目标.
尽管对我来说,使localmodconfig根本不起作用.其原因如下:
并停止
找不到问题是我的内核开发环境在virtualbox内部.当我选择安装"virtualbox来宾添加"时,就安装了这些vbox模块.
netfilter模块可能是一个特定于发行版的模块(很多netfilter模块都不是主线内核的一部分,所以这对我来说并不奇怪),
现在,解决方法显然是卸载这些模块,然后重试.但是我在考虑是否有 streamline_config.pl 的补丁程序,如果需要,它将使用户能够排除某些模块.问题是我对perl的了解为 zero ,我喜欢这种方式.
所以我在 nutshell
中遇到的问题修补 streamline_config.pl ,因此我可以给出模块名称列表作为参数,以免处理配置文件.
该脚本位于 kernel.org
编辑:删除了有关perl脚本未运行的内容.正如古根贤一指出的那样(我有多愚蠢?).但是仍然使make localmodconfig 不起作用,因为在源代码树下没有一些模块代码.修补 streamline_config.pl 仍然有效.
尝试构建最小内核映像并寻求减少构建时间的其他任何人,都应执行以下操作:
1)在源代码树中复制分发内核配置.可以使用以下任一命令完成此操作:
或
2)使用localmodconfig目标.
它将使用 lsmod 查找此时正在加载的模块.然后它将搜索发行版的.config启用它们并禁用其他.
重要的是要知道它并不总是完美无瑕的.因此,您应该使用 make menuconfig 进一步调整配置.您会看到一些模块仍标记为已构建,实际上这对于您的系统来说是不必要的.
有时树模块不足可能会导致make localmodconfig失败.如果是这种情况,您可以通过两种方式解决该问题:
a)卸载树外模块,然后再次尝试 make localmodconfig .b)直接运行perl脚本:
3)安装 ccache [1].它将大大缩短您的构建时间.它缓存对象.因此,它将减少后续构建.
ccache可能包含在发行版的存储库中,因此您可以通过 apt-get 或 yum 安装它.在CentOS中,它可以在EPEL仓库中使用.[2]
4)为构建作业提供尽可能多的内核
我的结果是:
[1] http://ccache.samba.org/[2] http://fedoraproject.org/wiki/EPEL