Skip to main content

TECH VEDA

Corporate on-site training - Submit proposal Pick your modulesSharpen your kernel skills: deep dives, drivers, Yocto, CVEs, careers — updated daily. Read the blog →
Tool Spotlight

merge_config.sh: Merge Kernel Config Fragments and Check the Result

merge_config.sh is the kernel script that merges kernel config fragments into a .config. Learn its options, a debug workflow, and its -s check.

merge_config.sh: Merge Kernel Config Fragments and Check the Result

merge_config.sh is the kernel’s own script for building a .config from a base configuration and a set of kernel config fragments. The kernel’s make targets call it, and Yocto and Buildroot run their own copies of it. This article covers its options, a workflow that builds a debug configuration from a base defconfig, how the script checks that every fragment line reached the final .config, and the kernel version that changed that check.

Most board teams do not keep one full .config per build. They keep a base defconfig and small kernel config fragments: one for debugging, one for a product feature, one for a test build. scripts/kconfig/merge_config.sh is the tool that turns a base and a list of fragments into one resolved configuration, and then tells you which requested values did not survive.

The problem: one board, several kernel configurations

A typical product needs at least two kernels: a production build and a debug build with options such as dynamic debug and lock checking. Full .config copies for each build drift apart, and nobody can say which differences were intended. Kernel config fragments solve this. Each fragment lists only the options it changes, so a debug fragment can be two lines long and reused on every board.

Two things are then needed. Something must apply the fragments in a known order on top of the base and let Kconfig fill in the rest. Something must also check the result, because Kconfig still applies its rules: a requested option is dropped if a dependency is missing, if the symbol has no prompt and can only be selected by another option, or if it was renamed. merge_config.sh does both.

What merge_config.sh is

It is a shell script in the kernel source at scripts/kconfig/merge_config.sh. Its header describes it as taking a list of config fragments, merging them one by one, and warning about overridden values and about requested values that did not reach the resulting .config.

  • Where it lives: the mainline kernel tree, under the KCONFIG entry of the MAINTAINERS file (maintainers Nathan Chancellor and Nicolas Schier, list linux-kbuild, status “Odd Fixes”).
  • Version: it has no version of its own; it changes with the kernel. This article uses the copy in Linux 7.3, whose latest stable release is 7.3.7, dated 30 November 2026. The most recent change to the script in mainline is dated 13 July 2026. It was rewritten to use awk in early 2026, and that rewrite first appears in Linux 7.0.
  • Licence: GPL-2.0.

Yocto’s kernel-yocto class runs it in do_kernel_configme, and Buildroot runs it when it applies BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES.

Get it

There is no separate package. Any kernel source tree has it, and it runs on the build host with the tree’s own Kconfig. It needs a C compiler, flex, bison and awk. Yocto runs the copy shipped in yocto-kernel-tools, built as the kern-tools-native recipe, and writes its output to cfg/merge_config_build.log in the kernel metadata directory. Buildroot keeps a copy at support/kconfig/merge_config.sh. Check the copy your build actually runs; these were not compared line by line with the kernel’s.

The commands worth knowing

All of these run on the build host, from the top of the kernel source tree. The first argument is the base configuration; the rest are kernel config fragments, applied in the order given. If two files set the same symbol, the later one wins and the script prints the previous and new values.

1. Merge and resolve. With no options, the script merges the fragments into a temporary file, runs make alldefconfig with that file as KCONFIG_ALLCONFIG, and then compares every requested line with the final .config. -O names an existing output directory.

raghu@techveda:~$ cd linux
raghu@techveda:~$ ARCH=arm64 scripts/kconfig/merge_config.sh -O ../build ../frag/base.cfg ../frag/debug.cfg

For each requested value that is missing from the result, it prints “Value requested for CONFIG_X not in final .config” with the requested and actual values. In 7.0 and later these messages start with “WARNING:”.

2. Merge only: -m. Writes the merged file as the configuration and stops, without running make and without the final comparison. The kernel’s make <name>.config targets and Buildroot use this form and run their own make step afterwards.

3. Start from nothing: -n. Uses allnoconfig instead of alldefconfig, so anything not requested is off. Yocto passes -n when KCONFIG_MODE selects allnoconfig, or when no mode is set and the recipe supplies a defconfig.

4. Strict mode: -s. Fails if a fragment redefines a value. In Linux 7.0 and later it also exits with status 1 and prints “Requested and effective config differ” when the final comparison finds a difference. Up to and including 6.19, it fails only on redefinition, and the final comparison only prints warnings.

raghu@techveda:~$ ARCH=arm64 scripts/kconfig/merge_config.sh -s -O ../build ../frag/base.cfg ../frag/debug.cfg

