genkernel

From Gentoo Wiki
Jump to:navigation Jump to:search
This page is a translated version of the page Genkernel and the translation is 71% complete.
Resources
Article status
This article has some todo items:
  • 全般的に genkernel-4 用に記事を更新する必要あり
  • --boot-font 機能のドキュメントを追加
  • --bcache 機能のドキュメントを追加
  • gk.keep 機能のドキュメントを追加 (/etc/initramfs.mounts も含めて)

genkernel は、カーネルinitramfs を自動的にビルドすることができる Gentoo 謹製のツールです。その主な特徴は:

  • カーネルソースを設定します。
  • 圧縮されたカーネル bzImage をビルドし、/boot にコピーします。
  • initramfs を作成して /boot にコピーします。
  • /boot にシンボリックリンクを作成します。
  • 暗号化に関連するファイル、ブートスプラッシュイメージ、追加モジュールなど、カスタムコンテンツを initramfs に追加します。
  • 新しく作成されたカーネルと initramfs をブートするようにブートローダを設定します。
メモ
genkernelカスタムのカーネル設定を「自動で」生成してくれるというのは、ありがちな誤解です。genkernel はカーネルのビルドと initramfs の生成を自動化しますが、カスタムのカーネル設定は生成することはありません。カーネル設定を特に提供しない場合、genkernel は汎用的なカーネル設定を使用して、日常的な使用に適した汎用カーネルを生成します (ただしカーネルモジュールは巨大になります)。


genkernel の initramfs についても同様です: その第一目標は、できるだけ早く実システムに制御を渡すことができるように、ルートファイルシステムを格納している (ブロック) デバイスをマウントするのに必要最小限のものを機能させることです。

利用可能なすべてのモジュールをロードしたり、利用可能なすべてのデバイスを開始したり、追加のボリュームをアンロックしたり、ネットワークを開始したり、その他便利なことを行うのは、genkernel のゴールではありません。実システムがブートを完了した後にこれらのことを実行できるように、通常のブート時サービスをを構成することを忘れないでください。

インストール

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

使い方

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

root #genkernel [オプション ...] アクション

オプション

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

メモ
オプションのいくつかは、二択式で指定します。--[no-]option_name のような形式で、角括弧で記載した二択の効果は、例えば以下のとおりです。:
コード オプションを有効または無効にする
--[no-]menuconfig : 有効化 [無効化] ...
無効にする設定しかないオプション、つまり no- で始まるもので、かつ、二択の選択が不可能な場合は、角括弧なしで記載しています。

ユーザ対話型操作を提供するオプション

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

--config=/path/to/genkernel.conf
使用するgenkernelの設定ファイルを指定します(既定では/etc/genkernel.confです)。
--kernel-config=/path/to/kernel.config
使用するカーネル設定ファイルを指定します。現在実行中のカーネルからカーネル設定を再利用するために、/proc/config.gz を (それが存在する場合は) 指定することができます。genkernel はデフォルトでは、同一カーネルバージョンの以前のビルド時のコンフィグか、以前のコンフィグが存在しない場合はデフォルトのカーネルコンフィグを使用します。genkernel のジェネリックカーネルコンフィグを利用を強制するには、特殊値 default を使用してください。失われたりエラーの原因となったりするリスクがあるため、この場所は /usr/src/linux/.config にしてはいけません
--[no-]menuconfig
カーネルをビルドする前に、make menuconfigコマンドを実行するかを指定します(このコマンドはインタラクティブな設定メニューを起動します)。
--gconfig
GTK ライブラリに依存するカーネル設定ユーティリティを提供します。このオプションはX-windowシステムを利用するため、ほとんどの人にとってこのツールを使うことで、カーネルの設定がより簡単で明瞭だと感じられることが利点です。このオプションを利用するためにはX-windowシステムを必要とするため、コマンドラインでは動作しないことが欠点です。
--xconfig
QTライブラリに依存するカーネル設定ユーティリティを提供します。このオプションはX-windowシステムを利用するため、ほとんどの人にとってこのツールを使うことで、カーネルの設定がより簡単で明瞭だと感じられることが利点です。このオプションを利用するためにはX-windowシステムを必要とするため、コマンドラインでは動作しないことが欠点です。
--[no-]save-config
後の使用に備えて、カーネルの設定を/etc/kernelsディレクトリに保存するかを指定します。
--kernel-append-localversion=-mycfg42
カーネルの LOCALVERSION 値を変更します。これは /boot 内のカーネルおよび initramfs のファイル名と、/lib/modules/ ディレクトリ内のモジュールに影響を与えます。これは、カーネルバイナリ、initramfs、およびモジュールを、新しい独立したリビジョンを付与して構築するのに特に有用です。上の例を使用して、amd64 上で =sys-kernel/gentoo-sources-5.4.2 をデフォルト設定でビルドすると、/boot/vmlinuz-5.4.2-gentoo-x86_64-mycfg42/boot/initramfs-5.4.2-gentoo-x86_64-mycfg42.img および /lib/modules/4.19.88-gentoo-x86_64-mycfg42 が作成されるでしょう。

生成されるシステムに関するオプション

以下のコンフィグレーションオプションは、生成されるカーネルや initrd/initramfs で有効化/無効化される機能を決定します。

--[no-]splash
genkernel 製の initrd イメージで Fbsplash フレームバッファスプラッシュのサポートを有効化 (または無効化) します。fbsplash によって使用されるデフォルトテーマを上書きするには、--splash=PreferredTheme (ここで PreferredTheme/etc/splash ディレクトリの中のディレクトリのどれかの名前です) を使用してください。
--splash-res=PreferredResolution
このオプションは、システムの起動中に initrd によってサポートされるスプラッシュスクリーンの解像度を選択します。これはふたつの理由により有用です。ひとつめは、システムに関連するスプラッシュスクリーンの解像度だけを選択することができるためです。ふたつめは、initrd による不必要なディスク消費量の増加を防ぐためです。(initrd はシステムの構成に関係の無い解像度をサポートする必要が無いからです。) しかしながら、このオプションはカーネルをインストール CD のためにコンパイルする場合は省くのが最善です; これにより、すべての可能な解像度に対してスプラッシュをサポートすることができます。
--do-keymap-auto
ブートシーケンス中にキーマップの選択を強制します。
--keymap
ブート時のキーマップ選択を有効化します (例えば、LUKS コンテナパスワード入力のために)。望ましいキーマップをブートオプションで keymap の値として渡すことができます (.map を除いたキーマップファイルの名前です)。利用可能なキーマップファイルは /usr/share/genkernel/defaults/keymaps/ で見つかります。
必要なキーマップが genkernel で利用可能でない場合は、既存の sys-apps/kbd キーマップ (/usr/share/genkernel/defaults/keymaps/ で利用可能) から選択して、loadkeys --bkeymap を使って変換できます。詳しくは loadkeys の man ページを確認してください。
--lvm
システムで利用可能であれば、Logical Volume Management (LVM2) を利用したストレージへのサポートを静的バイナリから取り込みます。利用可能でない場合は、関連する (静的な) LVM2 バイナリがコンパイルされます。このオプションを有効化する前に、sys-fs/lvm2 パッケージをシステムにインストール (emerge sys-fs/lvm2) していることを確認して、Gentoo wiki の LVM の記事を再確認してください。
--dmraid
DMRAID のサポートを含めます; カーネルのデバイスマッパサブシステムを利用して RAID マッピングを作成するユーティリティです。DMRAID はソフトウェア RAID セット (例えば ATARAID) と、それに含まれる DOS パーティションを発見し、有効化し、プロパティを表示します。
--luks
Linux Unified Key Setup または LUKS のサポートを含めます。これにより、ルートファイルシステムを含む、LUKS で暗号化されたデバイスを使用できます。ブートローダ上で、暗号化されたデバイスを crypt_root の値として設定し、root を LUKS が作成する復号されたデバイスに設定してください (マウントするパスが /dev/mapper/root であれば、正しいブートパラメータは次のようになります: GRUB_CMDLINE_LINUX="... crypt_root=UUID=<crypto_LUKS uuid> root=/dev/mapper/root ...")。
--iscsi
initrd に iSCSI のサポートを追加します。
--multipath
initrd に Multipath のサポートを追加します。
--linuxrc=/path/to/the/linuxrc_file
ユーザ作成の linuxrc を指定します。linuxrc は、実際のブートプロセスに先行する、カーネルのスタートアップステージの中で初期化されるスクリプトです。デフォルトの linuxrc スクリプトは /usr/share/genkernel/ ディレクトリで見つかります。このスクリプトを使用することで、小さなモジュール化されたカーネルにブートすることが可能になります; システムにとって必要になる最小限のドライバを (モジュールとして) ロードしようとします。
--cachedir=/path/to/alt/dir
カーネルのコンパイル中に使用されるキャッシュの場所をデフォルトから上書きします。
--tempdir=/path/to/new/tempdir
カーネルのコンパイル中に genkernel によって使用される一時ディレクトリの場所を指定します。
--unionfs
initrd に Unification File System のサポートを含めます。
--mountboot
/boot ディレクトリを独立したパーティションにマウントする必要があるかどうか検出します。ブートパーティションをファイルシステムにマウントする方法についての指示のために、(必要であれば) /etc/fstab スクリプトをチェックするでしょう。
--microcode
Xen および Linux の早期マイクロコードサポートのために、Intel/AMD プロセッサのためのマイクロコードを含む早期 cpio を作成します

ビルドの際に使用されるツールを選択するためのオプション

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

