Genkernel/zh-cn

是Article descriptionːː一个用来自动化构建[[kernel 和 initramfs的在gentoo平台上的运行的软件. ]] General的一些特征包括：


 * 配置内核源码
 * 构建压缩内核，并把他复制到.
 * 创建 initramfs 并将其复制到.
 * 创建 symlinks 到.
 * 添加自定义内容到initramfs中，如涉及加密的文件，引导启动图像，额外的模块等等.
 * 压缩 initramfs.
 * 配置 bootloader 来启动新创建的内核和initramfs.

Emerge
启动genkernel安装：

Usage
genkernel的调用的一般形式如下：

选项
Genkernel 的实际行为取决于繁多的选项，其中大部分可以在 文件中设置/取消设置或在每次调用时通过 命令. 通过在命令行的选项设置优先于在 中定义的选项. 配置文件被很好的记录，然而一些最常用的选项将在这篇文章中探讨. 我们的目的是让读者熟悉常见的 genkernel 调用. 如果你需要一套更完整的解释，请参阅 本身中的注释或  的输出.

用户交互选项
下面列出的配置选项可以帮助用户决定如何与配置流程进行交互. 用户甚至可以选择应保存在进程中创建的配置文件. 下面被视为主要的配置选项 ︰


 * 指定Genkernel使用哪一份配置文件 (默认为 ).
 * 指定Genkernel使用哪一份配置文件 (默认为 ).


 * Activates (or deactivates) the command (which invokes an interactive configuration menu) before building the kernel.
 * Activates (or deactivates) the command (which invokes an interactive configuration menu) before building the kernel.


 * Provides a kernel configuration utility which depends on the GTK+ libraries. The advantage of this option is that most users find it easier and clearer to configure the kernel using this tool, since it relies on the X-windowing system. The disadvantage of this option is that the X-windowing system is required to use it, so it will not work on the command line.
 * Provides a kernel configuration utility which depends on the GTK+ libraries. The advantage of this option is that most users find it easier and clearer to configure the kernel using this tool, since it relies on the X-windowing system. The disadvantage of this option is that the X-windowing system is required to use it, so it will not work on the command line.


 * Provides a kernel configuration utility which depends on the QT libraries. The advantage of this option is that most users find it easier and clearer to configure the kernel using this tool, since it relies on the X-windowing system. The disadvantage of this option is that the X-windowing system is needed to use it, so it will not work on the command line.
 * Provides a kernel configuration utility which depends on the QT libraries. The advantage of this option is that most users find it easier and clearer to configure the kernel using this tool, since it relies on the X-windowing system. The disadvantage of this option is that the X-windowing system is needed to use it, so it will not work on the command line.


 * Saves [or does not save] the kernel configuration to a file in the directory for later use.
 * Saves [or does not save] the kernel configuration to a file in the directory for later use.


 * Allows the modification of the name of the kernel and initrd images in the directory, so that the images produced are  and.
 * Allows the modification of the name of the kernel and initrd images in the directory, so that the images produced are  and.

根据所得到的系统的选项
此处列出的配置选项定义哪些功能会或不会在生成内核和 initrd 中启用.

=用于建造building 的工具选择的选项
以下选项支持 genkernel以及通过传递给相关的应用程序当内核正在构建组装. 这些选项会在内核编译过程中影响编译的工具，即使是在较低水平上.

作用于编译过程的选项
The following options usually take effect during the actual compilation:

调试选项
The use of debugging options during the kernel compilation process controls the amount of information reported, as well as the presentation of said data.

选项
The action passed on the command line with the tells genkernel what action to perform. The following actions are supported:

开始
Although there are several ways to run genkernel, the least-intrusive approach recommended for most users is provided by. Here, a generic configuration which works well for most systems is used. As was mentioned earlier, this approach is not without drawbacks; most of the modules created are useless to the average user and may increase compile time. Below is an illustration of a more efficient approach, achieved by passing certain options to genkernel as root:

The above operation causes genkernel to create a framebuffer splash-enabled kernel that will have to be manually installed. While preparing the kernel source tree, genkernel will refrain from cleaning out any preexisting object files present in the source tree. A menu-driven kernel configuration utility will be displayed that allows the user to select which modules will be built for the system.

Replacing  with the   option allows genkernel to automatically install the new kernel in the  directory, and will create symlinks if   is specified. Using the  option allows genkernel to mount the  partition automatically, if necessary.

