Kernel Configuration and the .config Workflow
Kernel Configuration and the .config Workflow
The Linux kernel contains over 15,000 configurable options defined in a domain-specific language called Kconfig. The entire state of a build is recorded in a single plaintext file at the root of the kernel tree named .config.
Anatomy of .config
Inside .config, options follow a simple key-value format:
# A boolean option enabled statically in kernel:
CONFIG_BINFMT_ELF=y
# A tri-state option built as a loadable module:
CONFIG_EXT4_FS=m
# A disabled option (not compiled):
# CONFIG_EXT2_FS is not set
# An integer configuration parameter:
CONFIG_NR_CPUS=64
# A string parameter (e.g., custom distro kernel release tag):
CONFIG_LOCALVERSION="-byol-v1"Mandatory Options for a Bootable Modern Distro
When building a distribution kernel from scratch, disabling certain options will cause immediate boot failures:
- Executable Formats:
CONFIG_BINFMT_ELF=y: Essential for running standard Linux binaries.CONFIG_BINFMT_SCRIPT=y: Essential for interpreting#!/bin/shscripts.
- Virtual Filesystems:
CONFIG_DEVTMPFS=yandCONFIG_DEVTMPFS_MOUNT=y: Tells the kernel to mount/devautomatically at boot.CONFIG_PROC_FS=yandCONFIG_SYSFS=y.
- Storage & Controller Drivers:
CONFIG_BLK_DEV_SD=y: SCSI/SATA disk support.CONFIG_ATA=yandCONFIG_ATA_GENERIC=y.CONFIG_NVME_CORE=y: Modern NVMe SSD support.CONFIG_VIRTIO_PCI=yandCONFIG_VIRTIO_BLK=y: Essential for QEMU/KVM virtual machine testing.
- Filesystem Drivers:
CONFIG_EXT4_FS=yorCONFIG_BTRFS_FS=y: Compiled as=y(built-in) if booting without an initramfs, or=mif the initramfs contains the driver.
Compiling the Kernel Image
Once .config is validated:
# Build the compressed kernel image and modules (-j$(nproc) uses all CPU cores):
$ make -j$(nproc) bzImage
$ make -j$(nproc) modules
# Install kernel modules into the target sysroot:
$ make INSTALL_MOD_PATH=/mnt/target modules_install
# Copy the kernel image into the boot directory:
$ cp arch/x86/boot/bzImage /mnt/target/boot/vmlinuz-byol