genkernel/zh-cn

From Gentoo Wiki
Jump to:navigation Jump to:search
This page is a translated version of the page Genkernel and the translation is 55% complete.
Outdated translations are marked like this.
Other languages:
Deutsch • ‎English • ‎español • ‎français • ‎italiano • ‎português do Brasil • ‎русский • ‎中文(中国大陆)‎ • ‎日本語 • ‎한국어

Warning: Display title "genkernel/zh-cn" overrides earlier display title "Genkernel".

genkernel 是[[Article descriptionːː一个用来自动化构建kernelinitramfs的在gentoo平台上的运行的软件。]] General的一些特征包括:

  • 配置内核源码
  • 构建压缩内核bzImage,并把他复制到/boot
  • 创建 initramfs 并将其复制到 /boot
  • 创建 symlinks 到 /boot
  • 添加自定义内容到initramfs中,如涉及加密的文件,引导启动图像,额外的模块等等。
  • 压缩 initramfs.
  • 配置 bootloader 来启动新创建的内核和initramfs。
附注
一个常见误解是 genkernel 会“自动”生成自定义内核配置。 genkernel 自动化内核构建过程并组装 initramfs,但“不”生成自定义内核配置文件。它使用通用内核配置文件,该文件在特定于体系结构的基础上为常用子系统提供支持。有关架构默认值的详细信息,请参见 上游存储库。选择架构,然后选择内核配置文件。

安装

USE 标记

USE flags for sys-kernel/genkernel Gentoo automatic kernel building scripts

firmware Prefer system firmware sys-kernel/linux-firmware over local copy.
ibm Add support for IBM ppc64 specific systems

Emerge

启动genkernel安装:

root #emerge --ask sys-kernel/genkernel

Usage

genkernel的调用的一般形式如下:

root #genkernel [选项 ...] action

选项

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

Note
Some of the options have a variant that triggers a converse behavior. They are figured as --[no-]option_name, and the converse effect is shown in square brackets as in the following example:
CODE Enable or disable a certain option
--[no-]menuconfig : Activates [deactivates] ...

Where options have only a negative effect, the no-, and its effect, which are not optional in this case, are figured without square brackets.

用户交互选项

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

Option Description
--config=/path/to/genkernel.conf Points to the Genkernel configuration file to use (defaults to /etc/genkernel.conf).
--[no-]menuconfig Activates (or deactivates) the make menuconfig command (which invokes an interactive configuration menu) before building the kernel.
--gconfig 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.
--xconfig 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.
--[no-]save-config Saves [or does not save] the kernel configuration to a file in the /etc/kernels directory for later use.
--kernname=NickName Allows the modification of the name of the kernel and initrd images in the /boot directory, so that the images produced are kernel-NickName-version and initramfs-NickName-version.

根据所得到的系统的选项

此处列出的配置选项定义哪些功能会或不会在生成内核和 initrd 中启用。

