内核/配置

From Gentoo Wiki
< Kernel
Jump to:navigation Jump to:search
This page is a translated version of the page Kernel/Configuration and the translation is 62% complete.
Other languages:

这篇文章描述了 Linux 内核的手动配置和设置。 有关设置 'safe defaults' 的方法,请参阅 genkernel 文章。

设置符号链接

/usr/src/linux 符号链接应始终指向当前正在使用的内核源代码。这可以通过以下三种方式之一完成:

1. 在 USE flag symlink 激活的情况下安装内核源代码。这将使 /usr/src/linux 指向新安装的内核源代码。如有需要,后期仍可通过以下两种方式进行修改:

2. 使用 eselect 工具设置符号链接:

root #eselect kernel list
Available kernel symlink targets:
[1] linux-3.3.8-gentoo
[2] linux-3.4.9-gentoo

这将输出可用的内核资源。星号表示选择的来源。要更改内核源,例如到第二个条目,执行:

root #eselect kernel set 2

3. 手动设置符号链接:

root #ln -sf /usr/src/linux-3.4.9-gentoo /usr/src/linux
root #ls -l /usr/src/linux
lrwxrwxrwx 1 root root 11 Aug 29 22:10 /usr/src/linux -> /usr/src/linux-3.4.9-gentoo

配置

配置工具

内核提供了几个面向用户的工具,可以用来自行配置。

命令 描述
make config 基于文本的配置。按照选项依次提示。所有的选项都必须回答,并且不能随意访问之前的选项。
make menuconfig 基于 ncurses 的伪图形化菜单(只能文本化输入)。浏览菜单修改所需的选项。
make defconfig 生成一个来自 ARCH 提供的 defconfig 文件的默认配置。使用这个选项,使用这个选项可以回到源代码中的默认配置文件。
make nconfig 基于 ncurses 的伪图形化菜单。需要安装 sys-libs/ncurses
make xconfig 使用 QT5 的图形化菜单。需要安装 dev-qt/qtwidgets
make gconfig 使用 GTK 的图形化菜单。需要安装 x11-libs/gtk+dev-libs/glibgnome-base/libglade
make oldconfig 查看内核版本之间的更改,并且为内核更新创建新的 .config
make olddefconfig 生成一个来自 ARCH 提供的 defconfig 文件的新配置。同时,维持所有之前在 /usr/src/linux/.config.config 文件的选项。这是一种快速安全的升级配置文件方法,它具有硬件支持的所有配置选项,同时获得错误修复和安全补丁。
make allyesconfig 在内核启用所有的配置选项。它将为 * 设置为 all 内核选项。在使用此选项之前,确保备份了最近的内核配置!
make allmodconfig 在内核中启用所有的模块

There are also several scripts to create miscellaneous default configurations. These can make deeper configuration more time efficient. Run the following command for a full list of make targets:

root #make help

The remainder of this article will describe configuration using the make menuconfig tool, but the procedure is similar for the other kernel build tools.

root #cd /usr/src/linux
root #make menuconfig

用法

In the shown menu the blue bar indicates the position of the cursor. With the and arrow keys change the position of the cursor. The and arrow keys traverse the menu bar in the bottom and define what happens when the Enter key is pressed. For the menu bar below, Select switches to a sub menu for the menu entries ending with ---> while Exit exits a sub menu. As an alternative the Esc key can be pressed twice to exit the application.

Pressing an associated letter key A-Z will move the position of the cursor lines that have characters in bold. The Y, M, N keys are excluded from navigation in this way; they are sanctified for other purposes. If a line begins with a Y, M, or N, the next character will be bold and capable of being jumped to. For example, relative to the cursor's current position, if the next line reads "Network Device Support --->" pressing the E key will move the cursor to that line.

The following symbols can appear in front of the lines in the menus:

Symbol(s) Description
[ ], [*] Options in square brackets can be activated or deactivated. The asterisk marks the menu entry as activated. The value can be changed with the space key. It is also possible to press Y key (Yes) to activate or N key (No) to deactivate the selected entry.


If the option is activated, the selected feature/driver will be built into the kernel and will always be available at boot time.