5. Controlling the messages: -r, -y, -Q. -r lists fragment lines that repeat a value already set. -y stops a fragment from turning a built-in option into a module. -Q hides the overridden-value messages.

The kernel tree also ships ready-made fragments in kernel/configs/ and arch/<arch>/configs/, for example debug.config, hardening.config and kvm_guest.config. make ARCH=arm64 defconfig debug.config applies one through this script with -m and then runs olddefconfig.

One workflow: a debug build from kernel config fragments

This sequence was run on a Linux 7.3.7 tree with ARCH=arm64. The goal is a debug kernel from the arm64 defconfig plus a two-line fragment, failing if any fragment line does not take effect.

First, produce a minimal base with savedefconfig. It writes a defconfig that Kconfig generated itself, so the base does not contain lines that Kconfig would drop:

raghu@techveda:~$ make ARCH=arm64 O=../build defconfig
raghu@techveda:~$ make ARCH=arm64 O=../build savedefconfig
raghu@techveda:~$ cp ../build/defconfig ../frag/base.cfg

The choice of base matters. A strict run in this test that used arch/arm64/configs/defconfig directly as the base also failed on lines that the upstream defconfig requests but Kconfig does not keep. A separate run that used a full .config as the base reported options that a fragment had selected, because the base listed them as not set. Neither message was about the fragment.

The first version of the debug fragment, debug.cfg, held CONFIG_DYNAMIC_DEBUG=y and CONFIG_LOCKDEP=y. Merge it in strict mode and read the exit status:

raghu@techveda:~$ ARCH=arm64 scripts/kconfig/merge_config.sh -s -O ../build ../frag/base.cfg ../frag/debug.cfg
raghu@techveda:~$ echo $?

The run printed the “not in final .config” warning for CONFIG_LOCKDEP and exited with status 1. In lib/Kconfig.debug, LOCKDEP has no prompt; PROVE_LOCKING, LOCK_STAT and DEBUG_LOCK_ALLOC select it. After changing the line to CONFIG_PROVE_LOCKING=y, the same command exited with status 0, and the final .config contained both CONFIG_PROVE_LOCKING=y and CONFIG_LOCKDEP=y. In CI, the same command fails the build when a kernel upgrade drops a symbol that a fragment requests.

To confirm on the running board, read the configuration of the kernel that booted. This needs CONFIG_IKCONFIG_PROC:

root@qemuarm64:~# zcat /proc/config.gz | grep PROVE_LOCKING

The TECH VEDA guide to cross-compiling an arm64 kernel and booting it in QEMU covers the build and boot steps around this configuration step.

Limits

  • Kernel version. A non-zero exit status for a missing value needs the script from 7.0 or later. With a 6.x vendor kernel, -s does not catch it, so read the warnings.
  • It reports, it does not explain. The script says a value was lost, not why. Use make menuconfig and search for the symbol to see its dependencies and what selects it. In Yocto, the kernel-yocto class runs a separate audit through symbol_why.py, controlled by KCONF_AUDIT_LEVEL.
  • The make targets skip the check. make defconfig debug.config merges with -m and then runs olddefconfig, so a dropped line produces no warning. Buildroot also merges with -m.

Key takeaways

  • merge_config.sh builds a .config from a base and kernel config fragments, applied in command-line order.
  • It runs alldefconfig (or allnoconfig with -n) and then compares every requested value with the result, unless it runs with -m.
  • From Linux 7.0, -s exits with status 1 when a requested value is missing, which makes it usable in CI.
  • A base written by savedefconfig keeps the messages about your own fragments.
  • The kernel’s make <name>.config targets, and Buildroot, use -m and do not run the comparison.
Was this worth your time?

Frequently asked questions

What does merge_config.sh do?

It merges a base configuration and a list of kernel config fragments, runs make alldefconfig (or allnoconfig with -n) on the result, and compares each requested value with the final .config.

Which merge_config.sh option makes a missing value fail the run?

The -s option. From Linux 7.0 it exits with status 1 and prints “Requested and effective config differ”. Up to 6.19 it fails only when a fragment redefines a value.

Does make defconfig debug.config check the fragment?

No. That target calls merge_config.sh with -m and then runs olddefconfig, so the final comparison is not run.

What base file should I use?

A defconfig written by make savedefconfig. An upstream defconfig or a full .config used as the base adds messages that are not about your own kernel config fragments.

References

RB
Raghu Bharadwaj

Founder, TECH VEDA — 20+ years teaching the Linux kernel, device drivers and embedded systems.

Follow on LinkedIn

Get the best of TECH VEDA by email

The best of our kernel and embedded Linux writing, a few emails a month. No spam.

We email occasionally and never share your address.