How to build a custom kernel with localmodconfig that support hardware of multiple machines?

9,157

The make localmodconfig command is still the right tool for the job. In fact make localmodconfig runs scripts/kconfig/streamline_config.pl.

File input

When reading the streamline_config.pl (perl) source code, there is an undocumented feature my $lsmod_file = $ENV{'LSMOD'}; that allows file input for loaded module detection instead of the output from the lsmod command.

Live CD

Because localmodconfig uses the output lsmod to detect the loaded modules. We run a Ubuntu Live CD on each of the different hardware setups, open a terminal (Ctrl+Alt+T), run lsmod and save its output.

Concatenate output

By concatenating the lsmod output files while stripping consecutive headers lines you can quickly create an input file that covers all your required kernel modules. We like to review the module list by hand and use a more manual recipe:

  1. $ cd linux-3.11.0/
    or go the directory where you will run your make command

  2. $ lsmod > lsmod.txt
    creates a text file with your loaded modules

  3. $ nano lsmod.txt
    will open the nano text editor, of course you can use your favorite editor application

  4. Append your desired modules that are not already there, to the bottom of this file (see for an example the bottom of this anwer), and save it when you are ready.
    Note: use spaces not tabs to match the column tabulator positions.

  5. $ make LSMOD="lsmod.txt" localmodconfig
    this will tell localmodconfig to use your lsmod.txt file as input for loaded modules detection

With regards to Steven Rostedt - the author of steamline_config.pl - for suggesting a shorter notation in step 5.


Example for what to append and not append to lsmod.txt (step 4):

Because the Intel D33217CK main board has Intel thermal sensors that we would like to read, we append these lines:

x86_pkg_temp_thermal   13810  0
intel_powerclamp       14239  0

But we don't want to run virtual machines on this hardware, that is why we skip these lines:

kvm_intel             128218  0
kvm                   364766  1 kvm_intel

It has an Apple (Broadcom) Gibabit ethernet adapter connected to its Thunderbolt port, so we append:

tg3                   152066  0
ptp                    18156  1 tg3
pps_core               18546  1 ptp

We think we don't need volume mirroring, and therefor do not add:

dm_mirror              21715  0
dm_region_hash         15984  1 dm_mirror
dm_log                 18072  2 dm_region_hash,dm_mirror

And we also don't need graphics output (text will do on a headless server), so we do not include:

i915                  589697  3
i2c_algo_bit           13197  1 i915
drm_kms_helper         46867  1 i915
drm                   242354  4 i915,drm_kms_helper

For another machine we need this Realtek ethernet driver aditionally:

r8169                  61434  0
mii                    13654  1 r8169
Share:
9,157

Related videos on Youtube

Pro Backup
Author by

Pro Backup

Pro Backup provides backup storage in different locations within Europe for a low price. Starting € 4,72 per month for 98 GiB's of backup space at 2 different locations. Including Code42 "Crashplan Pro" or PROe software for Mac OS X, Windows, Linux or Solaris that automates the process.

Updated on September 18, 2022

Comments

  • Pro Backup
    Pro Backup over 1 year

    When configuring a server to run a single task, like an appliance, there might rise the need to build a custom kernel. For example to save disk space.

    Ubuntu Core 13.10 amd64 root filesystem is a 38 MB download, where the "linux-image-generic" meta package including required dependencies will download 79 MB of archives, and the size of a kernel-image-x.y.z-generic package is still 14 MB.

    For building a kernel that is stripped from modules that your hardware will not use, the make localmodconfig command is the right tool for the job. However your virtual machine that runs your build and test environment loads different modules than your target deployment hardware. And/or after a while your deployment hardware might become eol, and different hardware is used. And at the frequency where kernel updates are released it might become too cumbersome to build a custom kernel for every different hardware configuration.

    How to quickly build a custom Linux kernel that runs on a few different hardware boxes?