< >, <M>, <*> Options in angle brackets can be activated or deactivated, but also activated as module (indicated by a M). The values can be modified by pressing Y/N keys as before or by pressing the M key to activate the feature/driver as a module.


See the Kernel Modules article for differentiation.

{M}, {*} Options in curly brackets can be activated or activated as module but not be deactivated. This happens because another feature/driver is dependent on this feature.
-M-, -*- Options between hyphens are activated in the shown way by another feature/driver. There is no choice.

Furthermore some menu entries have a tag at the end:

Tag Description
(NEW) This driver is new in the kernel and is maybe not stable enough.
(EXPERIMENTAL) This driver is experimental and most likely not stable enough.
(DEPRECATED) This driver is deprecated and not needed for most systems.
(OBSOLETE) This driver is obsolete and should not be activated.

大多数选项都有描述,可以通过按 H 键或在菜单栏中选择 Help 来查看。

驱动选择

See the hardware detection article and the articles in the Hardware category.

搜索模块

Within menuconfig, use the / key to search modules by name.

As shown below, the search result will show numbers in front of the matches. Pressing 1 in the example below would make menuconfig jump straight to the option Bluetooth device drivers in the menu structure.

内核 搜索 HCIBTUSB 后的示例输出
Symbol: BT_HCIBTUSB [=m]                       
Type  : tristate                               
Prompt: HCI USB driver                         
  Location:                                    
    -> Networking support (NET [=y])           
      -> Bluetooth subsystem support (BT [=y]) 
(1)     -> Bluetooth device drivers            
  Defined at drivers/bluetooth/Kconfig:5       
  Depends on: NET [=y] && BT [=y] && USB [=m]

启用 Gentoo Linux 通用设置

There is a kernel configuration option called CONFIG_GENTOO_LINUX only present in sys-kernel/gentoo-sources and other Kernel Project maintained kernels. It does nothing on its own, but sets various required configuration options for typical installations.

This setting automatically selects tmpfs and devtmpfs support, which are needed for handling /dev on Gentoo Linux, but might be expanded in the future to enable other mandatory settings for a Gentoo Linux system. For more information, read the help information available through the kernel configuration system as described earlier in this guide.

编译

After configuration has been accomplished successfully, compile the kernel:

root #make
附注
Depending on the speed and core count available to the system, building the kernel could take quite some time. If the number of CPU cores in the system are known, the -jN (where N is the number of available cores plus 1) option can be used to speed up the complication process. For example, a dual core processor contains two logical cores plus one (2 + 1). An easy way to determine the number of available cores is to run the nproc command:

user $nproc
3
root #make -j3

A quad core system contains four logical cores plus one (4 + 1):

root #make -j5

安装

If drivers are activated as modules, they must be installed:

root #make modules_install

The modules will be copied to a sub directory of /lib/modules.

安装实际的内核:

root #make install

This command executes /sbin/installkernel, which is part of the sys-apps/debianutils package. The new kernel is installed into /boot/vmlinuz-{version}. If a symbolic link /boot/vmlinuz already exists, it is refreshed by making a link from /boot/vmlinuz to the new kernel, and the previously installed kernel is available as /boot/vmlinuz.old. (installkernel man page). The same for config and System.map files. These symlinks are handy, because they always point to the newest kernel without changing the file path (e.g. they can be used in the bootloader configuration).

Bootloader

Change the system's bootloader configuration to load the kernel at system boot.

When the bootloader step has been finished, restart the system with the new kernel.

使用默认的配置编译最近的内核

Use the following procedure to get an overview of the kernel configuration settings that deviate from the default. Keep in mind that the modification of one configuration setting may alter additional configuration settings.

root #cd /usr/src/linux
root #cp -p .config ../.config.working
root #make defconfig
root #mv .config ../.config.default
root #cp -p ../.config.working .config
root #cd ..
root #/usr/src/linux/scripts/diffconfig .config.working .config.default > .config.diff

The search function in make menuconfig can be used to look up the symbols and their interpretations. When you're done, clean up:

root #cd /usr/src/
root #rm .config.working .config.default .config.diff

另请参阅

外部资源