When working with Linux kernel builds, developers often need to upgrade their configuration from an older kernel version. The standard make oldconfig
process prompts interactively for each new configuration option, which becomes tedious when dealing with hundreds of new options across kernel versions.
There are several approaches to automate the acceptance of default values:
# Method 1: Using yes with default newline
yes '' | make oldconfig
# Method 2: Using KCONFIG_ALLCONFIG
echo "CONFIG_CMDLINE=\"\"" > .config.defaults
make KCONFIG_ALLCONFIG=.config.defaults oldconfig
# Method 3: Using scripts/config
./scripts/config --file .config --set-str CONFIG_LOCALVERSION "-custom"
make olddefconfig
The most reliable solution is actually built into the kernel build system:
make olddefconfig
This command:
- Preserves all existing configuration options
- Automatically sets new options to their default values
- Doesn't prompt for any user input
- Maintains configuration file integrity
Here's how I typically update my kernel configuration:
# Copy existing config
cp /boot/config-$(uname -r) .config
# Update to new defaults automatically
make olddefconfig
# Optionally review changes
diff -u /boot/config-$(uname -r) .config | less
# Build with new configuration
make -j$(nproc)
For more complex scenarios, you might want to combine multiple techniques:
#!/bin/bash
# Backup current config
cp .config config.bak
# Merge specific customizations
./scripts/config --file .config --enable DEBUG_INFO
# Update all other options to defaults
make olddefconfig
# Verify critical options
if ! grep -q "CONFIG_MODULES=y" .config; then
echo "Warning: Modules support disabled!" >&2
fi
This approach gives you both automation and control over critical configuration options.
When porting an existing .config
to a newer kernel version, the traditional make oldconfig
workflow requires manual intervention for new configuration options. This becomes particularly problematic in automated build environments or when maintaining multiple kernel configurations.
The standard process preserves existing settings while prompting for new options:
make oldconfig
# For each new option:
# > New config option (CONFIG_FOO) [Y/n/m/?] (NEW)
For truly non-interactive operation with automatic defaults:
Method 1: Using yes and pipes
yes "" | make oldconfig
This feeds empty responses (defaults) to all prompts.
Method 2: KCONFIG_ALLCONFIG
Create a minimal config file (defaults.cfg
) with specific overrides, then:
KCONFIG_ALLCONFIG=defaults.cfg make oldconfig
Method 3: Combined approach
For complete automation while allowing some custom defaults:
# Set defaults for specific options
echo "CONFIG_NEW_FEATURE=y" > override.cfg
# Accept defaults for all others
KCONFIG_ALLCONFIG=override.cfg yes "" | make oldconfig
For build systems, combine with other config manipulation:
# Example in a build script
cp /boot/config-$(uname -r) .config &&
sed -i 's/CONFIG_DEBUG_INFO=y/CONFIG_DEBUG_INFO=n/' .config &&
yes "" | make oldconfig &&
make -j$(nproc)
Watch for these scenarios:
- Options removed in newer kernels may trigger warnings
- Some options might have non-obvious dependencies
- Architecture-specific defaults may vary
Always check the resulting config:
grep "NEW" .config
Should return no matches if all new options were properly handled.