Genkernel/ja

というツールを使うと、kernelとinitramfsを自動的にビルドすることができます. その特徴を大まかに説明しますと：


 * カーネルソースの設定.
 * 圧縮されたカーネルをビルドし、にコピーします.
 * initramfsを作成してにコピーします.
 * にシンボリックリンクを作成する.
 * 暗号化に関連するファイル、ブートイメージ、追加モジュールなど、カスタムコンテンツをinitramfsに追加する.
 * initramfsを圧縮する.
 * 新しく作成されたカーネルとinitramfsをブートするようにブートローダーを設定する.

Emerge
genkernelのインストールを開始します:

使い方
genkernel を実行する際の一般的な文法は以下のとおり:

オプション
genkernel の実際の挙動は、多数のオプションの組合せによって変わります. そのオプションの多くは、 内で有効/無効に設定するか、 genkernel コマンドに引渡します. コマンドに引渡したオプションのほうが、 内で定義されたものより優先して処理されます. ファイルにはとても多くの記載がありますが、そのうちのとりわけ一般的に利用されるオプションについて、ここではみていきましょう. より詳細な解説は、 や、 man genkernel コマンドの出力を参照してください.

ユーザ対話型操作を提供するオプション
カーネルコンフィグレーションに関する下記のオプションは、コンフィグレーションの過程においてどのような対話型操作を提供するかを指定します. その過程の最中でも、ユーザはコンフィグファイルを保存するか否かを選択することができます. 以下が主なコンフィグレーションオプションです :


 * Points to the Genkernel configuration file to use (defaults to ).
 * Points to the Genkernel configuration file to use (defaults to ).


 * 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 の仕様を左右します.


 * Activates (or deactivates) support for Fbsplash framebuffer splash in the genkernel-built initrd image. To override the default theme used by fbsplash, use  (where   is the title of one of the directories inside the  directory).
 * Activates (or deactivates) support for Fbsplash framebuffer splash in the genkernel-built initrd image. To override the default theme used by fbsplash, use  (where   is the title of one of the directories inside the  directory).


 * 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.
 * 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.


 * Force keymap selection during the boot sequence.
 * Force keymap selection during the boot sequence.


 * Enables keymap selection at boot (e.g. for LUKS container password input). The desired keymap can be passed in boot options as the value of  (name of the keymap file without .map). Available keymap files can be found in.
 * If the keymap you need is not available in genkernel you can convert one of the existing keymaps (available in ) using  . See  man page for details.
 * If the keymap you need is not available in genkernel you can convert one of the existing keymaps (available in ) using  . See  man page for details.


 * 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 package on the system  before enabling this option, then review the LVM article on the Gentoo wiki.
 * 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 package on the system  before enabling this option, then review the LVM article on the Gentoo wiki.


 * 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.
 * 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.


 * 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  (and   shall be the unencrypted device LUKS creates).
 * 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  (and   shall be the unencrypted device LUKS creates).


 * Adds support for disk label and UUID support to the initrd.
 * Adds support for disk label and UUID support to the initrd.


 * Adds support for iSCSI to the initrd.
 * Adds support for iSCSI to the initrd.


 * Adds support for Multipath to the initrd.
 * Adds support for Multipath to the initrd.


 * 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 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.
 * 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 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.


 * Overrides the default cache location used while compiling the kernel.
 * Overrides the default cache location used while compiling the kernel.


 * Specifies the location of the temporary directory used by genkernel while compiling the kernel.
 * Specifies the location of the temporary directory used by genkernel while compiling the kernel.


 * Includes support for the Unification File System in the initrd image.
 * Includes support for the Unification File System in the initrd image.


 * Detects whether or not the directory needs to be mounted on a separate partition. It will check  script for instructions on how to mount the boot partition on a file system (if needed).
 * Detects whether or not the directory needs to be mounted on a separate partition. It will check  script for instructions on how to mount the boot partition on a file system (if needed).


 * Creates an early cpio filled with microcode for Intel/AMD processors for Xen and Linux early microcode support
 * Creates an early cpio filled with microcode for Intel/AMD processors for Xen and Linux early microcode support

