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.

sehe
  • 374,641
  • 47
  • 450
  • 633
Aftnix
  • 4,461
  • 6
  • 26
  • 43
  • 2
    You can not run a Perl script with `sh`. Try `perl` and you will not get those `my: command not found` errors and the perl errors or warnings instead. – matthias krull Jul 13 '12 at 12:27
  • Looks like i'm the dumbest guy in the world. How could i do that :) – Aftnix Jul 13 '12 at 12:30
  • Does the script realy fail? From the code it looks like it just prints errors but does not fail if a module's code is not in the tree. See [line 375](http://git.kernel.org/?p=linux/kernel/git/stable/linux-stable.git;a=blob;f=scripts/kconfig/streamline_config.pl;h=bccf07ddd0b67a0e2f761fd5721f274a49bf9bbb;hb=HEAD#l375) – matthias krull Jul 13 '12 at 12:49
  • Another thing: If you run `make clean` and `make mrproper` you will always recompile the complete tree. This is not necessary. Usually you can recompile after changes without cleaning. This way only the changed modules will rebuild as the object files will be kept. – matthias krull Jul 13 '12 at 12:56
  • When i run it independently , i mean "perl , everything works perfectly. But if invoke it make localmodconfig, it restarts "make config". – Aftnix Jul 13 '12 at 12:57
  • 1
    You could still just unload the modules listed and run `make localmodconfig` again. – matthias krull Jul 13 '12 at 20:22

1 Answers1

10

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

Aftnix
  • 4,461
  • 6
  • 26
  • 43
  • 1
    you just saved me hours of going through the config (with my child interfering with my typing ☺). With your advice I could switch compile in all active modules with a simple sed-script. Thank you! `cp .config .config-old; make localmodconfig; for i in $(grep =m .config | xargs); do sed "s/$i/$(echo $i | sed s/=m/=y/)/" -i .config-old; cp .config-old .config; done` – Arne Babenhauserheide Jan 15 '14 at 16:04
  • isn't the streamline_config.pl script in 'scripts' not 'script' ? – Rob Latham Jul 04 '14 at 02:11
  • Use https://github.com/graysky2/modprobed-db to keep track of every module ever loaded over an extended period of time. The problem with just `make localmodconfig` is that some modules you need may not be loaded at the point when you run that command. – user7610 Feb 28 '20 at 00:26