内核配置中.config与Kconfig的区别及Kconfig作用咨询
.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
.configis a generated, user-specific configuration file that lives at the root of your kernel source tree once you run tools likemake menuconfig,make xconfig, ormake 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:
Defines all possible configuration options
EveryCONFIG_*entry in.configoriginates from aKconfigfile. For example, the option to enable USB support lives in aKconfigunderdrivers/usb, which sets the option name, description, dependencies (like "requires PCI support"), and whether it can be built as a module.Manages option dependencies
This is one of its most critical jobs.Kconfigensures 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 likemenuconfigwill either auto-enable PCI or gray out the Wi-Fi option until you turn PCI on.Powers interactive configuration tools
When you runmake menuconfigormake xconfig, these tools scan allKconfigfiles 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 fromKconfigdefinitions.Serves as feature documentation
EachKconfigentry includes a description of what the option does, helping you understand exactly what you’re enabling or disabling. For example, theCONFIG_NETentry might explain it enables basic networking support and list subsystems that depend on it.Links config options to the build system
Kconfigdoesn’t just define options—it tells the kernel’sMakefiles how to handle each choice. If you setCONFIG_USB=y, theMakefileindrivers/usbwill include those source files in the built kernel; set it tom, and it’ll build them as a loadable module.
Quick analogy to wrap up
Kconfigis like the questionnaire that lists all possible kernel features, their requirements, and explanations..configis 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