--kernel-cc=someCompiler
カーネルコンパイルプロセス中に使用されるコンパイラを指定します。
--kernel-ld=someLinker
カーネルコンパイルプロセス中に使用されるリンカを指定します。
--kernel-as=someAssembler
カーネルコンパイルプロセス中に使用されるアセンブラを指定します。
--kernel-make=someMake
カーネルコンパイルプロセス中に使用される GNU make ユーティリティの代替を指定します。
--utils-cc=someCompiler
サポートユーティリティのコンパイル中に使用されるコンパイラを指定します。
--utils-ld=someLinker
サポートユーティリティのコンパイル中に使用されるリンカを指定します。
--utils-as=someAssembler
サポートユーティリティのコンパイル中に使用されるアセンブラを指定します。
--utils-make=someMake
サポートユーティリティのコンパイル中に使用される GNU make ユーティリティの代替を指定します。
--makeopts=-jX
カーネル (とユーティリティ) をコンパイルするときに、make ユーティリティが実行できる並行スレッド数を指定します。 変数 X は自由に選択してかまいませんが、もっともよく使われる値はシステムが使用しているコア数 + 1 か、あるいは単にシステムのコア数です。つまり、1 コアのシステムでは、もっともよく使われるオプションの値は -j2 または -j1 で、2 コアのシステムでは -j3 または -j2 オプションがもっともよく使われる、という感じです。(Symmetric Multi-Processing (SMP) 対応がカーネルで有効化されていれば、Hyper-Threading™ (HT) Technology に対応したプロセッサ 1 個を備えるシステムは 2 コアとして扱うことができます。)

コンパイル手順に関するオプション

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

--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 which kernel configuration will be used. By default, genkernel will determine kernel version found in --kerneldir and look for kernel config (KV) in /etc/kernels/kernel-config-$KV. If no kernel configuration was found, genkernel will look for a generic kernel configuration in /usr/share/genkernel/$ARCH. A special value default can be used to force usage of genkernel's generic kernel configuration.
ヒント
Use --kernel-config=/proc/config.gz to start building a new kernel based on kernel configuration from currently running kernel.
Note: This will only work if current active kernel was built with CONFIG_IKCONFIG=y which is normally the case.
--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.
--[no-]module-rebuild
Runs, or does not run emerge @module-rebuild to build out-of-tree modules after kernel and kernel modules have been built. This option is enabled by default.
--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 initramfs.
メモ
Before genkernel-4, this callback was used to trigger rebuild of out-of-tree modules. Since genkernel-4, a dedicated command-line parameter --module-rebuild was introduced, see above.
--[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).

デバッグ用オプション

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

--loglevel=<0|1|2|3|4|5>
genkernel によって印字される情報の詳細度を制御します。LOGLEVEL 変数の値は 0 から 5 の間の整数値です。'0' は最小限の出力 (=出力なし) を表し、'5' は、カーネルコンパイルと initramfs 構築プロセス中の genkernel の挙動について可能な限り多くの情報を提供します。
メモ
Genkernel はデフォルトで、常に完全な出力を /var/log/genkernel.log にログとして出力するでしょう。--loglevel は画面上に表示される出力のみを制御します。
--logfile=/path/to/output_file
genkernel が出力するログファイルのデフォルトの出力先。デフォルトは /var/log/genkernel.log です。
--[no-]color
色付き出力を有効化 (または無効化) します。
--[no-]debug-cleanup
デバッグ目的のために、実行後の完全な後片付けを有効化 (または無効化) します。

アクション

コマンドライン上でgenkernel [options ...] actionによって渡されるアクションは、genkernelにどのアクションを起こさせるかを指定します。以下のアクションが対応しています:

アクション 説明
all 全てのステージをビルドします — initrd、カーネルイメージそしてモジュールです。
bzImage カーネルイメージだけをビルドします。
kernel カーネルイメージとモジュールだけをビルドします。
initramfs initramfs/ramdiskイメージだけをビルドします。
ramdisk initramfs/ramdiskイメージだけをビルドします。

設定

実行

genkernelを実行する方法はいくつかありますが、ほとんどのユーザーにお薦めしたい最も簡単な方法は、genkernel allでしょう。はいこれで、ほとんどのシステムでうまくいくような設定がされました。しかし先に述べたように、このアプローチには欠点がないわけではありません。作成されたモジュールのほとんどは平均的なユーザーには無駄であり、その上コンパイル時間も長くなるかもしれません。そこでもっと効果的なアプローチをお教えしましょう。rootユーザーでgenkernelに、幾つかのオプションを渡します:

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

上の操作によって、genkernel は LUKS および LUKS2 で暗号化されたボリュームを開けるカーネルを作成し、cryptsetup をコンパイルして initramfs に埋め込み (--luks)、このカーネルと initramfs は手動でインストールする必要があります (--no-install)。カーネルソースツリーの準備中に、genkernel はソースツリー内の既存のオブジェクトファイルを片付けません (--no-clean)。ユーザがシステムに対しどのモジュールをビルドするか選択できるように、メニュー式のカーネルコンフィグユーティリティが表示されます (--menuconfig)。

--no-install--install オプションで置き換えると、genkernel に新しいカーネルを /boot ディレクトリに自動でインストールさせることができ、--symlink が指定されると、シンボリックリンクを作成します。--mountboot オプションを使用すると genkernel に、必要であれば /boot パーティションを自動でマウントさせることができます。

メモ
/etc/genkernel.confファイルがgenkernelコマンドによって実行時に読み込まれること、そしてそのファイル内で定義されているあらゆるオプションが適用されることを忘れないでください(例外として、コマンドラインオプションはファイル内の設定より優先されます)。

カーネルの変更

最初にすべきことは、/etc/genkernel.conf ファイル内で make menuconfig が起動されるように設定することです:

ファイル /etc/genkernel.conf/etc/genkernel.conf でコンフィグメニューの使用を強制する
# Run 'make menuconfig' before compiling this kernel?
MENUCONFIG="yes"

ファイル管理

genkernelを使うのであれば、ユーザーは以下のことについて把握しておかなければいけません。一つ目はカーネルの設定に関する事柄、二つ目はカーネルのイメージファイルの管理に関する事柄、三つ目はカーネルソースがシステムによってどのように扱われるかに関する事柄です。

ソースファイル

emerge -u gentoo-sources を実行すると、新しいソースが利用可能なときはいつでも、それを保管するための新しいカーネルソースディレクトリが /usr/src/ 下に作成されます。通常、アクティブなカーネルソースディレクトリは /usr/src/linux シンボリックが指し示しています。

/usr/src ディレクトリは以下のようになっているかもしれません:

user $ls -l /usr/src
total 24
drwxr-xr-x  6 root root 4096 Dec 16 00:56 .
drwxr-xr-x 12 root root 4096 Dec 15 12:42 ..
-rw-r--r--  1 root root    0 Mar 19  2015 .keep
lrwxrwxrwx  1 root root   22 Dec 16 00:56 linux -> linux-5.3.14-gentoo-r1
drwxr-xr-x 26 root root 4096 Nov 24 03:33 linux-4.19.85-gentoo
drwxr-xr-x 27 root root 4096 Dec  9 15:10 linux-4.19.88-gentoo
drwxr-xr-x 27 root root 4096 Dec 16 00:51 linux-4.19.89-gentoo
drwxr-xr-x 25 root root 4096 Dec 16 00:58 linux-5.3.14-gentoo-r1

/usr/src/linux シンボリックリンクはいくつかの方法で変更することができます。

  • symlink USE フラグがセットされている場合、/usr/src/linux シンボリックリンクは自動的に、新しく emerge されたソースを指すように更新されます。
  • symlink USE フラグがセットされていない場合、ユーザは eselect kernel list に続けて eselect kernel set コマンドを使用して、シンボリックリンクの指す先を変更することができます。

genkernel は常に /usr/src/linux シンボリックリンクが指すソース (だけ) を使います。

カーネルコンフィグレーションファイル

アクティブなカーネルソースを使ったカーネルのコンパイルを一度実行したことがある場合、直前のカーネルの bzImage を作成するときに適用されたカーネルコンフィギュレーションを格納する、/etc/kernels ディレクトリの中に、ファイルがあるかもしれません。このファイルは例えば、kernel-config-5.3.14-gentoo-r1-x86_64-wifitest2 のような名前がつけられています。ここで x86_64 はシステムのアーキテクチャで、5.3.14-gentoo-r1使用されたソースのパッケージ/バージョンで、wifitest2 は追加されるユーザ定義の LOCALVERSION 値で、置き換えられているかもしれません。

genkernel --menuconfig all を実行したときに、初期状態のコンフィギュレーションとして使用されるのが、この kernel-config-5.3.14-gentoo-r1-x86_64-wifitest2 ファイルです。

新しいカーネルソースで初めて genkernel を実行している場合、または前回の結果が保存されていない場合、このファイルは usr/share/genkernel/arch/x86_64/generated-config (を x86_64 は実際のアーキテクチャで置き換えた場所) にあるデフォルトのコンフィギュレーションファイルで置き換えられます。

メモ
このデフォルトのコンフィギュレーションファイルのパスは、/etc/genkernel.conf ファイルで DEFAULT_KERNEL_CONFIG 変数を設定することで置き換えられます。
コンパイル済コンフィグレーションの保存

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

警告
--save-config genkernel オプションを設定して genkernel を実行するたびに、/etc/kernels 内の設定ファイルが上書きされることに注意してください。そのため、これを維持するためには genkernel を実行する前に、このファイルを新しい名前にコピーすることを強くおすすめします。
カーネルとinitramfsを /boot ディレクトリへインストール

genkernel を実行するときに --install オプションを指定すると、genkernel に対し、カーネルイメージと initramfs を /boot ディレクトリにインストールさせることができます。--install を便利な方法で実行するには、/etc/genkernel.conf ファイルで次を設定してください:

