genkernel
genkernelは、 kernelとinitramfsを自動的にビルドすることができるGentoo製のツールです。 その主な特徴は:
- カーネルソースの設定。
- 圧縮されたカーネルbzImageをビルドし、/bootにコピーします。
- initramfsを作成して/bootにコピーします。
- /bootにシンボリックリンクを作成する。
- 暗号化に関連するファイル、ブートスプラッシュイメージ、追加モジュールなど、カスタムコンテンツをinitramfsに追加する。
- initramfsを圧縮する。
- 新しく作成されたカーネルとinitramfsをブートするようにブートローダーを設定する。
genkernelがカスタムのカーネル設定を“自動で”生成してくれるというのは、ありがちな誤解です。genkernelはカーネルのビルドとinitramfsの生成を自動化しますが、カスタムのカーネル設定は生成せず、アーキテクチャ毎によく使われるサブシステムをサポートした汎用的なカーネル設定を使用します。アーキテクチャのデフォルトは上流リポジトリで見ることができます。アーキテクチャを選んでカーネル設定ファイルを選択してください。
インストール
USE フラグ
USE flags for sys-kernel/genkernel Gentoo automatic kernel building scripts
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です)。
--[no-]menuconfig
- カーネルをビルドする前に、make menuconfigコマンドを実行するかを指定します(このコマンドはインタラクティブな設定メニューを起動します)。
--gconfig
- GTK+ライブラリに依存するカーネル設定ユーティリティを提供します。このオプションはX-windowシステムを利用するため、ほとんどの人にとってこのツールを使うことで、カーネルの設定がより簡単で明瞭だと感じられることが利点です。このオプションを利用するためにはX-windowシステムを必要とするため、コマンドラインでは動作しないことが欠点です。
--xconfig
- QTライブラリに依存するカーネル設定ユーティリティを提供します。このオプションはX-windowシステムを利用するため、ほとんどの人にとってこのツールを使うことで、カーネルの設定がより簡単で明瞭だと感じられることが利点です。このオプションを利用するためにはX-windowシステムを必要とするため、コマンドラインでは動作しないことが欠点です。
--[no-]save-config
- 後の使用に備えて、カーネルの設定を/etc/kernelsディレクトリに保存するかを指定します。
--kernname=NickName
- /bootディレクトリにあるカーネルとinitrdのイメージの名前を変更します。これにより、生成されるイメージはkernel-NickName-versionとinitramfs-NickName-versionとなります。
生成されるシステムに関するオプション
以下のコンフィグレーションオプションは、生成されるカーネルや initrd の仕様を左右します。
--[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 が作成する復号されたデバイスに) 設定してください。 --disklabel
- initrd にディスクラベルのサポートと UUID のサポートを追加します。
--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 what alternative kernel configuration will be used, rather than the default /path/to/sources/.config file.
--module-prefix=/path/to/prefix-directory/
- Specifies a prefix to the directory where kernel modules will be installed (default path is the /lib/modules directory.)
--[no-]clean
- Activates (or deactivates) the make clean command before compiling the kernel. The make clean command removes all object files and dependencies from the kernel's source tree.
--[no-]mrproper
- Activates (or deactivates) the make mrproper command before kernel compilation. Like the make clean command listed above, make mrproper removes all object files and dependencies from the kernel's source tree. However, any previous configuration files (in /path/to/sources/.config or /path/to/sources/.config.old) will also be purged from the kernel's source tree. If it is undesirable that the kernel's .config file keeps disappearing, be sure to disable this option!
--oldconfig
- Issues the make oldconfig command, which attempts to collect configuration information for the system's architecture from a generic script in /usr/share/genkernel. This is a non-interactive process; no user input is entertained. Also, if
--oldconfig
is used in conjunction with--clean
, the latter option is negated, resulting in the activation of the--no-clean
option. --callback="echo hello"
- Calls the specified arguments (echo hello, in this case) after the kernel and the relevant modules have been built, but before building the initrd image. This may be useful when installing external modules in the initrd image by emerging the relevant item(s) with the callback feature, and then redefining a genkernel module group.
--[no-]install
- Activates (or deactivates) the make install command, which installs the new kernel image, configuration file, initrd image and system map onto the boot partition. Any compiled modules will be installed as well. By default genkernel will attempt mount /boot if it is on a separate partition before running the install command.
--no-ramdisk-modules
- Refrains from copying any modules to the genkernel-created initrd image. This option is an exception to the rule about the
no-
prefix; omission of this prefix creates an invalid genkernel option. --all-ramdisk-modules
- Copies all available modules to the genkernel-created initrd image.
--genzimage
- Creates the initrd image, prior to the kernel image (this hack currently applies only to PPC Pegasos systems).
デバッグ用オプション
カーネルのコンパイルプロセス中にデバッグオプションを使用すると、報告された情報の量だけでなく、言ったデータの表示を制御します。
--loglevel=<0|1|2|3|4|5>
- Controls the level of verbosity for information provided by genkernel. The variable
<verblevel>
is an integer between 0 and 5. The level '0' represents minimal output, while '5' provides as much information as possible about genkernel's activities during the kernel compilation process. --logfile=/path/to/output_file
- Ignores the value set by the
--loglevel
option (above) and sends all debugging data produced by genkernel to the specified output file. Outputs to /var/log/genkernel.log by default. --[no-]color
- Activates (or deactivates) colored output of debugging information (reported by genkernel) using escape sequences.
--[no-]debug-cleanup
- Activates (or deactivates) the full post-run cleanup for debug purposes.
アクション
コマンドライン上でgenkernel [options ...] actionによって渡されるアクションは、genkernelにどのアクションを起こさせるかを指定します。以下のアクションが対応しています:
アクション | 説明 |
---|---|
all | 全てのステージをビルドします — initrd、カーネルイメージそしてモジュールです。 |
bzImage | カーネルイメージだけをビルドします。 |
kernel | カーネルイメージとモジュールだけをビルドします。 |
initramfs | initramfs/ramdiskイメージだけをビルドします。 |
ramdisk | initramfs/ramdiskイメージだけをビルドします。 |
設定
実行
genkernelを実行する方法はいくつかありますが、ほとんどのユーザーにお薦めしたい最も簡単な方法は、genkernel allでしょう。はいこれで、ほとんどのシステムでうまくいくような設定がされました。しかし先に述べたように、このアプローチには欠点がないわけではありません。作成されたモジュールのほとんどは平均的なユーザーには無駄であり、その上コンパイル時間も長くなるかもしれません。そこでもっと効果的なアプローチをお教えしましょう。rootユーザーでgenkernelに、幾つかのオプションを渡します:
root #
genkernel --splash --no-install --no-clean --menuconfig all
上の操作によって、genkernel はフレームバッファによるスプラッシュが有効化されたカーネル (--splash
) を作成し、これは手動でインストールする必要があります (--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 16 lrwxrwxrwx 1 root root 19 21 Mar 2013 linux -> linux-3.7.10-gentoo drwxr-xr-x 24 root root 4096 25 Aug 10:39 linux-3.10.7-gentoo drwxr-xr-x 20 root root 4096 21 Apr 19:42 linux-3.7.10-gentoo drwxr-xr-x 21 root root 4096 14 Mar 2013 linux-3.7.9-gentoo
/usr/src/linux シンボリックリンクはいくつかの方法で変更することができます。
symlink
USE フラグがセットされている場合、/usr/src/linux シンボリックリンクは自動的に、新しく emerge されたソースを指すように更新されます。
symlink
USE フラグがセットされていない場合、ユーザは eselect kernel list に続けて eselect kernel set コマンドを使用して、シンボリックリンクの指す先を変更することができます。
genkernel は常に /usr/src/linux シンボリックリンクが指すソース (だけ) を使います。
カーネルコンフィグレーションファイル
アクティブなカーネルソースを使ったカーネルのコンパイルを一度実行したことがある場合、直前のカーネルの bzimage を作成するときに適用されたカーネルコンフィギュレーションを格納する、/etc/kernels ディレクトリの中に、ファイルがあるかもしれません。このファイルは例えば、kernel-config-x86_64-3.7.9-gentoo-r1 のような名前がつけられています。ここで x86_64
はシステムのアーキテクチャで、3.7.9
は使用されたソースのバージョンで、r1
はソースのリリースで、置き換えられているかもしれません。
genkernel --menuconfig all を実行したときに、初期状態のコンフィギュレーションとして使用されるのが、この kernel-config-x86_64-3.7.9-gentoo-r1 ファイルです。
新しいカーネルソースで初めて genkernel を実行している場合、または前回の結果が保存されていない場合、このファイルは usr/share/genkernel/arch/x86_64/kernel-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 grub2? BOOTLOADER="grub2"
- 最初のパラメータは、自身のために語っています。
- 2番目のパラメータは、コンパイルされたカーネル構成を/etc/kernelsに保存するようにgenkernelに指示します
- 最後の 2 つのオプションは、自動的に grub 設定を更新するように genkernel に指示します。実際には、次のことが起こります:
- 以前のカーネルイメージが同名ですでに存在する場合は、その名前の後に .old をつけた名前にリネームされます。それを指す kernel.old シンボリックリンクが自動的に作成されます。
- 新しいカーネルが、/boot 内で同名のカーネルに取って代わります。もしこれが初回のカーネルコンパイルだった場合、新しいカーネルを指す kernel シンボリックリンクが自動的に作成されます。
genkernel --menuconfig all を実行した後、/boot ディレクトリはこのように見えるかもしれません:
user $
ls -al /boot
total 41336 drwxr-xr-x 3 root root 4096 20 avril 17:23 . drwxr-xr-x 24 root root 4096 15 sept. 12:31 .. lrwxrwxrwx 1 root root 1 24 févr. 2013 boot -> . drwxr-xr-x 2 root root 4096 24 févr. 2013 grub lrwxrwxrwx 1 root root 40 20 avril 17:23 initramfs -> initramfs-genkernel-x86_64-3.7.10-gentoo -rw-r--r-- 1 root root 1314412 20 avril 17:23 initramfs-genkernel-x86_64-3.7.10-gentoo -rw-r--r-- 1 root root 1313548 21 mars 2013 initramfs-genkernel-x86_64-3.7.10-gentoo.old -rw-r--r-- 1 root root 1295344 25 févr. 2013 initramfs-genkernel-x86_64-3.7.9-gentoo -rw-r--r-- 1 root root 3310324 25 févr. 2013 initramfs-genkernel-x86_64-3.7.9-gentoo.old lrwxrwxrwx 1 root root 44 20 avril 17:23 initramfs.old -> initramfs-genkernel-x86_64-3.7.10-gentoo.old lrwxrwxrwx 1 root root 37 20 avril 17:23 kernel -> kernel-genkernel-x86_64-3.7.10-gentoo -rw-r--r-- 1 root root 4866656 20 avril 17:23 kernel-genkernel-x86_64-3.7.10-gentoo -rw-r--r-- 1 root root 4866560 21 mars 2013 kernel-genkernel-x86_64-3.7.10-gentoo.old -rw-r--r-- 1 root root 4552288 25 févr. 2013 kernel-genkernel-x86_64-3.7.9-gentoo -rw-r--r-- 1 root root 3400736 25 févr. 2013 kernel-genkernel-x86_64-3.7.9-gentoo.old lrwxrwxrwx 1 root root 41 20 avril 17:23 kernel.old -> kernel-genkernel-x86_64-3.7.10-gentoo.old
ブートローダの設定
新しいカーネルがブート可能でない場合であっても、そのようにブートローダの設定で上記のシンボリックリンクを使用することができ、ユーザーは常にブート古いものにすることができます。
genkernelによって提供されるカーネルとintirdが正しく動作するようにするには、ブートローダの設定ファイルに最小限の情報を指定します。
- カーネルイメージに渡されるカーネルパラメータに、
root=/dev/sdaN
を追加してください。ここで /dev/sdaN はルートパーティションを指しています (N
は、パーティションが存在している場合はパーティション番号です)。 - スプラッシュを使用している場合は、カーネルに渡されるパラメータに
vga=0x317
のよう適切なモード行を追加し、ブートプロセス中に必要になる詳細度に応じてsplash=verbose
またはsplash=silent
も追加してください。 - ブートローダによって必要になる initrd の情報を追加してください。ブートローダに initrd を関知させる方法の詳細については、Gentoo ハンドブックのブートローダ設定の章をお読みください。
以下は grub.conf ファイルがどのようであるかの例です。
/boot/grub/grub.conf
grub.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
作業中のファイルの退避
genkernel のアプリケーションは、新しい変更を自動的にファイルに保存します。以前の変更を退避しておきたい場合は、次の作業を行う必要があります。
- 退避させる最初のファイルは、/etc/kernels/ のカーネル構成ファイルです。カーネルの再コンパイル前にソースが変更されていない場合、このファイルの以前に使用された名前が使用されます。 したがって、以前の構成ファイルを別の名前でコピーすると、新しい構成の開始点としてファイルを使用可能にしたまま、情報を保持するのに役立ちます。
- 次に重要なことは、既に作成されたブート可能なカーネルと initramfs イメージを退避させることです。これを達成するための方法は、状況により異なります:
- 直前にコンパイルされたカーネルがブート可能な場合は、genkernel を実行することでこの古いカーネル (initramfs も同様) のイメージがkernel-genkernel-ARCH-X.Y.Z-gentoo-rx.old にリネームされて、新しい kernel-genkernel-ARCH-X.Y.Z-gentoo-rx が作成されます。つまり、新しいカーネルがブート可能でなかったとしても、ユーザはいつでも古いカーネルをブートすることができるでしょう。
- 直前にコンパイルされたカーネルがブート可能でなく、ブート可能なカーネルをコンパイルできたときからソースが変わっていない場合、genkernel を実行する前に、まず新しいカーネルイメージを削除して、直前にブート可能だったカーネルの .old 接尾辞を取り除いてください。これを行わないと、もし新しくコンパイルされたカーネルがまたしてもブート可能でなかった場合、ブート可能だった kernel-genkernel-ARCH-X.Y.Z-gentoo-rx.old は、ブートできない kernel-genkernel-ARCH-X.Y.Z-gentoo-rx がリネームされることで追い出されてしまい、ユーザにはブート不可能なシステムが残されることになるでしょう。initramfs についても同様の考え方を適用してください。
ソースを変更しながら、以前のカーネル設定を使用して
以前のコンフィギュレーションは、次のように /etc/genkernel.conf 内で MENUCONFIG 変数を通して使用できます:
/etc/genkernel.conf
make menuconfig をセットアップする# Run 'make menuconfig' before compiling this kernel? MENUCONFIG="yes"
genkernel を使用する場合は、例えば kernel-genkernel-ARCH-version-gentoo-rx から kernel-genkernel-ARCH-version-gentoo-r(x+1) に、あるいは kernel-genkernel-ARCH-version-gentoo から kernel-genkernel-ARCH-(version+1)-gentoo にバージョンが上がったときにカーネルのソースコードが変わっていたとしても、make oldconfig を実行する必要はありません。これは、make menuconfig は可能な限り以前のコンフィギュレーションを読み込もうと試みるからです。とはいえ、各オプションと新しいセクションをよく確認しておくことは推奨されることです。
ブートする前に initramfs が必要なユーティリティを含んでいるか確認する
システムを起動する前に、initramfs に必要なユーティリティが含まれていることを確認しておくのが良いかもしれません。例えば、LUKS でブートするときに cryptsetup が欠けていると、カーネルパニックが発生するでしょう。この投稿では、initramfs に cryptsetup が含まれているか確認するために次の手続きを使っています。
root #
mkdir /tmp/initramfs
root #
cd /tmp/initramfs
root #
xzcat kernel-genkernel-x86_64-4.14.65-gentoo | cpio -idmv
root #
ls -l sbin/cryptsetup
-rwxr-xr-x 1 root root 67568 28 d’oct 18:55 sbin/cryptsetup
ネットワークから起動する
インストールCDから
genkernel ユーティリティは、ネットワークブートあるいはネットブートに対応したカーネルと initrd イメージをビルドすることができます。すべてうまく行けば、最近のコンピュータ上でインストール CD が提供する環境をネットブートすることができるはずです。
秘密は genkernel の linuxrc スクリプトにあります。これは NFS を使用してインストール CD のネットマウントを試みます。そこから、インストール CD の init スクリプトが制御を引き継ぎ、あたかもローカルに CD があるかのように動作します。
ネットブートをサポートしたカーネルとinitramfsを構築
カーネルの設定をしながら、ネットブートのサポートを有効にするには、次のオプションが含まれます。:
genkernel でのネットブートのサポートは実験的なものであり、バグがあるかもしれません。
まず、カーネルイメージは、システムのネットワークインタフェースカード(NIC)用のドライバが含まれている必要があります。通常、このようなデバイスのドライバがモジュールとしてコンパイルされます。しかし、そのようなドライバがカーネルイメージにはなくモジュールとして直接コンパイルされていること(ネットブート用)が不可欠です。
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.
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.
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.conf
Sample 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:
ok
boot 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.conf
Enabling 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
トラブルシューティング
compile failed: Kernel not found
This failure can be experienced when attempting to compile a kernel for one architecture with a kernel .config file that has a target of a different architecture than the target. This could be as simple as a machine running an amd64 kernel attempting to compile for a x86 target.
This can be experienced when booting from a x86_64 LiveCD on a system that is capable of operating in 64-bits, however the target to be installed or repaired is 32-bits. After the compilation process begins, genkernel will attempt to automatically detect the architecture for the target based on the currently running kernel. If the currently running kernel is 64-bit, then, unless it is told otherwise, genkernel will presume it should be looking for a 64-bit kernel.
Suppose then that the kernel's .config file has x64 disabled. The make command will execute and the resulting kernel binary will be placed in the associated x86 directory. When genkernel goes to install (move and rename) the kernel it cannot find the kernel because it expected a 64-bit kernel.
The solution to this failure is to set genkernel's --arch-override
option to, in this case, the x86 architecture. The final command could look like this:
root #
genkernel --kernel-config=/usr/src/linux/.config --btrfs --install --arch-override=x86 all
To override the architecture choice permanently, modify the ARCH_OVERRIDE variable in the /etc/genkernel.conf file.
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 genkernel.conf to include this line:
/etc/genkernel.conf
Run a command after building a new kernel# Run the specified command in the current environment after the kernel and # modules have been compiled, useful to rebuild external kernel module # (use "emerge --quiet @module-rebuild" for >=portage-2.2) or installing additional # files (use 'copy_image_with_preserve dtb path/to/dtb dtb ${KNAME}-${ARCH}-${KV}') #CMD_CALLBACK="" CMD_CALLBACK="emerge --quiet @module-rebuild"
関連項目
- 手動カーネルコンフィギュレーション - 手動で行う必要があるときのために。
- Dracut - Gentoo で利用可能な他の initramfs ビルダ。
This page is based on a document formerly found on our main website gentoo.org.
The following people contributed to the original document: Tim Yamin, Jimi Ayodele, Thomas Seiler, , Sebastian Pipping (sping) , José Fournier (jaaf)
They are listed here because wiki history does not allow for any external attribution. If you edit the wiki article, please do not add yourself here; your contributions are recorded on each article's associated history page.