改变内核
做的第一件事应该是允许在 文件中触发 ：

文件管理
While using genkernel, the user has to be aware of some aspects relating to kernel configuration and kernel image files management and the way the kernel sources are handled by the system.

源文件
After an, whenever new sources are available, a new kernel source directory is created under to host them. Normally, the active kernel sources directory is pointed to by the symlink.

目录可能看起来像这样：

符号链接可以通过不同方式更改.


 * If the  USE is set the  symlink is automatically updated to point to the newly emerged sources.


 * If the  USE is not set, the user can change the destination of the symlink using the  followed by the  command.

genkernel will always (exclusively) use the sources pointed by the symlink.

内核配置文件
If a kernel compilation has already been run with the active kernel sources, there might be a file inside the directory that contains the kernel configuration that has been applied while creating the last bzimage of the kernel. This file is named, for example where   might be substituted with the system's architecture,   might be substituted with the version of the sources used, and   with the release of the sources.

It is this file that is used as a starting configuration when running .

If it is the first time that genkernel is run with the new kernel sources, or if the previous result has not been saved, this file is substituted with a default configuration file that resides at where x86_64 is substituted with the actual architecture.

保存编译的配置
If the  genkernel option is activated, either from the command line or inside, the compiled kernel configuration is saved (with the name given above) into the  directory. At the same time, the configuration is saved in the file in  directory but this file is not reused on the next  run.

安装内核和 initramfs 到 目录
Specifying the  option when invoking genkernel, will ask genkernel to install the kernel image and the initramfs into the  directory. In order to run  a convenient manner, set the following in the  file:


 * 第一个参数不言自明.


 * 第二个参数告诉 genkernel 将编译好的内核配置保存到


 * The last two options tell genkernel to automatically update the grub configuration. In practice, the following happens:
 * If a previous kernel image with the same name already exist, it is renamed by appending to its name. A symlink  is automatically created that points to it.
 * The new kernel takes the place of any kernel with the same name into . If it is the first time a kernel is compiled, a symlink kernel is automatically created that points to the new kernel.

运行 后， 目录可能如下所示：

配置 bootloader
The symlinks presented above in the bootloader's configuration can be used so that, even if the new kernel is not bootable, the user can always boot on the old one.

To allow the kernel and intird provided by genkernel to run correctly, provide a minimum information in bootloader's configuration file:


 * Add  to the kernel parameters passed to the kernel image, where  points to the root partition (  is the number of the partition if a partition exists).
 * If splash is used, add a suitable mode line such as  to the parameters passed to the kernel and also add   or   depending on the verboseness required through the boot process.
 * Add the initrd information as required by the bootloader. Consult the Bootloader Configuration Chapter of the Gentoo Handbook for details on how to make the bootloader initrd-aware.

以下是 文件可能的样式.

保存工作文件
The genkernel application automatically saves new changes to the files. If previous changes are to be preserved, then the following actions need to be taken.


 * The first file to preserve is the kernel configuration file in If the source has not changed prior to the recompilation of the kernel, the previously used name for this file will be used. So copying the previous configuration file under a different name helps in preserving the information while keeping the file available as a starting point for a new configuration.


 * The second important thing is to preserve the already bootable kernel and initramfs images. The way to accomplish this depends on the context:
 * If the last kernel compiled is bootable, running will rename this kernel (and similarly initramfs) image to  and create a new . This mean that even if the new kernel is not bootable, users will always be able to boot the old one.
 * If the last kernel compiled is not bootable and sources haven't changed since the user compiled a bootable one, prior to running, first delete the new kernel image and remove the suffix from the last bootable one. Without this, if the newly compiled kernel is not bootable for the second time, the bootable  will be kicked out by the renaming of the non bootable , giving the user an unbootable system. Use the same reasoning for initramfs.

在更改源时使用以前的内核配置
The previous configuration can be used through the MENUCONFIG variable in as follows:

在启动前检查 initramfs 是否包含必要的实用程序
Before booting the system, it might be wise checking that initramfs includes necessary utilities. For example, a missing cryptsetup will produce a kernel panic when booting with LUKS. This post uses the following procedure to check that initramfs includes cryptsetup:

从一个安装 CD
The utility can build kernel and initrd images that provide support for network booting, or netbooting. With any luck, users should be able to netboot any recent computer into the environment provided by the Installation CD.