ファイル /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 grub
# Possible values: empty/"no", "grub", "grub2"
BOOTLOADER="grub2"
  • 最初のパラメータは、その名前の通りです。
  • 2 番目のパラメータは、コンパイルされたカーネル構成を /etc/kernels に保存するように genkernel に指示します。
  • 最後の 2 つのオプションは、自動的に grub 設定を更新するように genkernel に指示します。実際には、次のことが起こります:
    • 以前のカーネルイメージが同名ですでに存在する場合は、その名前の後に .old をつけた名前にリネームされます。それを指す kernel.old シンボリックリンクが自動的に作成されます。
    • 新しいカーネルが、/boot 内で同名のカーネルに取って代わります。もしこれが初回のカーネルコンパイルだった場合、新しいカーネルを指す kernel シンボリックリンクが自動的に作成されます。

genkernel --menuconfig all を実行した後、/boot ディレクトリはこのように見えるかもしれません:

user $ls -al /boot
total 69388
lrwxrwxrwx 1 root root      44 Dec 16 00:58 System.map -> System.map-5.3.14-gentoo-r1-x86_64-wifitest2
-rw-r--r-- 1 root root 3465443 Dec  9 15:05 System.map-4.19.88-gentoo-x86_64
-rw-r--r-- 1 root root 3465554 Dec 16 00:45 System.map-4.19.89-gentoo-x86_64
-rw-r--r-- 1 root root 3645309 Dec 15 16:07 System.map-5.3.14-gentoo-r1-x86_64
-rw-r--r-- 1 root root 3645309 Dec 15 16:07 System.map-5.3.14-gentoo-r1-x86_64.old
-rw-r--r-- 1 root root 3645309 Dec 16 00:58 System.map-5.3.14-gentoo-r1-x86_64-wifitest2
drwxr-xr-x 2 root root    4096 Mar 21  2015 efi
drwxr-xr-x 6 root root    4096 Dec 16 01:02 grub
lrwxrwxrwx 1 root root      47 Dec 16 01:02 initramfs -> initramfs-5.3.14-gentoo-r1-x86_64-wifitest2.img
-rw-r--r-- 1 root root 3631084 Dec  9 15:34 initramfs-4.19.88-gentoo-x86_64.img
-rw-r--r-- 1 root root 3637148 Dec 16 00:54 initramfs-4.19.89-gentoo-x86_64.img
-rw-r--r-- 1 root root 3670176 Dec 15 17:41 initramfs-5.3.14-gentoo-r1-x86_64.img
-rw-r--r-- 1 root root 3669692 Dec 16 01:02 initramfs-5.3.14-gentoo-r1-x86_64-wifitest2.img
-rw-r--r-- 1 root root  168960 Nov 16 19:10 intel-uc.img
lrwxrwxrwx 1 root root      41 Dec 16 00:58 kernel -> vmlinuz-5.3.14-gentoo-r1-x86_64-wifitest2
-rw-r--r-- 1 root root 7509552 Dec  9 15:05 vmlinuz-4.19.88-gentoo-x86_64
-rw-r--r-- 1 root root 7509552 Dec 16 00:45 vmlinuz-4.19.89-gentoo-x86_64
-rw-r--r-- 1 root root 7784496 Dec 15 16:07 vmlinuz-5.3.14-gentoo-r1-x86_64
-rw-r--r-- 1 root root 7784496 Dec 15 16:07 vmlinuz-5.3.14-gentoo-r1-x86_64.old
-rw-r--r-- 1 root root 7784496 Dec 16 00:58 vmlinuz-5.3.14-gentoo-r1-x86_64-wifitest2

ブートローダの設定

extlinux

TODO

GRUB Legacy
警告
以下の文章は 2019 年 2 月に Gentoo から削除された GRUB Legacy に関するものです。もし可能なのであれば、できる限り早く GRUB2 に移行してください。

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

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

  • カーネルイメージに渡されるカーネルパラメータに、root=/dev/sdaN を追加してください。ここで /dev/sdaN はルートパーティションを指しています (N は、パーティションが存在している場合はパーティション番号です)。
  • スプラッシュを使用している場合は、カーネルに渡されるパラメータに vga=0x317 のよう適切なモード行を追加し、ブートプロセス中に必要になる詳細度に応じて splash=verbose または splash=silent も追加してください。
  • ブートローダによって必要になる initrd の情報を追加してください。ブートローダに initrd を関知させる方法の詳細については、Gentoo ハンドブックのブートローダ設定の章をお読みください。

以下は grub.conf ファイルがどのようであるかの例です。

ファイル /boot/grub/grub.confgrub.conf ファイルの例
# 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
GRUB

TODO

systemd-boot

TODO

作業中のファイルの退避

genkernel のアプリケーションは、新しい変更を自動的にファイルに保存します。以前の変更を退避しておきたい場合は、次の作業を行う必要があります。

  • 退避させる最初のファイルは、/etc/kernels/ のカーネル構成ファイルです。カーネルの再コンパイル前にソースが変更されていない場合、このファイルの以前に使用された名前が使用されます。 したがって、以前の構成ファイルを別の名前でコピーすると、新しい構成の開始点としてファイルを使用可能にしたまま、情報を保持するのに役立ちます。
  • 次に重要なことは、既に作成されたブート可能なカーネルと initramfs イメージを退避させることです。これを達成するための方法は、状況により異なります:
  1. 直前にコンパイルされたカーネルがブート可能な場合は、genkernel を実行することでこの古いカーネル (initramfs も同様) のイメージがvmlinuz-$KV.old にリネームされて、新しい vmlinuz-$KV が作成されます。つまり、新しいカーネルがブート可能でなかったとしても、ユーザはいつでも古いカーネルをブートすることができるでしょう。
  2. 直前にコンパイルされたカーネルがブート可能でなく、ブート可能なカーネルをコンパイルできたときからソースが変わっていない場合、genkernel を実行する前に、まず新しいカーネルイメージを削除して、直前にブート可能だったカーネルの .old 接尾辞を取り除いてください。これを行わないと、もし新しくコンパイルされたカーネルがまたしてもブート可能でなかった場合、ブート可能だった vmlinuz-$KV.old は、ブートできない vmlinuz-$KV がリネームされることで追い出されてしまい、ユーザにはブート不可能なシステムが残されることになるでしょう。initramfs についても同様の考え方を適用してください。
メモ
genkernel-4 以降では genkernel --kernel-append-localversion=-my-new-revision all を使用して、カーネルイメージ、initramfs、および /lib/modules にインストールされるモジュールを、新しい独自のリビジョンを付与して作成するのが推奨されます。

ソースを変更しながら、以前のカーネル設定を使用して

以前のコンフィギュレーションは、次のように /etc/genkernel.conf 内で MENUCONFIG 変数を通して使用できます:

ファイル /etc/genkernel.confmake menuconfig をセットアップする
# Run 'make menuconfig' before compiling this kernel
MENUCONFIG="yes"
メモ
genkernel を使用する場合は、カーネルのソースコードが変わっていたとしても、make oldconfig を手動で実行する必要はありません。これは、make menuconfig は可能な限り以前のコンフィギュレーションを読み込もうと試みるからです。とはいえ、各オプションと新しいセクションをよく確認しておくことは推奨されることです。

ブートする前に initramfs が必要なモジュール/ユーティリティを含んでいるか確認する

システムを起動する前に、initramfs に必要なユーティリティとモジュールが含まれていることを確認しておくのが良いかもしれません。例えば、LUKS を使用したヘッドレスシステムでリモートアンロック機能を利用するためには、使用中のネットワークインターフェースカードのためのカーネルモジュール、dropbear、そして cryptsetup が含まれていることを確認してください。

lsinitrd を使用する

genkernel-4 より、作成された initramfs は sys-kernel/dracut パッケージに含まれる lsinitrd コマンドを使用して処理することができます:

user $lsinitrd /boot/initramfs-5.3.14-gentoo-r1-x86_64-wifitest2.img
Image: /boot/initramfs-5.3.14-gentoo-r1-x86_64-wifitest2.img: 4,5M
========================================================================
Version: Genkernel 4.0.1 (2019-12-16 00:48:10 UTC)
 
Arguments: --boot-font=none --keymap --compress-initramfs --no-microcode-initramfs --ramdisk-modules --busybox --no-btrfs --no-iscsi --no-multipath --no-dmraid --mdadm --lvm --no-unionfs --no-zfs --no-splash --no-strace --no-gpg --luks --no-firmware --firmware-dir=/lib/firmware --ssh --no-e2fsprogs --no-xfsprogs
 