Option Description
--[no-]splash Activates (or deactivates) support for Fbsplash framebuffer splash in the genkernel-built initrd image. To override the default theme used by fbsplash, use --splash=PreferredTheme (where PreferredTheme is the title of one of the directories inside the /etc/splash directory).
--splash-res=PreferredResolution This option allows to select which splash screen resolutions will be supported in the initrd during the start-up of the system. This is useful for two reasons. First, to be able to select only the splash screen resolution(s) relevant to the system. Second, to avoid the unnecessary increase in the disk space required by initrd (since the initrd does not have to support resolutions that are irrelevant for the system's configuration.) However, the option is best omitted if the kernel is being compiled for an Installation CD; this allows splash support for all possible resolutions.
--do-keymap-auto Force keymap selection during the boot sequence.
--lvm Includes support for storage using via Logical Volume Management (LVM2) from static binaries, if available to the system. Relevant (static) LVM2 binaries are compiled if they are unavailable. Be sure to install the sys-fs/lvm2 package on the system (emerge sys-fs/lvm2) before enabling this option, then review the LVM article on the Gentoo wiki.
--dmraid Includes support for DMRAID; the utility which creates RAID mappings using the kernel device-mapper subsystem. DMRAID discovers, activates, deactivates and displays properties of software RAID sets (ATARAID, for example) and contained DOS partitions.
--luks Includes support for Linux Unified Key Setup or LUKS. This will allow to use a device encrypted by LUKS which contains the root filesystem. On the bootloader, set that encrypted device as the value of crypt_root (and root shall be the unencrypted device LUKS creates).
--disklabel Adds support for disk label and UUID support to the initrd.
--iscsi Adds support for iSCSI to the initrd.
--multipath Adds support for Multipath to the initrd.
--linuxrc=/path/to/the/linuxrc_file Specifies a user-created linuxrc — a script that is initialized during the start-up stage of the kernel, prior to the actual boot process. A default linuxrc script can be found in the /usr/share/genkernel/ directory. This script allows booting into a small, modularized kernel; it tries to load the minimum amount of drivers that are needed (as modules) by the system.
--cachedir=/path/to/alt/dir Overrides the default cache location used while compiling the kernel.
--tempdir=/path/to/new/tempdir Specifies the location of the temporary directory used by genkernel while compiling the kernel.
--unionfs Includes support for the Unification File System in the initrd image.
--mountboot Detects whether or not the /boot directory needs to be mounted on a separate partition. It will check /etc/fstab script for instructions on how to mount the boot partition on a file system (if needed).

= =用于建造building 的工具选择的选项

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

Options Description
--kernel-cc=someCompiler Specifies the compiler employed during the kernel compilation process.
--kernel-ld=someLinker Specifies the linker employed during the kernel compilation process.
--kernel-as=someAssembler Specifies the assembler employed during the kernel compilation process.
--kernel-make=someMake Specifies an alternative to the GNU make utility employed during the kernel compilation process.
--utils-cc=someCompiler Specifies the compiler employed during the compilation of support utilities.
--utils-ld=someLinker Specifies the linker employed during the compilation of support utilities.
--utils-as=someAssembler Specifies the assembler employed during the compilation of support utilities.
--utils-make=someMake Specifies an alternative to the GNU make utility employed during the compilation of support utilities.
--makeopts=-jX Specifies the number of concurrent threads that the make utility can implement while the kernel (and utilities) are being compiled. The variable X is a number to be freely chosen, although the most common values are obtained by adding one (1) to the number of cores used by the system, or just use the number of cores on the system. So, for a system with one core, most common option values are -j2 or -j1; a system with two cores most likely uses the -j3 or -j2 options, and so on. (A system with one processor that supports Hyper-Threading™ (HT) Technology can be assumed to have 2 cores, provided Symmetric Multi-Processing (SMP) support is enabled in the kernel.)

作用于编译过程的选项

The following options usually take effect during the actual compilation:

Option Description
--kerneldir=/path/to/sources/ Specifies an alternative kernel source location, rather than the default /usr/src/linux/ location.
--kernel-config=/path/to/config-file Specifies what alternative kernel configuration will be used, rather than the default /path/to/sources/.config file.
--module-prefix=/path/to/prefix-directory/ Specifies a prefix to the directory where kernel modules will be installed (default path is the /lib/modules directory.)
--[no-]clean Activates (or deactivates) the make clean command before compiling the kernel. The make clean command removes all object files and dependencies from the kernel's source tree.
--[no-]mrproper Activates (or deactivates) the make mrproper command before kernel compilation. Like the make clean command listed above, make mrproper removes all object files and dependencies from the kernel's source tree. However, any previous configuration files (in /path/to/sources/.config or /path/to/sources/.config.old) will also be purged from the kernel's source tree. If it is undesirable that the kernel's .config file keeps disappearing, be sure to disable this option!
--oldconfig Issues the make oldconfig command, which attempts to collect configuration information for the system's architecture from a generic script in /usr/share/genkernel. This is a non-interactive process; no user input is entertained. Also, if --oldconfig is used in conjunction with --clean, the latter option is negated, resulting in the activation of the --no-clean option.
--callback="echo hello" Calls the specified arguments (echo hello, in this case) after the kernel and the relevant modules have been built, but before building the initrd image. This may be useful when installing external modules in the initrd image by emerging the relevant item(s) with the callback feature, and then redefining a genkernel module group.
--[no-]install Activates (or deactivates) the make install command, which installs the new kernel image, configuration file, initrd image and system map onto the boot partition. Any compiled modules will be installed as well. By default genkernel will attempt mount /boot if it is on a separate partition before running the install command.
--no-ramdisk-modules Refrains from copying any modules to the genkernel-created initrd image. This option is an exception to the rule about the no- prefix; omission of this prefix creates an invalid genkernel option.
--all-ramdisk-modules Copies all available modules to the genkernel-created initrd image.
--genzimage Creates the initrd image, prior to the kernel image (this hack currently applies only to PPC Pegasos systems).

调试选项

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

Option Description
--loglevel=<0|1|2|3|4|5> Controls the level of verbosity for information provided by genkernel. The variable <verblevel> is an integer between 0 and 5. The level '0' represents minimal output, while '5' provides as much information as possible about genkernel's activities during the kernel compilation process.
--logfile=/path/to/output_file Ignores the value set by the --loglevel option (above) and sends all debugging data produced by genkernel to the specified output file. Outputs to /var/log/genkernel.log by default.
--[no-]color Activates (or deactivates) colored output of debugging information (reported by genkernel) using escape sequences.
--[no-]debug-cleanup Activates (or deactivates) the full post-run cleanup for debug purposes.

选项

The action passed on the command line with the genkernel [options …] action tells genkernel what action to perform. The following actions are supported:

Action Description
all Builds all stages — the initrd, kernel image and modules.
bzImage Only builds the kernel image.
kernel Only builds the kernel image and modules.
initramfs Only builds the initramfs/ramdisk image.
ramdisk Only builds the initramfs/ramdisk image.

配置

开始

Although there are several ways to run genkernel, the least-intrusive approach recommended for most users is provided by genkernel all. 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:

root #genkernel --splash --no-install --no-clean --menuconfig all

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

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

Note
Don't forget that the /etc/genkernel.conf file is sourced by the genkernel command at startup, and that any option defined there will be applied, except where a command line option takes precedence over it.

改变内核

做的第一件事应该是允许在 /etc/genkernel.conf 文件中触发 make menuconfig

FILE /etc/genkernel.conf强制使用 /etc/genkernel.conf 中的配置菜单
# Run 'make menuconfig' before compiling this kernel?
MENUCONFIG="yes"

文件管理

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 emerge -u gentoo-sources, whenever new sources are available, a new kernel source directory is created under /usr/src/ to host them. Normally, the active kernel sources directory is pointed to by the /usr/src/linux symlink.

/usr/src 目录可能看起来像这样:

user $ls -l /usr/src
total 16
lrwxrwxrwx  1 root root   19 21 Mar   2013 linux -> linux-3.7.10-gentoo
drwxr-xr-x 24 root root 4096 25 Aug  10:39 linux-3.10.7-gentoo
drwxr-xr-x 20 root root 4096 21 Apr  19:42 linux-3.7.10-gentoo
drwxr-xr-x 21 root root 4096 14 Mar   2013 linux-3.7.9-gentoo

/usr/src/linux 符号链接可以通过不同方式更改。

  • If the symlink USE is set the /usr/src/linux symlink is automatically updated to point to the newly emerged sources.
  • If the symlink USE is not set, the user can change the destination of the symlink using the eselect kernel list followed by the eselect kernel set command.

genkernel will always (exclusively) use the sources pointed by the /usr/src/linux symlink.

内核配置文件

If a kernel compilation has already been run with the active kernel sources, there might be a file inside the /etc/kernels directory that contains the kernel configuration that has been applied while creating the last bzimage of the kernel. This file is named, for example kernel-config-x86_64-3.7.9-gentoo-r1 where x86_64 might be substituted with the system's architecture, 3.7.9 might be substituted with the version of the sources used, and r1 with the release of the sources.

It is this kernel-config-x86_64-3.7.9-gentoo-r1 file that is used as a starting configuration when running  genkernel --menuconfig all.

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 usr/share/genkernel/arch/x86_64/kernel-config where x86_64 is substituted with the actual architecture.

Note
The path to this default configuration file, may be altered by setting the DEFAULT_KERNEL_CONFIG variable in /etc/genkernel.conf file.
保存编译的配置

If the --save-config genkernel option is activated, either from the command line or inside /etc/genkernel.conf, the compiled kernel configuration is saved (with the name given above) into the /etc/kernels directory. At the same time, the configuration is saved in the .config file in /usr/src/linux directory but this file is not reused on the next genkernel all run.

Warning
One has to be aware, that each time genkernel is run, with the --save-config genkernel option set, the configuration file in /etc/kernels is overridden. Thus, it is highly recommended to copy this file under a new name before running genkernel in order to preserve it.
= 安装内核和 initramfs 到 /boot 目录

Specifying the --install option when invoking genkernel, will ask genkernel to install the kernel image and the initramfs into the /boot directory. In order to run --install a convenient manner, set the following in the /etc/genkernel.conf file:

FILE /etc/genkernel.conf设置内核和 initramfs 自动保存
# Mount BOOTDIR automatically if it is not mounted?
MOUNTBOOT="yes"
  
# Save the new configuration in /etc/kernels upon
# successful compilation
SAVE_CONFIG="yes"
  
# Make symlinks in BOOTDIR automatically?
SYMLINK="yes"
  
# Add new kernel to grub2?
BOOTLOADER="grub2"
  • 第一个参数不言自明。
  • 第二个参数告诉 genkernel 将编译好的内核配置保存到 /etc/kernels
  • 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 .old to its name. A symlink kernel.old is automatically created that points to it.
    • The new kernel takes the place of any kernel with the same name into /boot. If it is the first time a kernel is compiled, a symlink kernel is automatically created that points to the new kernel.

运行 genkernel --menuconfig all 后,/boot 目录可能如下所示:

user $ls -al /boot
total 41336
drwxr-xr-x  3 root root    4096 20 avril 17:23 .
drwxr-xr-x 24 root root    4096 15 sept. 12:31 ..
lrwxrwxrwx  1 root root       1 24 févr.  2013 boot -> .
drwxr-xr-x  2 root root    4096 24 févr.  2013 grub
lrwxrwxrwx  1 root root      40 20 avril 17:23 initramfs -> initramfs-genkernel-x86_64-3.7.10-gentoo
-rw-r--r--  1 root root 1314412 20 avril 17:23 initramfs-genkernel-x86_64-3.7.10-gentoo
-rw-r--r--  1 root root 1313548 21 mars   2013 initramfs-genkernel-x86_64-3.7.10-gentoo.old
-rw-r--r--  1 root root 1295344 25 févr.  2013 initramfs-genkernel-x86_64-3.7.9-gentoo
-rw-r--r--  1 root root 3310324 25 févr.  2013 initramfs-genkernel-x86_64-3.7.9-gentoo.old
lrwxrwxrwx  1 root root      44 20 avril 17:23 initramfs.old -> initramfs-genkernel-x86_64-3.7.10-gentoo.old
lrwxrwxrwx  1 root root      37 20 avril 17:23 kernel -> kernel-genkernel-x86_64-3.7.10-gentoo
-rw-r--r--  1 root root 4866656 20 avril 17:23 kernel-genkernel-x86_64-3.7.10-gentoo
-rw-r--r--  1 root root 4866560 21 mars   2013 kernel-genkernel-x86_64-3.7.10-gentoo.old
-rw-r--r--  1 root root 4552288 25 févr.  2013 kernel-genkernel-x86_64-3.7.9-gentoo
-rw-r--r--  1 root root 3400736 25 févr.  2013 kernel-genkernel-x86_64-3.7.9-gentoo.old
lrwxrwxrwx  1 root root      41 20 avril 17:23 kernel.old -> kernel-genkernel-x86_64-3.7.10-gentoo.old

配置 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 root=/dev/sdaN to the kernel parameters passed to the kernel image, where /dev/sdaN points to the root partition (N is the number of the partition if a partition exists).
  • If splash is used, add a suitable mode line such as vga=0x317 to the parameters passed to the kernel and also add splash=verbose or splash=silent 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.

以下是 grub.conf 文件可能的样式。

FILE /boot/grub/grub.confAn example of grub.conf file
# This is a sample grub.conf for use with Genkernel, per the Gentoo handbook 
# http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=1&chap=10#doc_chap2 
# If you are not using Genkernel and you need help creating this file, you 
# should consult the handbook. Alternatively, consult the grub.conf.sample that 
# is included with the Grub documentation. 
  
default 0 
timeout 5
splashimage=(hd1,0)/boot/grub/splash.xpm.gz 
   
title Gentoo Linux 
root (hd0,6) 
kernel /boot/kernel initrd=/dev/ram0 root=/dev/sda7 rootfstype=ext4  
initrd /boot/initramfs
  
title Gentoo Linux old kernel 
root (hd0,6) 
kernel /boot/kernel.old initrd=/dev/ram0 root=/dev/sda7 rootfstype=ext4 
initrd /boot/initramfs.old

保存工作文件

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 /etc/kernels/ 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:
  1. If the last kernel compiled is bootable, running genkernel will rename this kernel (and similarly initramfs) image to kernel-genkernel-ARCH-X.Y.Z-gentoo-rx.old and create a new kernel-genkernel-ARCH-X.Y.Z-gentoo-rx. This mean that even if the new kernel is not bootable, users will always be able to boot the old one.
  2. If the last kernel compiled is not bootable and sources haven't changed since the user compiled a bootable one, prior to running genkernel, first delete the new kernel image and remove the .old suffix from the last bootable one. Without this, if the newly compiled kernel is not bootable for the second time, the bootable kernel-genkernel-ARCH-X.Y.Z-gentoo-rx.old will be kicked out by the renaming of the non bootable kernel-genkernel-ARCH-X.Y.Z-gentoo-rx, giving the user an unbootable system. Use the same reasoning for initramfs.

在更改源时使用以前的内核配置

The previous configuration can be used through the MENUCONFIG variable in /etc/genkernel.conf as follows:

FILE /etc/genkernel.conf设置 make menuconfig
# Run 'make menuconfig' before compiling this kernel?
MENUCONFIG="yes"
Note
There is no need to run make oldconfig when using genkernel, even if the sources are changed from kernel-genkernel-ARCH-version-gentoo-rx to kernel-genkernel-ARCH-version-gentoo-r(x+1) or from kernel-genkernel-ARCH-version-gentoo to kernel-genkernel-ARCH-(version+1)-gentoo. This is because make menuconfig will try to load the previous configuration into the menu as much as possible. Nevertheless, reviewing each option and new sections carefully is recommended.

在启动前检查 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:

root # mkdir /tmp/initramfs
root # cd /tmp/initramfs
root # xzcat kernel-genkernel-x86_64-4.14.65-gentoo | cpio -idmv
root # ls -l sbin/cryptsetup
-rwxr-xr-x 1 root root 67568 28 d’oct 18:55 sbin/cryptsetup

网络启动

从一个安装 CD

The genkernel 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

要启用对网络引导的支持,请在配置内核时包括以下选项:

警告
对 genkernel 网络引导的支持是实验性的,可能包含漏洞。

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.

KERNEL Configuring a 3.x.x series kernel to support various NIC drivers
Device Drivers --->
   Networking Support --->
      Ethernet (10 or 100Mbit)  --->
         [*] Ethernet (10 or 100Mbit)
         <*>   The driver(s) for each network card
附注
一定要选择 <*> 而不是 <M>

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.

KERNEL Configuring a 3.x.x series kernel to support DHCP
Device Drivers --->
   Networking Support --->
      Networking options
         [*] TCP/IP networking--->
         [*]   IP: kernel level autoconfiguration
         [*]     IP: DHCP support

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.

KERNEL 配置内核以支持 SquashFS
File systems--->
   Miscellaneous filesystems --->
      [*] SquashFS 2.X - Squashed file system support

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.

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

root #cd /
root #tar -cf /tmp/modules-X.Y.Z.tar.gz /lib/modules/X.Y.Z/

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

要创建以太网引导映像:

root #emerge --ask net-misc/mknbi
root #cd /boot
root #mkelf-linux -params="root=/dev/ram0 init=/linuxrc ip=dhcp" kernel... initrd... > etherboot.img

要创建 OpenBoot/SPARC64 TFTP 映像:

root #emerge --ask sys-apps/sparc-utils
root #cd /boot
root #elftoaout kernel... -o kernel.aout
root #piggyback64 kernel.aout System.map-... initrd-...
root #mv kernel.aout openboot.img

openboot.img 文件是启动映像。

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 /nfs/livecd/add/ directory. All that needs to be done here is copy the modules-X.Y.Z.tar.gz archive to the /nfs/livecd/add/ directory.

The following assumes that /nfs/livecd is an exported NFS share:

root #mount /tmp/gentoo-livecd.iso /mnt/cdrom -o loop
root #cp -p /mnt/cdrom /nfs/livecd
root #umount /mnt/cdrom

现在将 modules.tar.gz 文件复制到 /add 中:

root #mkdir /nfs/livecd/add
root #cp /tmp/modules-X.Y.Z.tar.gz /nfs/livecd/add

DHCP 设置

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

FILE /etc/dhcpd.confSample client dhcpd.conf setup
# Here, 192.168.1.2 is the NFS server while 192.168.1.10 will be the IP address of the netbooted machine
host netbootableMachine {
         hardware ethernet 11:22:33:44:55:66;
         fixed-address 192.168.1.10;
         option root-path "192.168.1.2:/nfs/livecd";
}

网络引导说明

Netbooting itself is again very platform-specific. The important part is to specify the ip=dhcp and init=/linuxrc 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 Stop+A at the boot prompt and then enter:

okboot net ip=dhcp init=/linuxrc

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

FILE pxelinux.cfg/defaultDefault entry
DEFAULT gentoo
TIMEOUT 40
PROMPT 1
  
LABEL gentoo
    KERNEL kernel-X.Y.Z
    APPEND initrd=initrd-X.Y.Z root=/dev/ram0 init=/linuxrc ip=dhcp

启动 genkernel initramfs

介绍

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 --lvm and --mdadm options. Do not forget to enable support during boot as well. This can be done using the dolvm and domdadm options.

FILE /boot/grub/grub.confEnabling LVM and/or MDADM support
# Example for GRUB 1.x
title Gentoo Linux
root (hd0,0)
kernel /vmlinuz root=/dev/md3 dolvm domdadm
initrd /initramfs-genkernel-x86_64-3.4.3
在单用户模式下启动

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.

FILE /boot/grub/grub.confBooting in single-user mode
# Example for GRUB 1.x
title Gentoo Linux
root (hd0,0)
kernel /vmlinuz root=/dev/md3 init_opts=S
initrd /initramfs-genkernel-x86_64-3.4.3

故障排除

编译失败:未找到内核

This failure can be experienced when attempting to compile a kernel for one architecture with a kernel .config file that has a target of a different architecture than the target. This could be as simple as a machine running an amd64 kernel attempting to compile for a x86 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, genkernel 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, genkernel will presume it should be looking for a 64-bit kernel.

Suppose then that the kernel's .config file has x64 disabled. The make command will execute and the resulting kernel binary will be placed in the associated x86 directory. When genkernel 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 genkernel's --arch-override option to, in this case, the x86 architecture. The final command could look like this:

root #genkernel --kernel-config=/usr/src/linux/.config --btrfs --install --arch-override=x86 all

To override the architecture choice permanently, modify the ARCH_OVERRIDE variable in the /etc/genkernel.conf file.

必须使用新内核手动重建外部模块(例如 xtables_addons)

Genkernel can rebuild external modules after the kernel is built; edit genkernel.conf to include this line:

FILE /etc/genkernel.confRun a command after building a new kernel
# Run the specified command in the current environment after the kernel and
# modules have been compiled, useful to rebuild external kernel module
# (use "emerge --quiet @module-rebuild" for >=portage-2.2) or installing additional
# files (use 'copy_image_with_preserve dtb path/to/dtb dtb ${KNAME}-${ARCH}-${KV}')
#CMD_CALLBACK=""
CMD_CALLBACK="emerge --quiet @module-rebuild"

另请参阅

  • Manual kernel configuration - For the times it is necessary to to do things manually.
  • Dracut - Another initramfs builder available in Gentoo.
    This page is based on a document formerly found on our main website gentoo.org.
    The following people contributed to the original document: Tim Yamin, Jimi Ayodele, Thomas Seiler, , Sebastian Pipping (sping), José Fournier (jaaf)
    They are listed here because wiki history does not allow for any external attribution. If you edit the wiki article, please do not add yourself here; your contributions are recorded on each article's associated history page.