The magic lies in genkernel's linuxrc script: it will try to netmount the Installation CD using NFS. From there, the init scripts of the Installation CD can take over, as if the CD was present locally.

Building the kernel and initramfs with netboot support
要启用对网络引导的支持，请在配置内核时包括以下选项：

First, the kernel image must include the drivers for the system's Network Interface Cards (NIC). Normally, drivers for such devices will be compiled as modules. However, it is essential (for netbooting) that such drivers are compiled directly into the kernel image and not as modules.

Secondly, it is suggested that IP: kernel level autoconfiguration is enabled as well as IP: DHCP support options. This avoids an unnecessary layer of complexity since the IP address and the NFS path to the Installation CD can be configured on a DHCP server. Of course, this means the kernel command line will remain constant for any machine — which is very important for etherbooting.

These options tell the kernel to send a DHCP request at bootup.

Additionally, enable SquashFS because most modern Gentoo Installation CDs require it. Support for SquashFS is not included with the generic kernel source tree. To enable SquashFS, apply the necessary patches to the generic kernel source or install gentoo-sources.

Once the compilation process is completed, create a compressed tarball (tar.gz) that contains the kernel's modules. This step is only necessary if the kernel version does not match the kernel image version on the Installation CD.

要创建包含所有模块的存档：

根据网络引导机制，需要遵循以下步骤之一：

要创建以太网引导映像：

要创建 OpenBoot/SPARC64 TFTP 映像：

文件是启动映像.

Finally, copy this kernel to the TFTP server. The details are architecture-dependent and are beyond the scope of this guide. Please refer to the documentation for the specific platform of interest.

NFS 设置
To setup a NFS share that contains the Installation CD, use the loop device to mount the ISO image and then copy the contents of the CD into the NFS share. As a nice extra, genkernel's initrd scripts will extract all tar.gz files located in the directory. All that needs to be done here is copy the archive to the  directory.

The following assumes that is an exported NFS share:

现在将 文件复制到  中：

DHCP 设置
The netboot images will ask the DHCP server on the network for an IP as well as a  option. Both can be specified per host using a MAC address to identify machines:

网络引导说明
Netbooting itself is again very platform-specific. The important part is to specify the  and   parameters on the kernel command line, as this will bring up the network interface and tell the initrd scripts to mount the Installation CD via NFS. Here are some platform-specific tips.

For etherboot, insert the etherboot disk into the drive and reboot. The kernel command line was specified when the image was constructed. With Sparc64, press + at the boot prompt and then enter:

For PXE, setup pxelinux (part of syslinux), then create a along the lines of:

介绍
If an initramfs is installed with genkernel, then take a look at the various boot options that can (or should) be defined in the bootloader configuration. The most common ones are added to this guide.

加载 LVM 或软件型 RAID
If the system uses LVM or software-RAID, the initramfs has to be built using the  and   options. Do not forget to enable support during boot as well. This can be done using the dolvm and domdadm options.

在单用户模式下启动
If for some reason boot-up fails, rescuing the system by booting in the single-user mode is still possible. This will only load the really necessary services and then drop the user to a rescue (root) shell.

编译失败：未找到内核
This failure can be experienced when attempting to compile a kernel for one architecture with a kernel file that has a target of a different architecture than the target. This could be as simple as a machine running an kernel attempting to compile for a  target.

This can be experienced when booting from a x86_64 LiveCD on a system that is capable of operating in 64-bits, however the target to be installed or repaired is 32-bits. After the compilation process begins, will attempt to automatically detect the architecture for the target based on the currently running kernel. If the currently running kernel is 64-bit, then, unless it is told otherwise, will presume it should be looking for a 64-bit kernel.

Suppose then that the kernel's file has x64 disabled. The command will execute and the resulting kernel binary will be placed in the associated  directory. When goes to install (move and rename) the kernel it cannot find the kernel because it expected a 64-bit kernel.

The solution to this failure is to set 's  option to, in this case, the  architecture. The final command could look like this:

To override the architecture choice permanently, modify the ARCH_OVERRIDE variable in the file.

必须使用新内核手动重建外部模块（例如 xtables_addons）
Genkernel can rebuild external modules after the kernel is built; edit to include this line:

另请参阅

 * Manual kernel configuration - For the times it is necessary to to do things manually.
 * Dracut - Another initramfs builder available in Gentoo.