dracut modules:
========================================================================
drwxr-xr-x  16 root     root            0  Dec 16 01:49 .
drwxr-xr-x   2 root     root            0  Dec 16 01:49 bin
lrwxrwxrwx   1 root     root            7  Dec 16 01:49 bin/ash -> busybox
lrwxrwxrwx   1 root     root            7  Dec 16 01:49 bin/[ -> busybox
-rwxr-xr-x   1 root     root      2351376  Dec 16 01:49 bin/busybox
lrwxrwxrwx   1 root     root            7  Dec 16 01:49 bin/cat -> busybox
lrwxrwxrwx   1 root     root            7  Dec 16 01:49 bin/cut -> busybox
lrwxrwxrwx   1 root     root            7  Dec 16 01:49 bin/echo -> busybox
lrwxrwxrwx   1 root     root            7  Dec 16 01:49 bin/mknod -> busybox
lrwxrwxrwx   1 root     root            7  Dec 16 01:49 bin/mount -> busybox
lrwxrwxrwx   1 root     root            7  Dec 16 01:49 bin/sh -> busybox
lrwxrwxrwx   1 root     root            7  Dec 16 01:49 bin/uname -> busybox
drwxr-xr-x   2 root     root            0  Dec 16 01:49 dev
drwxr-xr-x   8 root     root            0  Dec 16 01:49 etc
-rw-r--r--   1 root     root           24  Dec 16 01:49 etc/build_date
-rw-r--r--   1 root     root           16  Dec 16 01:49 etc/build_id
drwxr-xr-x   2 root     root            0  Dec 16 01:49 etc/dropbear
-rw-------   1 root     root          140  Dec 16 01:49 etc/dropbear/dropbear_ecdsa_host_key
-rw-------   1 root     root          806  Dec 16 01:49 etc/dropbear/dropbear_rsa_host_key
prw-r--r--   1 root     root            0  Dec 16 01:49 etc/dropbear/fifo_root
prw-r--r--   1 root     root            0  Dec 16 01:49 etc/dropbear/fifo_swap
-rw-r--r--   1 root     root           97  Dec 16 01:49 etc/fstab
-rw-r--r--   1 root     root           14  Dec 16 01:49 etc/group
-rw-r--r--   1 root     root         3742  Dec 16 01:49 etc/initrd.defaults
-rw-r--r--   1 root     root        69232  Dec 16 01:49 etc/initrd.scripts
-rw-r--r--   1 root     root          441  Dec 16 01:49 etc/ld.so.cache
-rw-r--r--   1 root     root           78  Dec 16 01:49 etc/ld.so.conf
drwxr-xr-x   2 root     root            0  Dec 16 01:49 etc/ld.so.conf.d
-rw-r--r--   1 root     root           81  Dec 16 01:49 etc/ld.so.conf.d/05gcc-x86_64-pc-linux-gnu.conf
-rw-r--r--   1 root     root         2298  Dec 16 01:49 etc/localtime
drwxr-xr-x   3 root     root            0  Dec 16 01:49 etc/lvm
drwxr-xr-x   2 root     root            0  Dec 16 01:49 etc/lvm/cache
-rw-r--r--   1 root     root        95231  Dec 16 01:49 etc/lvm/lvm.conf
-rw-r--r--   1 root     root         2882  Dec 16 01:49 etc/mdadm.conf
drwxr-xr-x   3 root     root            0  Dec 16 01:49 etc/mdev
-rw-r--r--   1 root     root         1172  Dec 16 01:49 etc/mdev.conf
drwxr-xr-x   2 root     root            0  Dec 16 01:49 etc/mdev/helpers
-rwxr-xr-x   1 root     root          666  Dec 16 01:49 etc/mdev/helpers/nvme
-rwxr-xr-x   1 root     root         1295  Dec 16 01:49 etc/mdev/helpers/storage-device
drwxr-xr-x   2 root     root            0  Dec 16 01:49 etc/modprobe.d
-rw-r--r--   1 root     root         1186  Dec 16 01:49 etc/modprobe.d/aliases.conf
-rw-r--r--   1 root     root          122  Dec 16 01:49 etc/modprobe.d/i386.conf
drwxr-xr-x   2 root     root            0  Dec 16 01:49 etc/modules
-rw-r--r--   1 root     root           24  Dec 16 01:49 etc/modules/ataraid
-rw-r--r--   1 root     root           21  Dec 16 01:49 etc/modules/block
-rw-r--r--   1 root     root          180  Dec 16 01:49 etc/modules/crypto
-rw-r--r--   1 root     root           26  Dec 16 01:49 etc/modules/dmraid
-rw-r--r--   1 root     root           23  Dec 16 01:49 etc/modules/firewire
-rw-r--r--   1 root     root          123  Dec 16 01:49 etc/modules/fs
-rw-r--r--   1 root     root           86  Dec 16 01:49 etc/modules/hyperv
-rw-r--r--   1 root     root           40  Dec 16 01:49 etc/modules/iscsi
-rw-r--r--   1 root     root          437  Dec 16 01:49 etc/modules/lvm
-rw-r--r--   1 root     root          194  Dec 16 01:49 etc/modules/mdadm
-rw-r--r--   1 root     root           75  Dec 16 01:49 etc/modules/multipath
-rw-r--r--   1 root     root          214  Dec 16 01:49 etc/modules/net
-rw-r--r--   1 root     root           56  Dec 16 01:49 etc/modules/nvme
-rw-r--r--   1 root     root          519  Dec 16 01:49 etc/modules/pata
-rw-r--r--   1 root     root           83  Dec 16 01:49 etc/modules/pcmcia
-rw-r--r--   1 root     root          158  Dec 16 01:49 etc/modules/sata
-rw-r--r--   1 root     root          523  Dec 16 01:49 etc/modules/scsi
-rw-r--r--   1 root     root          350  Dec 16 01:49 etc/modules/usb
-rw-r--r--   1 root     root          133  Dec 16 01:49 etc/modules/virtio
-rw-r--r--   1 root     root           15  Dec 16 01:49 etc/modules/waitscan
-rw-r--r--   1 root     root           47  Dec 16 01:49 etc/passwd
-rw-r-----   1 root     root           22  Dec 16 01:49 etc/shadow
-rw-r--r--   1 root     root           25  Dec 16 01:49 etc/shells
-rwxr-xr-x   1 root     root        32331  Dec 16 01:49 init
drwxr-xr-x   2 root     root            0  Dec 16 01:49 .initrd
drwxr-xr-x   6 root     root            0  Dec 16 01:49 lib
lrwxrwxrwx   1 root     root            3  Dec 16 01:49 lib32 -> lib
lrwxrwxrwx   1 root     root            3  Dec 16 01:49 lib64 -> lib
drwxr-xr-x   2 root     root            0  Dec 16 01:49 lib/console
drwxr-xr-x   2 root     root            0  Dec 16 01:49 lib/dracut
-rw-r--r--   1 root     root          312  Dec 16 01:49 lib/dracut/build-parameter.txt
-rw-r--r--   1 root     root           42  Dec 16 01:49 lib/dracut/dracut-gk-version.info
drwxr-xr-x   2 root     root            0  Dec 16 01:49 lib/keymaps
lrwxrwxrwx   1 root     root            9  Dec 16 01:49 lib/keymaps/10.map -> croat.map
lrwxrwxrwx   1 root     root            6  Dec 16 01:49 lib/keymaps/11.map -> cz.map
lrwxrwxrwx   1 root     root            6  Dec 16 01:49 lib/keymaps/12.map -> de.map
lrwxrwxrwx   1 root     root            6  Dec 16 01:49 lib/keymaps/13.map -> dk.map
lrwxrwxrwx   1 root     root           10  Dec 16 01:49 lib/keymaps/14.map -> dvorak.map
lrwxrwxrwx   1 root     root            6  Dec 16 01:49 lib/keymaps/15.map -> es.map
lrwxrwxrwx   1 root     root            6  Dec 16 01:49 lib/keymaps/16.map -> et.map
lrwxrwxrwx   1 root     root            6  Dec 16 01:49 lib/keymaps/17.map -> fi.map
lrwxrwxrwx   1 root     root            6  Dec 16 01:49 lib/keymaps/18.map -> fr.map
lrwxrwxrwx   1 root     root            6  Dec 16 01:49 lib/keymaps/19.map -> gr.map
lrwxrwxrwx   1 root     root           10  Dec 16 01:49 lib/keymaps/1.map -> azerty.map
lrwxrwxrwx   1 root     root            6  Dec 16 01:49 lib/keymaps/20.map -> hu.map
lrwxrwxrwx   1 root     root            6  Dec 16 01:49 lib/keymaps/21.map -> il.map
lrwxrwxrwx   1 root     root            6  Dec 16 01:49 lib/keymaps/22.map -> is.map
lrwxrwxrwx   1 root     root            6  Dec 16 01:49 lib/keymaps/23.map -> it.map
lrwxrwxrwx   1 root     root            6  Dec 16 01:49 lib/keymaps/24.map -> jp.map
lrwxrwxrwx   1 root     root            6  Dec 16 01:49 lib/keymaps/25.map -> la.map
lrwxrwxrwx   1 root     root            6  Dec 16 01:49 lib/keymaps/26.map -> lt.map
lrwxrwxrwx   1 root     root            6  Dec 16 01:49 lib/keymaps/27.map -> mk.map
lrwxrwxrwx   1 root     root            6  Dec 16 01:49 lib/keymaps/28.map -> nl.map
lrwxrwxrwx   1 root     root            6  Dec 16 01:49 lib/keymaps/29.map -> no.map
lrwxrwxrwx   1 root     root            6  Dec 16 01:49 lib/keymaps/2.map -> be.map
lrwxrwxrwx   1 root     root            6  Dec 16 01:49 lib/keymaps/30.map -> pl.map
lrwxrwxrwx   1 root     root            6  Dec 16 01:49 lib/keymaps/31.map -> pt.map
lrwxrwxrwx   1 root     root            6  Dec 16 01:49 lib/keymaps/32.map -> ro.map
lrwxrwxrwx   1 root     root            6  Dec 16 01:49 lib/keymaps/33.map -> ru.map
lrwxrwxrwx   1 root     root            6  Dec 16 01:49 lib/keymaps/34.map -> se.map
lrwxrwxrwx   1 root     root            6  Dec 16 01:49 lib/keymaps/35.map -> sf.map
lrwxrwxrwx   1 root     root            6  Dec 16 01:49 lib/keymaps/36.map -> sg.map
lrwxrwxrwx   1 root     root            8  Dec 16 01:49 lib/keymaps/37.map -> sk-y.map
lrwxrwxrwx   1 root     root            8  Dec 16 01:49 lib/keymaps/38.map -> sk-z.map
lrwxrwxrwx   1 root     root           11  Dec 16 01:49 lib/keymaps/39.map -> slovene.map
lrwxrwxrwx   1 root     root            8  Dec 16 01:49 lib/keymaps/3.map -> bepo.map
lrwxrwxrwx   1 root     root            7  Dec 16 01:49 lib/keymaps/40.map -> trf.map
lrwxrwxrwx   1 root     root            6  Dec 16 01:49 lib/keymaps/41.map -> ua.map
lrwxrwxrwx   1 root     root            6  Dec 16 01:49 lib/keymaps/42.map -> uk.map
lrwxrwxrwx   1 root     root            6  Dec 16 01:49 lib/keymaps/43.map -> us.map
lrwxrwxrwx   1 root     root           10  Dec 16 01:49 lib/keymaps/44.map -> wangbe.map
lrwxrwxrwx   1 root     root            6  Dec 16 01:49 lib/keymaps/4.map -> bg.map
lrwxrwxrwx   1 root     root            8  Dec 16 01:49 lib/keymaps/5.map -> br-a.map
lrwxrwxrwx   1 root     root            8  Dec 16 01:49 lib/keymaps/6.map -> br-l.map
lrwxrwxrwx   1 root     root            6  Dec 16 01:49 lib/keymaps/7.map -> by.map
lrwxrwxrwx   1 root     root            6  Dec 16 01:49 lib/keymaps/8.map -> cf.map
lrwxrwxrwx   1 root     root           11  Dec 16 01:49 lib/keymaps/9.map -> colemak.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/azerty.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/be.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/bepo.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/bg.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/br-a.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/br-l.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/by.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/cf.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/colemak.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/croat.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/cz.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/de.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/dk.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/dvorak.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/es.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/et.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/fi.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/fr.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/gr.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/hu.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/il.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/is.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/it.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/jp.map
-rw-r--r--   1 root     root          518  Dec 16 01:49 lib/keymaps/keymapList
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/la.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/lt.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/mk.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/nl.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/no.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/pl.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/pt.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/ro.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/ru.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/se.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/sf.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/sg.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/sk-y.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/sk-z.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/slovene.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/trf.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/ua.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/uk.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/us.map
-rw-r--r--   1 root     root         2823  Dec 16 01:49 lib/keymaps/wangbe.map
-rwxr-xr-x   1 root     root       169376  Dec 16 01:49 lib/ld-linux-x86-64.so.2
-rwxr-xr-x   1 root     root      1913648  Dec 16 01:49 lib/libc.so.6
-rwxr-xr-x   1 root     root        26800  Dec 16 01:49 lib/libnss_dns.so
lrwxrwxrwx   1 root     root           13  Dec 16 01:49 lib/libnss_dns.so.2 -> libnss_dns.so
-rwxr-xr-x   1 root     root        51536  Dec 16 01:49 lib/libnss_files.so
lrwxrwxrwx   1 root     root           15  Dec 16 01:49 lib/libnss_files.so.2 -> libnss_files.so
-rwxr-xr-x   1 root     root        88736  Dec 16 01:49 lib/libresolv.so.2
drwxr-xr-x   3 root     root            0  Dec 16 01:49 lib/modules
drwxr-xr-x   3 root     root            0  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2
drwxr-xr-x   5 root     root            0  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/kernel
drwxr-xr-x   2 root     root            0  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/kernel/crypto
-rw-r--r--   1 root     root         7152  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/kernel/crypto/algif_rng.ko
drwxr-xr-x   6 root     root            0  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/kernel/drivers
drwxr-xr-x   3 root     root            0  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/kernel/drivers/hid
drwxr-xr-x   2 root     root            0  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/kernel/drivers/hid/usbhid
-rw-r--r--   1 root     root        66448  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/kernel/drivers/hid/usbhid/usbhid.ko
drwxr-xr-x   2 root     root            0  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/kernel/drivers/md
-rw-r--r--   1 root     root        19024  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/kernel/drivers/md/dm-log.ko
-rw-r--r--   1 root     root        27256  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/kernel/drivers/md/dm-mirror.ko
-rw-r--r--   1 root     root        49200  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/kernel/drivers/md/dm-raid.ko
-rw-r--r--   1 root     root        16536  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/kernel/drivers/md/dm-region-hash.ko
drwxr-xr-x   3 root     root            0  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/kernel/drivers/net
drwxr-xr-x   2 root     root            0  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/kernel/drivers/net/intel
drwxr-xr-x   2 root     root            0  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/kernel/drivers/net/intel/e1000
-rw-r--r--   1 root     root        70480  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/kernel/drivers/net/intel/e1000/e1000.ko
drwxr-xr-x   6 root     root            0  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/kernel/drivers/usb
drwxr-xr-x   2 root     root            0  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/kernel/drivers/usb/common
-rw-r--r--   1 root     root         6584  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/kernel/drivers/usb/common/usb-common.ko
drwxr-xr-x   2 root     root            0  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/kernel/drivers/usb/core
-rw-r--r--   1 root     root       308944  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/kernel/drivers/usb/core/usbcore.ko
drwxr-xr-x   2 root     root            0  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/kernel/drivers/usb/host
-rw-r--r--   1 root     root        60416  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/kernel/drivers/usb/host/ehci-hcd.ko
-rw-r--r--   1 root     root        10616  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/kernel/drivers/usb/host/ehci-pci.ko
-rw-r--r--   1 root     root        46072  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/kernel/drivers/usb/host/ohci-hcd.ko
-rw-r--r--   1 root     root        35896  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/kernel/drivers/usb/host/uhci-hcd.ko
drwxr-xr-x   2 root     root            0  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/kernel/drivers/usb/storage
-rw-r--r--   1 root     root       126512  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/kernel/drivers/usb/storage/usb-storage.ko
drwxr-xr-x   3 root     root            0  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/kernel/fs
drwxr-xr-x   2 root     root            0  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/kernel/fs/fat
-rw-r--r--   1 root     root        95664  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/kernel/fs/fat/fat.ko
-rw-r--r--   1 root     root        16104  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/kernel/fs/fat/msdos.ko
-rw-r--r--   1 root     root        32434  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/modules.alias
-rw-r--r--   1 root     root        42356  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/modules.alias.bin
-rw-r--r--   1 root     root         8132  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/modules.builtin
-rw-r--r--   1 root     root        11529  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/modules.builtin.bin
-rw-r--r--   1 root     root        15196  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/modules.dep
-rw-r--r--   1 root     root        23748  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/modules.dep.bin
-rw-r--r--   1 root     root            0  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/modules.devname
-rw-r--r--   1 root     root         8320  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/modules.order
-rw-r--r--   1 root     root          117  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/modules.softdep
-rw-r--r--   1 root     root        24707  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/modules.symbols
-rw-r--r--   1 root     root        29469  Dec 16 01:49 lib/modules/5.3.14-gentoo-r1-x86_64-wifitest2/modules.symbols.bin
lrwxrwxrwx   1 root     root            4  Dec 16 01:49 linuxrc -> init
drwxr-xr-x   2 root     root            0  Dec 16 01:49 mnt
drwxr-xr-x   2 root     root            0  Dec 16 01:49 proc
drwxr-xr-x   3 root     root            0  Dec 16 01:49 root
drwx------   2 root     root            0  Dec 16 01:49 root/.ssh
-rw-------   1 root     root          742  Dec 16 01:49 root/.ssh/authorized_keys
drwxr-xr-x   2 root     root            0  Dec 16 01:49 run
-rw-r--r--   1 root     root            0  Dec 16 01:49 run/utmp
drwxr-xr-x   2 root     root            0  Dec 16 01:49 sbin
-rwxr-xr-x   1 root     root      1105720  Dec 16 01:49 sbin/blkid
-rwxr-xr-x   1 root     root      2813384  Dec 16 01:49 sbin/cryptsetup
lrwxrwxrwx   1 root     root           19  Dec 16 01:49 sbin/dmsetup -> ../usr/sbin/dmsetup
lrwxrwxrwx   1 root     root           19  Dec 16 01:49 sbin/dmstats -> ../usr/sbin/dmstats
lrwxrwxrwx   1 root     root            7  Dec 16 01:49 sbin/init -> ../init
lrwxrwxrwx   1 root     root           15  Dec 16 01:49 sbin/lvm -> ../usr/sbin/lvm
-rwxr-xr-x   1 root     root      1510360  Dec 16 01:49 sbin/mdadm
-rwxr-xr-x   1 root     root      1267904  Dec 16 01:49 sbin/mdmon
drwxr-xr-x   2 root     root            0  Dec 16 01:49 sys
drwxrwxrwt   2 root     root            0  Dec 16 01:49 tmp
drwxr-xr-x   6 root     root            0  Dec 16 01:49 usr
drwxr-xr-x   2 root     root            0  Dec 16 01:49 usr/bin
lrwxrwxrwx   1 root     root           13  Dec 16 01:49 usr/bin/dropbearconvert -> dropbearmulti
lrwxrwxrwx   1 root     root           13  Dec 16 01:49 usr/bin/dropbearkey -> dropbearmulti
-rwxr-xr-x   1 root     root      1365144  Dec 16 01:49 usr/bin/dropbearmulti
-rwxr-xr-x   1 root     root         2881  Dec 16 01:49 usr/bin/login-remote.sh
lrwxrwxrwx   1 root     root           13  Dec 16 01:49 usr/bin/scp -> dropbearmulti
drwxr-xr-x   2 root     root            0  Dec 16 01:49 usr/lib
lrwxrwxrwx   1 root     root            3  Dec 16 01:49 usr/lib32 -> lib
lrwxrwxrwx   1 root     root            3  Dec 16 01:49 usr/lib64 -> lib
drwxr-xr-x   2 root     root            0  Dec 16 01:49 usr/sbin
lrwxrwxrwx   1 root     root           11  Dec 16 01:49 usr/sbin/cache_check -> pdata_tools
lrwxrwxrwx   1 root     root           11  Dec 16 01:49 usr/sbin/cache_dump -> pdata_tools
lrwxrwxrwx   1 root     root           11  Dec 16 01:49 usr/sbin/cache_metadata_size -> pdata_tools
lrwxrwxrwx   1 root     root           11  Dec 16 01:49 usr/sbin/cache_repair -> pdata_tools
lrwxrwxrwx   1 root     root           11  Dec 16 01:49 usr/sbin/cache_restore -> pdata_tools
lrwxrwxrwx   1 root     root           11  Dec 16 01:49 usr/sbin/cache_writeback -> pdata_tools
-rwxr-xr-x   1 root     root      1262952  Dec 16 01:49 usr/sbin/dmsetup
lrwxrwxrwx   1 root     root            7  Dec 16 01:49 usr/sbin/dmstats -> dmsetup
lrwxrwxrwx   1 root     root           20  Dec 16 01:49 usr/sbin/dropbear -> ../bin/dropbearmulti
lrwxrwxrwx   1 root     root           11  Dec 16 01:49 usr/sbin/era_check -> pdata_tools
lrwxrwxrwx   1 root     root           11  Dec 16 01:49 usr/sbin/era_dump -> pdata_tools
lrwxrwxrwx   1 root     root           11  Dec 16 01:49 usr/sbin/era_invalidate -> pdata_tools
lrwxrwxrwx   1 root     root           11  Dec 16 01:49 usr/sbin/era_restore -> pdata_tools
-rwxr-xr-x   1 root     root      2905416  Dec 16 01:49 usr/sbin/lvm
-rwxr-xr-x   1 root     root      3061192  Dec 16 01:49 usr/sbin/pdata_tools
-rwxr-xr-x   1 root     root          609  Dec 16 01:49 usr/sbin/resume-boot
lrwxrwxrwx   1 root     root           11  Dec 16 01:49 usr/sbin/thin_check -> pdata_tools
lrwxrwxrwx   1 root     root           11  Dec 16 01:49 usr/sbin/thin_delta -> pdata_tools
lrwxrwxrwx   1 root     root           11  Dec 16 01:49 usr/sbin/thin_dump -> pdata_tools
lrwxrwxrwx   1 root     root           11  Dec 16 01:49 usr/sbin/thin_ls -> pdata_tools
lrwxrwxrwx   1 root     root           11  Dec 16 01:49 usr/sbin/thin_metadata_size -> pdata_tools
lrwxrwxrwx   1 root     root           11  Dec 16 01:49 usr/sbin/thin_repair -> pdata_tools
lrwxrwxrwx   1 root     root           11  Dec 16 01:49 usr/sbin/thin_restore -> pdata_tools
lrwxrwxrwx   1 root     root           11  Dec 16 01:49 usr/sbin/thin_rmap -> pdata_tools
lrwxrwxrwx   1 root     root           11  Dec 16 01:49 usr/sbin/thin_trim -> pdata_tools
-rwxr-xr-x   1 root     root         3076  Dec 16 01:49 usr/sbin/unlock-luks
drwxr-xr-x   3 root     root            0  Dec 16 01:49 usr/share
drwxr-xr-x   2 root     root            0  Dec 16 01:49 usr/share/udhcpc
-rwxr-xr-x   1 root     root         1098  Dec 16 01:49 usr/share/udhcpc/default.script
drwxr-xr-x   3 root     root            0  Dec 16 01:49 var
drwxr-xr-x   2 root     root            0  Dec 16 01:49 var/log
-rw-r--r--   1 root     root            0  Dec 16 01:49 var/log/lastlog
-rw-r--r--   1 root     root            0  Dec 16 01:49 var/log/wtmp
lrwxrwxrwx   1 root     root            6  Dec 16 01:49 var/run -> ../run
========================================================================

上の出力は、Intel NIC のための e1000.ko ファイル、dropbear 実行可能ファイル (usr/bin/dropbearmulti)、そして cryptsetup (sbin/cryptsetup) 実行可能ファイルが、initramfs ファイルに埋め込まれていることを示しています。

手動展開

生成された initramfs を展開して内容を確認するには:

root #mkdir /tmp/initramfs
root #cd /tmp/initramfs
root #xzcat /boot/initramfs-5.3.14-gentoo-r1-x86_64-wifitest2.img | cpio -idmv
root #ls -l sbin/cryptsetup
-rwxr-xr-x   1 root     root      2813384  Dec 16 01:49 sbin/cryptsetup
メモ
CPU マイクロコードの更新が initramfs に埋め込まれている場合、手動展開は困難になるでしょう。

マイクロコードのロード

マイクロコード (ucode) の更新のためには、カーネルは (早期) マイクロコードローディングをサポートする必要があり、マイクロコードの更新がブート時の早期に存在している必要があります。さらなる詳細については Microcode の記事を参照してください。

カーネルでのマイクロコードローディングのサポート

デフォルトでは、genkernel はカーネルでのマイクロコードローディングのサポートを、AMD と Intel プロセッサの両方に対して有効化するでしょう。この挙動は /etc/genkernel.conf 内の MICROCODE オプションを通じて、または呼び出し時に --microcode=(no|all|amd|intel コマンドライン引数を使用することで、制御することができます。

マイクロコードの更新を initramfs に埋め込む

マイクロコード (ucode) の更新を initramfs に埋め込むには、/etc/genkernel.confMICROCODE_INITRAMFS を有効化するか、実行時にコマンドライン引数 --microcode-initramfs を渡す必要があります。これにより genkernel は選択されたプロセッサ (上の --microcode オプションを参照してください) 用のマイクロコードを initramfs の先頭に追加します。Intel プロセッサに対しては split-ucode USE フラグ付きの sys-firmware/intel-microcode、AMD プロセッサに対しては sys-kernel/linux-firmware がインストールされている必要があります。

メモ
マイクロコードの更新を initramfs に埋め込むテクニックは、現代のシステムではブートローダ (sys-boot/grub 等) を使用する方法によって取って代わられ、非推奨になっています。ブートローダを使用する方法では、複数の initramfs ファイルをロードすることもできます。GRUB または他の現代的なブートローダを使用している場合は、Intel プロセッサ向けには sys-firmware/intel-microcode を、AMD プロセッサ向けには sys-kernel/linux-firmware をインストールすることが推奨されます。いずれも initramfs USE フラグを有効化する必要があります。ブートローダに、genkernel の initramfs に加えて、/boot/amd-uc.img および/または /boot/intel-uc.img をロードさせてください。これにより、カーネル/initramfs の更新とは独立して CPU マイクロコードの更新が有効化されます。

ファームウェアのロード

Specific firmware files can easily be added to genkernel's automatically generated initramfs by listing them (with their relative paths) in variable FIRMWARE_FILES in /etc/genkernel.conf. When sys-kernel/genkernel is installed with USE="firmware" it will prefer firmware files from /lib/firmware.

ファイル /etc/genkernel.confIncluding firmware in the initramfs
# Add firmware(s) to initramfs
FIRMWARE="yes"
 
# Specify directory to pull from
FIRMWARE_DIR="/lib/firmware"
 
# Specify a comma-separated list of firmware files or directories to include,
# relative to FIRMWARE_DIR.  If empty or unset, the full contents of 
# FIRMWARE_DIR will be included (if FIRMWARE option above is set to YES).
FIRMWARE_FILES="<comma-separated list of firmware files here>"

In case sys-kernel/gentoo-sources is installed with USE="experimental" and the kernel is configured with CONFIG_GENTOO_PRINT_FIRMWARE_INFO=y, the following command gets a comma-separated list of all currently loaded firmware files for the use in the FIRMWARE_FILES variable from /etc/genkernel.conf as illustrated above (the output is just an example):

root #dmesg -t | grep '^Loading firmware*' | sed 's/^Loading\sfirmware:\s//' | echo $(cat) | tr ' ' ','
amdgpu/green_sardine_sdma.bin,amdgpu/green_sardine_asd.bin,amdgpu/green_sardine_ta.bin,amdgpu/green_sardine_pfp.bin,amdgpu/green_sardine_me.bin,amdgpu/green_sardine_ce.bin,amdgpu/green_sardine_rlc.bin,amdgpu/green_sardine_mec.bin,amdgpu/green_sardine_dmcub.bin,amdgpu/green_sardine_vcn.bin,regulatory.db,regulatory.db.p7s,rtw89/rtw8852a_fw.bin,rtl_bt/rtl8852au_fw.bin,rtl_bt/rtl8852au_config.bin,rtl_nic/rtl8168h-2.fw

It is also possible to incorporate the firmware into the kernel image directly, but be aware that CONFIG_EXTRA_FIRMWARE in the kernel configuration file .config (normally found in /usr/src/linux) requires a space-separated list (output example):

root #dmesg -t | grep '^Loading firmware*' | sed 's/^Loading\sfirmware:\s//' | echo $(cat)
amdgpu/green_sardine_sdma.bin amdgpu/green_sardine_asd.bin amdgpu/green_sardine_ta.bin amdgpu/green_sardine_pfp.bin amdgpu/green_sardine_me.bin amdgpu/green_sardine_ce.bin amdgpu/green_sardine_rlc.bin amdgpu/green_sardine_mec.bin amdgpu/green_sardine_dmcub.bin amdgpu/green_sardine_vcn.bin regulatory.db regulatory.db.p7s rtw89/rtw8852a_fw.bin rtl_bt/rtl8852au_fw.bin rtl_bt/rtl8852au_config.bin rtl_nic/rtl8168h-2.fw
メモ
Such a list will only be complete if the drivers successfully load all the required firmware(s): In case a driver requires more than one firmware file but fails loading the first one, only this will be listed and thereby other required firmware filenames will be missing. A recommended procedure to find all required firmware files is to compile the respective drivers as modules first, M in the kernel configuration, and to not have them included in the initramfs. This way they will be loaded after the switch to the real / (root) directory, where all firmware files will be available from sys-kernel/linux-firmware (and others) under /lib/firmware. When a system boots successfully with this method, running the above command will gather a complete list of the required firmware files. They may then be included in the initramfs (or the kernel itself), allowing for the drivers to be compiled directly into the kernel, * in the kernel configuration, or to include the drivers as kernel modules in the initramfs as well. In both cases loading the modules will be earlier and it will be successful with the availability of the firmware files in the initramfs, which must be loaded alongside the kernel e.g. using GRUB.

Remote rescue shell

genkernel can embed the net-misc/dropbear SSH daemon into the initramfs which will allow fixing certain things on boot remotely when initramfs is at least able to load. The most common used feature will be remote unlock capability for LUKS-encrypted root or swap devices or ZFS volumes.

Pre-requirement for SSH daemon support in initramfs

A authorized_keys file must exist before genkernel will be invoked. By default, genkernel will look for /etc/dropbear/authorized_keys. Command-line argument --ssh-authorized-keys-file=/path/to/custom/authorized_keys or genkernel configuration option SSH_AUTHORIZED_KEYS_FILE can be used to alter default value.

ヒント
Create /etc/dropbear/authorized_keys as a symlink to /root/.ssh/authorized_keys for example to keep root access and remote rescue shell access in sync!

Adding SSH support to initramfs

To embed SSH daemon into genkernel's initramfs, run genkernel with --ssh command-line argument or set SSH="yes" in genkernel configuration file. Needless to mention that this feature will require working network at boot. The following example will just (re-)build initramfs with SSH daemon embedded:

root #genkernel --ssh initramfs
* Gentoo Linux Genkernel; Version 4.0.1
* Using genkernel configuration from '/etc/genkernel.conf' ...
* Running with options: --ssh initramfs

* Working with Linux kernel 5.3.14-gentoo-r1-x86_64 for x86_64
* Using kernel config file '/etc/kernels/kernel-config-5.3.14-gentoo-r1-x86_64' ...

* initramfs: >> Initializing ...
*         >> Appending devices cpio data ...
*         >> Appending base_layout cpio data ...
*         >> Appending auxilary cpio data ...
*         >> Appending blkid cpio data ...
*         >> Appending busybox cpio data ...
*         >> Appending dropbear cpio data ...
=================================================================
This initramfs' sshd will use the following host key(s):
256 MD5:a5:13:09:90:5b:f6:a1:95:49:9f:87:d9:fa:e5:d8:02 (ECDSA)
256 SHA256:5dxNGEOwH9hvX4+sV4WtzRV/9m8/hrhgnNtTplZf5x8 (ECDSA)
2048 MD5:1d:e6:cc:ce:c8:96:a0:73:3e:4c:2a:56:ce:b9:10:26 (RSA)
2048 SHA256:V4WrMKhfVSxSeW3XIbW8dSaAmXiwN6jiMA/geNKLcqA (RSA)
=================================================================
*         >> Appending modprobed cpio data ...
*         >> Appending modules cpio data ...
*         >> Appending linker cpio data ...
*         >> Deduping cpio ...
*         >> Pre-generating initramfs' /etc/ld.so.cache ...
*         >> Compressing cpio data (.xz) ...
*
* You will find the initramfs in '/boot/initramfs-5.3.14-gentoo-r1-x86_64.img'.

* WARNING... WARNING... WARNING...
* Additional kernel parameters that *may* be required to boot properly:
* - Add "dosshd" to start SSH daemon in initramfs

* Do NOT report kernel bugs as genkernel bugs unless your bug
* is about the default genkernel configuration...
*
* Make sure you have the latest ~arch genkernel before reporting bugs.
メモ
By default, genkernel will generate own, dedicated SSH host keys for any missing supported key algorithm for embedded SSH daemon. This will allow to differentiate between real system's SSH daemon and initramfs' SSH daemon. To use host's SSH host keys instead or generate new keys at runtime on each boot use --ssh-host-keys command-line option and see genkernel's man page for more details.

Enabling SSH daemon on boot

Just adding SSH daemon to initramfs is not enough. Because exposing any network service could be a security risk, this feature must be enabled via the kernel command-line argument dosshd! See Configure Network for how to configure network in genkernel.

Remote unlock

There are two possibilities to unlock LUKS-encrypted root and/or swap volume: A manual way, through an SSH connection, run a command and will get prompted for passphrase(s) or an automatic way where user passes passphrase through SSH as command.

メモ
This will require a kernel/initramfs generated with --luks command-line argument and kernel must be booted with crypt_root (and/or crypt_swap) kernel command-line argument. ZFS user must generate kernel/initramfs with --zfs command-line argument and kernel must be booted with dozfs kernel command-line argument.
Manual unlock

Connect to the remote system through SSH and run the following commands:

user $ssh root@remote-system-running-genkernel-initramfs-with-dosshd
>> Welcome to Genkernel 4.0.1 (2019-12-16 22:34:14 UTC) remote rescue shell!
>> ...running Linux kernel 5.3.14-gentoo-r1-x86_64

>> The lockfile '/tmp/remote-rescueshell.lock' was created.
>> In order to resume boot process, run 'resume-boot'.
>> Be aware that it will kill your connection which means
>> you will no longer be able to work in this shell.
>> To remote unlock LUKS-encrypted root device, run 'unlock-luks root'.

remote rescueshell ~ # unlock-luks root
>> Detected real_root as a md device. Setting up the device node ...
Enter passphrase for /dev/md126:
>> LUKS device /dev/md126 opened
remote rescueshell ~ # resume-boot
>> Resuming boot process ...
メモ
In this example, system was booted with just crypt_root= set in kernel command-line. In case system was booted with crypt_swap= there will be an additional prompt regarding how to unlock swap. ZFS user will get prompted to use unlock-zfs command instead.
Automatic unlock

It's basically the same like manual unlock just without the need to manually run resume-boot. In case user has both, encrypted root and swap volume, user must unlock swap volume first:

user $cat /path/to/secret.key/on/local/disk | ssh root@remote-system-running-genkernel-initramfs-with-dosshd post root
>> Detected real_root as a md device. Setting up the device node ...
>> LUKS device /dev/md126 opened
>> Resuming boot process ...
メモ
Automatic unlock is not available for ZFS users.

ネットワークから起動する

インストールCDから

genkernel ユーティリティは、ネットワークブートあるいはネットブートに対応したカーネルと initrd イメージをビルドすることができます。すべてうまく行けば、最近のコンピュータ上でインストール CD が提供する環境をネットブートすることができるはずです。

秘密は genkernel の linuxrc スクリプトにあります。これは NFS を使用してインストール CD のネットマウントを試みます。そこから、インストール CD の init スクリプトが制御を引き継ぎ、あたかもローカルに CD があるかのように動作します。

ネットブートをサポートしたカーネルとinitramfsを構築

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

警告
genkernel でのネットブートのサポートは実験的なものであり、バグがあるかもしれません。

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

カーネル さまざまな NIC ドライバをサポートするように 3.x.x シリーズカーネルを構成する
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.

カーネル DHCP をサポートするように 3.x.x シリーズカーネルを構成する
Device Drivers --->
   Networking Support --->
      Networking options
         [*] TCP/IP networking--->
         [*]   IP: kernel level autoconfiguration
         [*]     IP: DHCP support

これらのオプションは、起動時に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.

カーネル SquashFS をサポートするようにカーネルを構成する
File systems--->
   Miscellaneous filesystems --->
      [*] SquashFS 2.X - Squashed file system support

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

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

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

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

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

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 ファイルがブートイメージです。

最後に、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 /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

Now copy the modules.tar.gz file into /add:

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

DHCP setup

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:

ファイル /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 instructions

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

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

ファイル pxelinux.cfg/defaultデフォルトのエントリ
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

Booting a 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.

ファイル /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
シングルユーザーモードでブートする

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

ファイル /boot/grub/grub.confシングルユーザーモードでブートする
# 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

クロスコンパイルサポート

To build kernel and/or initramfs for a different platform as genkernel is being executed on, kernel/initramfs must be cross-compiled.

root #genkernel --mdadm --no-install --cross-compile=aarch64-linux-gnu all

The above command causes genkernel to create a kernel supporting MD raid and embed mdadm into initramfs (--mdadm), both kernel and initramfs will have to be manually installed (--no-install). The kernel and programs embedded into initramfs will run on arm64 (--cross-compile=aarch64-linux-gnu).

--cross-compile=<target triplet>
Target triple (i.e. aarch64-linux-gnu) to build for. Only needed when the system running genkernel has a different architecture like the system which should boot the created kernel/initramfs.
ヒント
The recommended way to create a cross-compile environment is using sys-devel/crossdev. See the how to create a cross-compile environment article for more details.

Initramfs kernel command-line parameters

メモ
The following parameter list is just an excerpt. Always check man genkernel from the version you are using.
root=<...>
Specifies the device node of the root filesystem to mount. I.e. root=/dev/sda3, root=UUID=a1e5968c-bd1b-41ee-bf08-2d0ed376fa83.
cdroot
This attempts to load livecd.squashfs and is used for loading live media.
crypt_root=<...>
This specifies the device encrypted by LUKS, which contains the root filesystem to mount. Supports same syntax like root kernel command-line parameter from above.
メモ
Will require that at least initramfs was built with --luks option set.
crypt_swap=<...>
This specifies the swap device encrypted by LUKS. For more details please see crypt_root kernel command-line parameter from above.
root_trim=(yes|no)
Enables TRIM support for a LUKS-based root device.
メモ
Will require that at least initramfs was built with --luks option set and is only useful for flash-based volumes.
ip=<dhcp,addr/cidr>
Normally used to tell the kernel that it should start a network interface which can be specified using gk.net.iface kernel parameter. By default, dhcp will be used. You can set a specific IP address using addr/CIDR notation, i.e. 1.2.3.4/24.
gk.net.dhcp.retries=<...>
By default we will send up to 3 DHCP discovery requests.
gk.net.iface=<interface,macaddr>
By default we will use the interface named eth0. Use this kernel parameter to specify another interface.
You can also specify a MAC address (00:00:00:00:00:00 format) instead of an interface name.
gk.net.gw=<...>
Optional gateway. If ip is set to dhcp, this kernel parameter will be ignored.
gk.net.routes=<...>
Optional additional routes. If ip is set to dhcp, this kernel parameter will be ignored.
gk.net.timeout.dad=<...>
By default we will wait up to 10 seconds for IPv6's DAD to complete. At the moment, we only wait for DAD while bringing down an interface to prevent a race condition.
gk.net.timeout.deconfiguration=<...>
By default we will wait up to 10 seconds while bringing down an interface to prevent a race condition.
gk.net.timeout.dhcp=<...>
By default we will wait up to 10 seconds for a DHCP server reply.
gk.net.timeout.interface=<...>
By default we will wait up to 10 seconds for interface to show up.
gk.prompt.timeout=<...>
By default a prompt within genkernel initramfs like shown when set root could not be found will never timeout. Use this option to set a timeout.
メモ
When dosshd is used, gk.prompt.timeout will be set to 30 seconds when not set. This will allow remote user to provide answer through GK_PROMPT_FILE which is set to /tmp/current_prompt by default.
dosshd
Will bring up an interface and start a SSH daemon within initramfs allowing to remotely unlock encrypted devices or just for debugging purpose. See ip option for how to configure network.
メモ
Will require that initramfs was built at least with --ssh option set.
gk.sshd.port=<...>
By default, sshd will listen on port 22.
gk.sshd.wait=<...>
Wait X seconds after setting up sshd, useful when you want to login (and thus pause boot process) before booting real system.
dolvm
Activate LVM volumes on bootup.
メモ
Will require that initramfs was built at least with --lvm option set.
lvmraid=<...>
Specify RAID devices to set up before the activation of LVM volumes. Implies option dolvm from above.
domdadm (Deprecated in Genkernel 4.2.0, udev rules now control MD assembly)
Scan for RAID arrays on bootup.
メモ
Will require that initramfs was built at least with --mdadm option set.
dozfs[=cache,force]
Scan for bootable ZFS pools on bootup. Optionally use cachefile or force import if necessary or perform both actions.
メモ
Will require that initramfs was built at least with --zfs option set.
gk.log.disabled=<...>
By default, any shown message and external command calls will be logged to /tmp/init.log in initramfs. This boolean option allows you to disable logging for some reason.
gk.log.keep=<...>
When set to a boolean value, genkernel will preserve /tmp/init.log, see above, and copy file to /genkernel-boot.log on root device (see root or real_root kernel command-line parameter above). You can also set your own file like /root/my-genkernel-boot.log to copy log to a custom path.
メモ
The default file /genkernel-boot.log on root was chosen because genkernel's initramfs will only mount root filesystem by default. If you want to store the log file in /var/log/genkernel-boot.log for example make sure that this mountpoint is accessible, see /etc/initramfs.mounts.
gk.hw.load-all=<...>
By default, genkernel loads various module groups (nvme, sata, scsi, pata, usb...) until block device specified in root parameter (see above) becomes available. This boolean option can be used to force loading of all module groups regardless whether root device is already available when set to yes.

FAQ

systemd ベースのシステムでも genkernel を使えますか?

はい。

Genkernel? Genkernel-next? Dracut?

メモ
sys-kernel/genkernel-next は 2020 年 8 月 20 日以降 Gentoo リポジトリから削除されています。

Gentoo is about choices. sys-kernel/genkernel-next was created as fork of sys-kernel/genkernel when genkernel development was stuck, booting a systemd-based system using kernel/initramfs created with sys-kernel/genkernel was a problem (systemd support in sys-kernel/genkernel is fixed for quite some time) and some developers wanted support for things like sys-boot/plymouth which requires sys-fs/udev which was not and still is not compatible with genkernel's main idea (see "Note" right at the beginning of this article). While the name suggests that sys-kernel/genkernel-next is or will be the successor of sys-kernel/genkernel, it is just misleading: Since 2013 there are some requests to merge genkernel-next back into genkernel but the process became stuck. Since the release of sys-kernel/genkernel-4 which changed a lot and the fact that there was no progress in sys-kernel/genkernel-next development since 2018, it's now very unlikely that genkernel-next will ever merge back into genkernel.

sys-kernel/dracut in comparison to sys-kernel/genkernel is just a generic tool for creating an initramfs. It cannot help you with creating a kernel like genkernel does. I.e. while both, genkernel and dracut supports booting from LUKS-encrypted root volume, only genkernel will ensure that kernel will have all required options set. It's also worthwhile to mention that genkernel will compile most packages (LVM, cryptsetup, mdadm, sshd...) used in initramfs on its own whereas dracut will copy binaries from host system which can be a problem for some setups. That's also the reason why you can use genkernel to create kernel/initramfs for another system (cross-compile) which isn't supported in dracut or genkernel-next.

How do I create a separate kernel/initramfs to test something?

root #genkernel --kernel-config=/proc/config.gz --kernel-append-localversion=-test42 --menuconfig all

The above command causes genkernel to build a new kernel and initramfs (all) based on config from current running kernel (--kernel-config=/proc/config.gz), invoke menuconfig (--menuconfig) allowing user to adjust configuration and will append -test42 to kernel's LOCALVERSION variable (--kernel-append-localversion=-test42) which will affect naming of kernel image, modules dir and initramfs by default.

How do I rebuild external modules (such as xtables-addons, nvidia-drivers...) for new kernel?

By default, genkernel will call emerge @module-rebuild when building a kernel to ensure that out-of-tree modules installed through the package manager are still present in new/rebuilt kernel. This feature can be toggled via --[no-]module-rebuild command-line argument or MODULEREBUILD in /etc/genkernel.conf.

How do I run additional commands after kernel has been built?

Genkernel provides a callback for that (before version 4, callback was used to rebuild external modules). See CMD_CALLBACK in /etc/genkernel.conf for more details.

How do I use ccache or distcc with genkernel?

Set up ccache or distcc the normal way like you would do for sys-apps/portage. Now you set --kernel-cc command-line parameter or adjust KERNEL_CC in /etc/genkernel.conf for the tool you want to use. Do the same for UTILS_CC (--utils-cc) and UTILS_CXX (--utils-cxx).

ERROR: compile_kernel(): compile_generic() failed to compile the "bzImage" target!

Check /var/log/genkernel.log first. In most cases, a root cause will appear like:

ファイル /var/log/genkernel.log
[...]
  AR      drivers/usb/built-in.a
  AR      drivers/built-in.a
  GEN     .version
  CHK     include/generated/compile.h
  AR      built-in.a
  LD      vmlinux.o
  MODPOST vmlinux.o
ld: .tmp_vmlinux1: final close failed: No space left on device
make: *** [Makefile:1032: vmlinux] Error 1
 
* ERROR: compile_kernel(): compile_generic() failed to compile the "bzImage" target!
* Please consult '/var/log/genkernel.log' for more information and any
* errors that were reported above.
*
* Report any genkernel bugs to bugs.gentoo.org and
* assign your bug to genkernel@gentoo.org. Please include
* as much information as you can in your bug report; attaching
* '/var/log/genkernel.log' so that your issue can be dealt with effectively.
*
* Please do *not* report kernel compilation failures as genkernel bugs!
*
 
* mount: >> Boot partition state on '/boot' was not changed; Skipping restore boot partition state ...
>>> Ended on: 2019-12-16 02:30:19 (after 0 days 0 hours 07 minutes 49 seconds)
</pre>

In other words: The system has run out of disk space (No space left on device) during compilation.

To guard against problems like this set CHECK_FREE_DISK_SPACE_BOOTDIR=50 and CHECK_FREE_DISK_SPACE_KERNELOUTPUTDIR=4000 in /etc/genkernel.conf in which case genkernel would fail early with a message like

root #genkernel --kernel-config=/proc/config.gz all
* Gentoo Linux Genkernel; Version 4.0.1
* Using genkernel configuration from '/etc/genkernel.conf' ...
* Running with options: --kernel-config=/proc/config.gz all
 
* Working with Linux kernel 4.19.89-gentoo-x86_64 for x86_64
* Using kernel config file '/proc/config.gz' ...
*
* Note: The version above is subject to change (depends on config and status of kernel sources).
* ERROR: 4000 MB free disk space is required in '/usr/src/linux' but only 1026 MB is available!
[...]

カーネルコマンドライン引数の順序は重要ですか?

いいえ。

Help! Something isn't working!

To report a problem, please always provide /var/log/genkernel.log (sometimes it maybe necessary to compress that file before sharing or attaching to bugs) which will help developers a lot. Even if the command is run with --loglevel=1 (default), the logfile will always contain complete output (no need to re-run with logging turned on) which will help developers to understand, reproduce and maybe fix a bug.

関連項目

  • Dracut — an initramfs infrastructure and aims to have as little as possible hard-coded into the initramfs.
  • Kernel — オペレーティングシステムの中核
  • Kernel/ConfigurationLinux カーネル の設定とセットアップを手作業で行う方法
  • Project:Distribution Kernel — aims to maintain sys-kernel/*-kernel packages.
    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, Joshua Saddler (nightmorph), 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.