You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

内核配置中.config与Kconfig的区别及Kconfig作用咨询

Understanding .config vs Kconfig in Linux Kernel Configuration

Hey there! Let’s break this down clearly since you’re just getting started with kernel configuration. First, let’s recap what you already know, then dive deep into the role of Kconfig.

What you already know: .config

  • .config is a generated, user-specific configuration file that lives at the root of your kernel source tree once you run tools like make menuconfig, make xconfig, or make oldconfig.
  • It’s the final set of choices the kernel build system uses when compiling—every CONFIG_* line directly tells the build system whether to include a feature, build it as a module, or exclude it entirely.
  • Think of it as your saved answer sheet after working through all the kernel configuration options.

The core role of Kconfig

Kconfig is the source of truth for all available kernel configuration options. It’s not a single file—you’ll find a Kconfig in almost every subdirectory of the kernel source tree, each defining options relevant to that subsystem (networking, storage, drivers, etc.). Here’s what it does:

  1. Defines all possible configuration options
    Every CONFIG_* entry in .config originates from a Kconfig file. For example, the option to enable USB support lives in a Kconfig under drivers/usb, which sets the option name, description, dependencies (like "requires PCI support"), and whether it can be built as a module.

  2. Manages option dependencies
    This is one of its most critical jobs. Kconfig ensures you can’t enable an option that relies on another feature being active first. For example, if you try to enable a Wi-Fi driver that needs PCI support, tools like menuconfig will either auto-enable PCI or gray out the Wi-Fi option until you turn PCI on.

  3. Powers interactive configuration tools
    When you run make menuconfig or make xconfig, these tools scan all Kconfig files across the source tree to build the interactive menu system you navigate. Menus, submenus, descriptions, and option states (enabled/disabled/module) are all pulled directly from Kconfig definitions.

  4. Serves as feature documentation
    Each Kconfig entry includes a description of what the option does, helping you understand exactly what you’re enabling or disabling. For example, the CONFIG_NET entry might explain it enables basic networking support and list subsystems that depend on it.

  5. Links config options to the build system
    Kconfig doesn’t just define options—it tells the kernel’s Makefiles how to handle each choice. If you set CONFIG_USB=y, the Makefile in drivers/usb will include those source files in the built kernel; set it to m, and it’ll build them as a loadable module.

Quick analogy to wrap up

  • Kconfig is like the questionnaire that lists all possible kernel features, their requirements, and explanations.
  • .config is like your filled-out questionnaire that the build system uses to know exactly what to compile.

Every time you run a config tool, it reads Kconfig files to present options, then writes your choices to .config for the build process.

内容的提问来源于stack exchange,提问作者Manoj

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 04:10:32