ビルドの際に使用されるツールを選択するためのオプション
次のオプションはgenkernelをすることによってサポートされており、カーネルを組み立てている間、関連するアプリケーションに渡されます. これらのオプションは、はるかに低いレベルではあるが、カーネルのコンパイル処理に使用するコンパイルツールに影響を与えます.


 * Specifies the compiler employed during the kernel compilation process.
 * Specifies the compiler employed during the kernel compilation process.


 * Specifies the linker employed during the kernel compilation process.
 * Specifies the linker employed during the kernel compilation process.


 * Specifies the assembler employed during the kernel compilation process.
 * Specifies the assembler employed during the kernel compilation process.


 * Specifies an alternative to the GNU make utility employed during the kernel compilation process.
 * Specifies an alternative to the GNU make utility employed during the kernel compilation process.


 * Specifies the compiler employed during the compilation of support utilities.
 * Specifies the compiler employed during the compilation of support utilities.


 * Specifies the linker employed during the compilation of support utilities.
 * Specifies the linker employed during the compilation of support utilities.


 * Specifies the assembler employed during the compilation of support utilities.
 * Specifies the assembler employed during the compilation of support utilities.


 * Specifies an alternative to the GNU make utility employed during the compilation of support utilities.
 * Specifies an alternative to the GNU make utility employed during the compilation of support utilities.


 * Specifies the number of concurrent threads that the make utility can implement while the kernel (and utilities) are being compiled. The variable  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   or  ; a system with two cores most likely uses the   or   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.)
 * Specifies the number of concurrent threads that the make utility can implement while the kernel (and utilities) are being compiled. The variable  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   or  ; a system with two cores most likely uses the   or   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.)

