如何获得正确的 .config 文件以编译特定于我的硬件的 Linux 内核源代码?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11171903/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I get the correct .config file for compiling the Linux kernel source specific to my hardware?
提问by gjain
I tried using make defconfig
to compile the kernel, but as expected, it failed to boot. I was wondering what .config file do kernel vendors like Canonical for Ubuntu use, that the kernel is able to boot right out-of-the-box. Of course, I am still a beginner and configuring the various parameters, is a little out of my league currently.
我尝试使用make defconfig
编译内核,但正如预期的那样,它无法启动。我想知道像 Canonical for Ubuntu 这样的内核供应商使用什么 .config 文件,内核能够开箱即用。当然,我还是个初学者,各种参数的配置,目前有点超出我的能力范围。
Specifically,I am looking to load a basic "hello, world!" module to my running kernel 2.6.32.41. For that, I would need to compile kernels source against the same .config file that was used for the running kernel.
具体来说,我希望加载一个基本的“你好,世界!” 模块到我正在运行的内核 2.6.32.41。为此,我需要针对用于运行内核的相同 .config 文件编译内核源代码。
采纳答案by Jeff Welling
I don't know about getting the one that's "correct for your hardware", but you can use the config that Ubuntu gives you by looking in /boot/
for a file starting with the name config
. There may be more than one, in which case use the command uname -r
to tell which kernel you're currently running, and then you can use the appropriate config.
我不知道如何获得“适合您的硬件”的配置,但是您可以通过查找以/boot/
name 开头的文件来使用 Ubuntu 为您提供的配置config
。可能不止一个,在这种情况下,使用该命令uname -r
来告诉您当前正在运行哪个内核,然后您可以使用适当的配置。
回答by Peter Teoh
"defconfig" is usually pegged at the commonly used hardware - x86, or x86_64, and perhaps not so recent chipset or motherboard. Sometimes, like my Lenovo laptop, only the latest kernel source, and with enabling some config option, after googling through the bugzilla database, will it work.
“defconfig”通常与常用硬件相关联 - x86 或 x86_64,可能不是最近的芯片组或主板。有时,像我的联想笔记本电脑,只有最新的内核源代码,并启用一些配置选项,在谷歌搜索 bugzilla 数据库后,它会工作。
Like what Jeff Welling said, to get the config in use, u can look under /boot directory. Same for my Fedora Core too. But if u want to compile a basic program as a "kernel module", and by that it simply means "loadable kernel module", u don't need to compile the kernel source. U just need the kernel headers for that current version. For example, "apt-cache search" in Ubuntu 10.04 returns several possible option:
就像 Jeff Welling 所说的,要获取使用中的配置,您可以查看 /boot 目录下。我的 Fedora Core 也一样。但是,如果您想将基本程序编译为“内核模块”,并且仅表示“可加载内核模块”,则不需要编译内核源代码。你只需要当前版本的内核头文件。例如,Ubuntu 10.04 中的“apt-cache search”返回几个可能的选项:
linux-headers-2.6.38 - Header files related to Linux kernel, specifically,
linux-libc-dev - Linux Kernel Headers for development
Ubuntu normally patched the stock kernel (from kernel.org) to have their own kernel. If u have downloaded the stock kernel, and attempt to use the /boot's config file (or sometimes u can find the currently loaded config as /proc/config.gz, like the Backtrack's Ubuntu, which is based on 10.04 LTS), then u may need to do a "make oldconfig" with the current config file named as ".config". "make oldconfig" will then use the .config to generate a new .config that is compatible with the kernel source.
Ubuntu 通常会修补库存内核(来自 kernel.org)以拥有自己的内核。如果您下载了库存内核,并尝试使用 /boot 的配置文件(或者有时您可以找到当前加载的配置为 /proc/config.gz,例如 Backtrack 的 Ubuntu,它基于 10.04 LTS),那么您可能需要使用名为“.config”的当前配置文件执行“make oldconfig”。然后“make oldconfig”将使用 .config 生成与内核源代码兼容的新 .config。
回答by Gnurou
If your running kernel was compiled with the CONFIG_IKCONFIG_PROC
option, you can get the config in /proc/config.gz
:
如果您正在运行的内核是使用该CONFIG_IKCONFIG_PROC
选项编译的,您可以在/proc/config.gz
以下位置获取配置:
$ zcat /proc/config.gz >my_config
Copy my_config
into your kernel build directory as .config
and run make config
to be prompted for configuration options that are absent from your config file (this will only happen if you are using a kernel source that is newer than your running kernel). You should then be able to compile a new kernel with the same features as your current one.
复制my_config
到您的内核构建目录中.config
并运行make config
以提示您提供配置文件中不存在的配置选项(仅当您使用比正在运行的内核更新的内核源时才会出现这种情况)。然后,您应该能够编译具有与当前内核相同功能的新内核。
Distros typically use their own kernel configuration, where most of the drivers are compiled as modules to be dynamically loaded when the corresponding hardware is requested. Also the kernel needs to be booted with relevant boot options (like the one specifying the root filesystem). Your defconfig kernel probably failed to boot because of that.
发行版通常使用自己的内核配置,其中大多数驱动程序被编译为模块,以便在请求相应的硬件时动态加载。此外,内核需要使用相关的引导选项(例如指定根文件系统的选项)来引导。因此,您的 defconfig 内核可能无法启动。
回答by ashish
option1:
选项1:
source code of your booted system
启动系统的源代码
cd /usr/src/linux-headers-3.2.0-29;
this will generate .config
这将生成 .config
sudo make oldconfig;
vi .config
option2:
选项2:
zcat /proc/config.gz > my_config
option3:
选项3:
echo /boot/config* > my_config