Handbook:Parts/Installation/Kernel/zh-cn

安装源码
Linux内核是所有发行版的核心. 它位于用户程序和系统硬件之间. Gentoo提供给用户一些可选的内核源码. 完整的带描述的列表在内核概述页面.

针对基于系统的Gentoo，建议使用包.

选择一个合适的内核并使用来安装它.

这将在中安装Linux内核源码，并有一个符号连接叫作将指向安装的内核源码：

现在是时候来配置和编译内核源代码了. 有两种方法:


 * 1) The kernel is manually configured and built.
 * 2) A tool called  is used to automatically build and install the Linux kernel.

We explain the manual configuration as the default choice here as it is the best way to optimize an environment.

介绍
Manually configuring a kernel is often seen as the most difficult procedure a Linux user ever has to perform. Nothing is less true - after configuring a couple of kernels no-one even remembers that it was difficult ;)

However, one thing is true: it is vital to know the system when a kernel is configured manually. Most information can be gathered by emerging which contains the  command:

Another source of system information is to run to see what kernel modules the installation CD uses as it might provide a nice hint on what to enable.

Now go to the kernel source directory and execute. This will fire up menu-driven configuration screen.

The Linux kernel configuration has many, many sections. Let's first list some options that must be activated (otherwise Gentoo will not function, or not function properly without additional tweaks). We also have a Gentoo kernel configuration guide on the Gentoo wiki that might help out further.

Activating required options
Make sure that every driver that is vital to the booting of the system (such as SCSI controller, ...) is compiled in the kernel and not as a module, otherwise the system will not be able to boot completely.

Next select the exact processor type. It is also recommended to enable MCE features (if available) so that users are able to be notified of any hardware problems. On some architectures (such as x86_64), these errors are not printed to dmesg, but to. This requires the package.

Also select Maintain a devtmpfs file system to mount at /dev so that critical device files are already available early in the boot process.

Now go to File Systems and select support for the filesystems you use. Don't compile the file system that is used for the root filesystem as module, otherwise the Gentoo system will not be able to mount the partition. Also select Virtual memory and /proc file system.

If PPPoE is used to connect to the Internet, or a dial-up modem is used, then enable the following options:

The two compression options won't harm but are not definitely needed, neither does the PPP over Ethernet option, that might only be used by ppp when configured to do kernel mode PPPoE.

Don't forget to include support in the kernel for the network (Ethernet or wireless) cards.

Most systems also have multiple cores at their disposal, so it is important to activate Symmetric multi-processing support:

If USB input devices (like keyboard or mouse) are used don't forget to enable those as well:

可选:建造initramfs
In certain cases it is necessary to build an initramfs - an initial ram-based file system. The most common reason is when important file system locations (like or ) are on separate partitions. With an initramfs, these partitions can be mounted using the tools available inside the initramfs.

如果没有initramfs的，存在着巨大的风险，系统将无法正常开机，因为这是负责安装的文件系统工具需要驻留在这些文件系统的信息. initramfs中的一个将在必要的文件拉进它的内核启动之后使用的档案，但控制被移交前转移到初始化工具. 在initramfs的脚本，然后将确保分区正确地安装在系统继续启动之前.

To install an initramfs, install first, then have it generate an initramfs:

In order to enable specific support in the initramfs, such as lvm or raid, add in the appropriate options to. See for more information. In the next example we enables support for LVM and software raid (mdadm):

The initramfs will be stored in. The resulting file can be found by simply listing the files starting with initramfs:

Now continue with Kernel modules.

备选：使用genkernel
If a manual configuration looks too daunting, then using is recommended. It will configure and build the kernel automatically.

works by configuring a kernel nearly identically to the way the installation CD kernel is configured. This means that when is used to build the kernel, the system will generally detect all  hardware at boot-time, just like the installation CD does. Because doesn't require any manual kernel configuration, it is an ideal solution for those users who may not be comfortable compiling their own kernels.

Now, let's see how to use genkernel. First, emerge the ebuild:

Next, edit the file so that the line containing  as second field has the first field pointing to the right device. If the partitioning example from the handbook is followed, then this device is most likely with the ext2 file system. This would make the entry in the file look like so:

Now, compile the kernel sources by running. Be aware though, as compiles a kernel that supports almost all hardware, this compilation will take quite a while to finish!

Once genkernel completes, a kernel, full set of modules and initial ram disk (initramfs) will be created. We will use the kernel and initrd when configuring a boot loader later in this document. Write down the names of the kernel and initrd as this information is used when the boot loader configuration file is edited. The initrd will be started immediately after booting to perform hardware autodetection (just like on the installation CD) before the "real" system starts up.

配置模块
List the modules that need to be loaded automatically in. Extra options can be added to the modules too if necessary.

To view all available modules, run the following command. Don't forget to substitute " " with the version of the kernel just compiled:

For instance, to automatically load the module (which is the driver for a specific 3Com network card family), edit the  file and enter the module name in it.

Continue the installation with Configuring the system.

可选：安装固件
Some drivers require additional firmware to be installed on the system before they work. This is often the case for network interfaces, especially wireless network interfaces. Most of the firmware is packaged in :