コンパイル手順に関するオプション
次のオプションは通常、実際のコンパイル時に有効になります:


 * Specifies an alternative kernel source location, rather than the default location.
 * Specifies an alternative kernel source location, rather than the default location.


 * Specifies what alternative kernel configuration will be used, rather than the default file.
 * Specifies what alternative kernel configuration will be used, rather than the default file.


 * Specifies a prefix to the directory where kernel modules will be installed (default path is the directory.)
 * Specifies a prefix to the directory where kernel modules will be installed (default path is the directory.)


 * Activates (or deactivates) the command before compiling the kernel. The  command removes all object files and dependencies from the kernel's source tree.
 * Activates (or deactivates) the command before compiling the kernel. The  command removes all object files and dependencies from the kernel's source tree.


 * Activates (or deactivates) the command before kernel compilation. Like the  command listed above,  removes all object files and dependencies from the kernel's source tree. However, any previous configuration files (in  or ) will also be purged from the kernel's source tree. If it is undesirable that the kernel's  file keeps disappearing, be sure to disable this option!
 * Activates (or deactivates) the command before kernel compilation. Like the  command listed above,  removes all object files and dependencies from the kernel's source tree. However, any previous configuration files (in  or ) will also be purged from the kernel's source tree. If it is undesirable that the kernel's  file keeps disappearing, be sure to disable this option!


 * Issues the command, which attempts to collect configuration information for the system's architecture from a generic script in . This is a non-interactive process; no user input is entertained. Also, if   is used in conjunction with , the latter option is negated, resulting in the activation of the   option.
 * Issues the command, which attempts to collect configuration information for the system's architecture from a generic script in . This is a non-interactive process; no user input is entertained. Also, if   is used in conjunction with , the latter option is negated, resulting in the activation of the   option.


 * Calls the specified arguments (, 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.
 * Calls the specified arguments (, 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.


 * Activates (or deactivates) the 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  if it is on a separate partition before running the install command.
 * Activates (or deactivates) the 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  if it is on a separate partition before running the install command.


 * Refrains from copying any modules to the genkernel-created initrd image. This option is an exception to the rule about the  prefix; omission of this prefix creates an invalid genkernel option.
 * Refrains from copying any modules to the genkernel-created initrd image. This option is an exception to the rule about the  prefix; omission of this prefix creates an invalid genkernel option.


 * Copies all available modules to the genkernel-created initrd image.
 * Copies all available modules to the genkernel-created initrd image.


 * Creates the initrd image, prior to the kernel image (this hack currently applies only to PPC Pegasos systems).
 * Creates the initrd image, prior to the kernel image (this hack currently applies only to PPC Pegasos systems).

デバッグ用オプション
カーネルのコンパイルプロセス中にデバッグオプションを使用すると、報告された情報の量だけでなく、言ったデータの表示を制御します.


 * Controls the level of verbosity for information provided by genkernel. The variable  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.
 * Controls the level of verbosity for information provided by genkernel. The variable  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.


 * Ignores the value set by the  option (above) and sends all debugging data produced by genkernel to the specified output file. Outputs to  by default.
 * Ignores the value set by the  option (above) and sends all debugging data produced by genkernel to the specified output file. Outputs to  by default.


 * Activates (or deactivates) colored output of debugging information (reported by genkernel) using escape sequences.
 * Activates (or deactivates) colored output of debugging information (reported by genkernel) using escape sequences.


 * Activates (or deactivates) the full post-run cleanup for debug purposes.
 * Activates (or deactivates) the full post-run cleanup for debug purposes.

アクション
The action passed on the command line with the tells genkernel what action to perform. The following actions are supported:

Starting off
genkernelを実行する方法はいくつかありますが、ほとんどのユーザーに推奨最小侵襲アプローチは、genkernel allによって提供されています. ここでは、ほとんどのシステムに適しています一般的な構成が使用されます. 先に述べたように、このアプローチには欠点がないわけではありません. 作成されたモジュールのほとんどは、平均的なユーザーには役に立たないとコンパイル時間を増加させることができます. 以下は、rootとしてgenkernelをするために特定のオプションを渡すことによって達成より効率的な手法の説明図です.

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.

カーネルの変更
The first thing that should be done is to allow the triggering of in the  file:

ファイル管理
genkernelをを使用している間、ユーザーは、カーネルのコンフィギュレーションとカーネルイメージファイルの管理やカーネルソースは、システムによって処理される方法に関連するいくつかの側面を知っていなければなりません.

ソースファイル
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.

The directory might look like this:

The symlink can be changed in different ways.


 * 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.

コンパイル済コンフィグレーションの保存
コマンドラインから、またはの中から genkernelオプションが有効になっている場合、コンパイルされたカーネル設定はディレクトリに保存されます. 同時に、設定はディレクトリのファイルに保存されますが、このファイルは次ので再利用されません.

カーネルとinitramfsを /boot ディレクトリへインストール
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:


 * 最初のパラメータは、自身のために語っています.


 * 2番目のパラメータは、コンパイルされたカーネル構成をに保存するように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.

After running, the directory might look like this:

ブートローダの設定
新しいカーネルがブート可能でない場合であっても、そのようにブートローダの設定で上記のシンボリックリンクを使用することができ、ユーザーは常にブート古いものにすることができます.

genkernelによって提供されるカーネルとintirdが正しく動作するようにするには、ブートローダの設定ファイルに最小限の情報を指定します.


 * 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.

Here is how the file might look.

作業ファイルの保存
genkernelのアプリケーションが自動的にファイルへの新しい変更を保存します. 以前の変更が保存される場合、次のアクションが取られる必要があります.


 * 保存する最初のファイルは、のカーネル構成ファイルです. カーネルの再コンパイル前にソースが変更されていない場合、このファイルの以前に使用された名前が使用されます. したがって、以前の構成ファイルを別の名前でコピーすると、新しい構成の開始点としてファイルを使用可能にしたまま、情報を保持するのに役立ちます.


 * 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:

Checking that initramfs includes necessary utilites before booting
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:

From an installation 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.

ネットブートをサポートしたカーネルとinitramfsを構築
カーネルの設定をしながら、ネットブートのサポートを有効にするには、次のオプションが含まれます. :

まず、カーネルイメージは、システムのネットワークインタフェースカード（NIC）用のドライバが含まれている必要があります. 通常、このようなデバイスのドライバがモジュールとしてコンパイルされます. しかし、そのようなドライバがカーネルイメージにはなくモジュールとして直接コンパイルされていること（ネットブート用）が不可欠です.

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.

これらのオプションは、起動時にDHCP要求を送信するために、カーネルに伝えます.

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.

コンパイル処理が完了すると、カーネルのモジュールを含む圧縮tarボール（tar.gz形式）を作成します. カーネルのバージョンがインストールCDのカーネルイメージのバージョンと一致しない場合は、このステップは必要なだけです.

すべてのモジュールを含むアーカイブを作成するには:

ネットワークブートメカニズムに応じて、次のいずれかの手順に従う必要があります. :

etherbootにイメージを作成するには:

OpenBootの/ SPARC64のTFTPイメージを作成するには:

The file is the boot image.

最後に、TFTPサーバにこのカーネルをコピーします. 詳細は、アーキテクチャに依存していると、このガイドの範囲を超えています. 興味のある特定のプラットフォームのドキュメントを参照してください.

NFS setup
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:

Now copy the file into :

DHCP setup
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 instructions
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:

PXE のためには、pxelinux (syslinuxの一部)をセットアップし、 を作成して以下の行を続けます:

はじめに
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.

Loading LVM or software-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.

シングルユーザーモードでブートします
ブートアップが失敗した何らかの理由で場合は、シングルユーザーモードでブートして、システムを救出することも可能です. これは、本当に必要なサービスをロードし、救助（root）シェルにユーザーをドロップします.

compile failed: Kernel not found
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.

external modules (such as xtables_addons) must be rebuilt manually with a new kernel
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.