Trying to find all the kernel modules needed for my machine using shell script

旧巷老猫 提交于 2021-02-04 10:27:10

问题


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

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

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


回答1:


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:

$chmod +x script/kconfig/streamline_config.pl
$perl script/kconfig/streamline_config.pl > .config

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

$make -j8 CC="ccache gcc"

My results are :

real 3m10.871s
user 4m36.949s
sys 1m52.656s

[1] http://ccache.samba.org/ [2] http://fedoraproject.org/wiki/EPEL



来源:https://stackoverflow.com/questions/11470447/trying-to-find-all-the-kernel-modules-needed-for-my-machine-using-shell-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!