EFI スタブ

From Gentoo Wiki
Jump to:navigation Jump to:search
This page is a translated version of the page EFI stub and the translation is 86% complete.
Outdated translations are marked like this.
Other languages:
Resources
This article has some todo items:
  • CONFIG_PM_STD_PARTITION for hibernation

多くのコンピュータに存在する (U)EFI ファームウェアはブートマネージャとして機能し、対応した EFI ブートローダを使用してシステムをブートすることができます。カーネル 自体をこのようなブートローダ (EFI スタブと呼ばれます) にすることで、2 次ブートローダを必要とせずにブートすることができます。この記事では、カーネルを設定して、EFI モードで実行中のコンピュータの EFI システムパーティション (ESP) にインストールするための手順を提供します。

警告
UEFI implementations differ between vendors, as such EFI Stub booting is not guaranteed to work for all UEFI systems. Ensure a back-up booting method is available before attempting (automated) EFI Stub booting.

カーネル設定

EFI スタブサポート

以下のカーネル設定オプションが有効化されていなくてはなりません:

カーネル カーネル 6.1+ に対して EFI スタブサポートを有効化する
Processor type and features  --->
    [*] EFI runtime service support
    [*]     EFI stub support
    [ ]     EFI mixed-mode support (OPTIONAL)
メモ
EFI mixed-mode support は、CPU が 64 ビットモードに対応しており、EFI handover が有効化されている場合に、32 ビットファームウェアから 64 ビットカーネルをブートするためにのみ必要です。
メモ
ディストリビューションカーネル (gentoo-kernel-bin を除く) では、カーネル設定はsavedconfig または /etc/kernel/config.d に保存されます。

インストール

ヒント
省略可能: EFI システムパーティション (ESP) が存在しない場合は、先にそれを構築するための手順に従ってください。

自動

Automated EFI stub booting is provided by sys-kernel/installkernel when the efistub USE flag is enabled. This relocates the regular boot layout from /boot to the EFI/Gentoo directory on the EFI System Partition and then calls kernel-bootcfg from app-emulation/virt-firmware to add or remove a boot entry for the installed or removed kernel. Installkernel is called automatically by the kernel's make install or by the Distribution Kernels' post-install phase. Therefore, no special action is required when installing a new kernel, though the kernel-bootcfg-boot-successful init service from app-emulation/virt-firmware should be enabled to automatically make an entry for a new kernel permanent when booting it was successful.

systemd システムでは:

root #systemctl --enable --now kernel-bootcfg-boot-successful.service

OpenRC システムでは:

root #rc-update add kernel-bootcfg-boot-successful default

When the to-be-registered kernel image is not an Unified Kernel Image a kernel command line for the new entry is read from:

  • /etc/kernel/cmdline, or
  • /usr/lib/kernel/cmdline, or
  • /proc/cmdline

in this order. In addition, the initrd= kernel command line argument is automatically added if an initramfs was generated while installing the kernel. If on the other hand the to-be-registered kernel is an Unified Kernel Image, then no command line is added to the new entry. Instead the command line built into the Unified Kernel Image is used, the contents of this built-in command line are usually also read from the same files when the UKI is generated.

メモ
The efistub USE flag on sys-kernel/installkernel requires the systemd USE flag. However, the systemd flag does not force a dependency on the systemd init system. The dependencies are satisfied by the boot and kernel-install flags on sys-apps/systemd-utils, as such this also works on OpenRC systems.

手動

EFI スタブサポートを付けてカーネルを設定したら (ESP/efi にマウントされていると仮定して)。システムによっては /efi/efi が既に存在することがあり、その場合はそれを使用しなくてはなりません。/efi/EFI (または /efi/efi が既に存在する場合はそちら) の下に個別のディレクトリを作成することが推奨されます。以下では example の名前を使用します:

root #mkdir -p /efi/EFI/example

カーネルは現在のカーネルディレクトリから作成され、新しいディレクトリにコピーされます。これはカーネルを /efi/EFI/example/bzImage.efi にインストールします:

/usr/src/linux #make && make modules_install && cp arch/x86/boot/bzImage /efi/EFI/example/bzImage.efi
ヒント
カーネルをアップグレードするときには、動作することが分かっている古いバージョンを残しておくことが推奨されます:
user $tree -L 3 /efi
 /efi
 └── EFI
     └── example
         ├── bzImage-6.1.67.efi
         └── bzImage-6.1.70.efi

ルートパーティション設定

UEFI から直接ブートするためには、ブートするシステムのルート (/) パーティションがどこにあるのかをカーネルまたは initramfs が認識していなくてはなりません。grub などのブートマネージャを使用する場合は、カーネルはルートパーティションをどこから探せばよいかの情報を、ブートマネージャからコマンドライン引数を介して取得します。スタブカーネルを使用する場合は、カーネルにこの情報を渡すために使用できる方法として 2 つの選択肢があります - これらの選択肢から一方を選択してください:

選択肢 1: カーネル内で設定する =
カーネル カーネル 6.1+ のためのルートパーティション情報
Processor type and features  --->
    [*] Built-in kernel command line
    (root=PARTUUID=adf55784-15d9-4ca3-bb3f-56de0b35d88d ro)
重要
adf55784-15d9-4ca3-bb3f-56de0b35d88d は例であり、実際のルートパーティションの値で置き換えなくてはなりません。これは blkid コマンドを使用して得ることができます:
root #blkid | grep sda3
/dev/sda3: UUID="d1e0c1e0-3a40-42c5-8931-cfa2c7deae32" TYPE="ext4" PARTUUID="adf55784-15d9-4ca3-bb3f-56de0b35d88d"
パーティションの PARTUUID はファイルシステムの UUID とは異なります。UUID は一意なファイルシステムパーティションを指し、initramfs で使用する必要があるもので、PARTUUID はディスクパーティションを指し、カーネルをブートするときに使用することができるものです。
選択肢 2: UEFI 内で設定する

カーネルコマンドライン引数付きのエントリを追加するには:

root #efibootmgr --create --disk /dev/sda --label "Gentoo EFI Stub" --loader "\EFI\example\bzImage.efi" -u "root=/dev/sda3"
重要
ルートの場所は PARTUUID を使用して、または initramfs を使用する場合には (ファイルシステムの) UUID を使用して設定するほうが、一般的により好ましく間違いを起こしにくいです。

EFI ファームウェア設定

カーネルファイルが /efi/EFI/example/bzImage.efi にある場合は、ブートエントリは以下で追加することができます:

root #efibootmgr --create --disk /dev/sda --label "Gentoo EFI Stub" --loader "\EFI\example\bzImage.efi"

さらなる例を efibootmgr で見つけることができます。

追加可能: initramfs とともに併用する

外部の (CPIO アーカイブの) initramfs とともにカーネルを使用する場合、追加の手順が必要です。dist-kernel をビルドする場合または genkernel を使用する場合は、必ず initramfs が作成されます。dist-kernel を使用する場合、この initramfs は "initrd" という名前が付けられ、/usr/src/linux-6.1.57-gentoo-dist/arch/x86/boot/initrd に置かれます。このファイルを ESP にコピーする必要があります:

root #cp /path/to/my/initramfs/myinitrd.cpio.gz /efi/EFI/example/initrd.cpio.gz

カーネルは initramfs をどこから探すべきかの情報を必要とし、initramfs はルートパーティションをどこから探すべきかの情報を必要とします。UEFI は両方の情報を与えなくてはなりません:

root #efibootmgr -c -d /dev/sda -p 1 -L "Gentoo EFI Stub" -l '\EFI\example\bzImage.efi' -u 'root=UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx initrd=\EFI\example\initrd.cpio.gz'

フォーラム投稿はそれについてより詳しく説明しています - さらにユーザのエラーをいくつか修正しています:

Forums topic - Booting UEFI without Grub

Early Userspace Mounting を使用する場合は、Generating the Initramfs および Using a Stub Kernel の節でそれについて詳しく説明しています。

省略可能: 埋め込み initramfs

It's also possible to embed the initramfs directly into the kernel. Advantages include the initramfs being verified by Secure Boot when it verifies the kernel, a simplified boot process and EFI partition, and it being easier to load the kernel by hand (because callers no longer need to specify the initramfs). Disadvantages are reduced flexibility, the ease of making a mistake, and using an unconventional boot setup.

警告
If your initramfs contains Microcode, then it is critical for security that it is receiving updates. When embedded, the initramfs can't be updated independently of the kernel, and a kernel rebuild will be necessary every time the initramfs is updated. In particular, please ensure that:
  • If
    root #make clean
    is not being run before rebuilding the kernel,
    root #rm usr/initramfs_data.cpio
    is run to clear the cached initramfs CPIO archive that remains from the last build.
  • When the initramfs has an update, the kernel is rebuilt and reinstalled.
  • If the initramfs is managed by sys-apps/portage, the initramfs is updated before the kernel.

The kernel supports both CPIO files (for example, as produced by Dracut) and source directories which are to be compressed into a CPIO archive. The following shows the latter with /usr/src/initramfs, however should be substituted with /path/to/my/initramfs/myinitrd.cpio.gz if the former case is desired (it usually is, unless you are using a Custom Initramfs).

カーネル カーネルに initramfs を埋め込む
General Setup  --->
    [*] Initial RAM filesystem and RAM disk (initramfs/initrd) support
    (/usr/src/initramfs) Initramfs source file(s)

To ensure everything is functioning correctly, the kernel may be booted without the initrd command line argument.

バックアップカーネル

It is recommended to always have a backup kernel. If a bootmanager like grub is already installed, it should not be uninstalled, because grub can boot a stub kernel just like a normal kernel. A second possibility is to work with an additional UEFI entry. Before installing a new kernel, the current one can be copied from /efi/EFI/example/ to /efi/EFI/backup. The second UEFI entry was also created with efibootmgr. In this example, other names were used:

root #efibootmgr
BootCurrent: 0002
Timeout: 1 seconds
BootOrder: 0002,0000,0001
Boot0000* Secure        HD(1,GPT,0adcbfee-21aa-42ea-9a9a-2e53bd05e6a2,0x800,0x7f800)/File(\EFI\secure\bzImage.efi)
Boot0001* gentoo        HD(1,GPT,0adcbfee-21aa-42ea-9a9a-2e53bd05e6a2,0x800,0x7f800)/File(\EFI\gentoo\grubx64.efi)
Boot0002* Backup        HD(1,GPT,0adcbfee-21aa-42ea-9a9a-2e53bd05e6a2,0x800,0x7f800)/File(\EFI\backup\bzImage.efi)

マイクロコードのロード

initramfs を使わないカーネルを使用する場合は、以下の記事に記載されているようにマイクロコードをロードすることが推奨されます:

省略可能: セキュアブートのために署名する

このカーネルをセキュアブートする場合は、app-crypt/sbsigntools に含まれる sbsign を使用して署名しなくてはなりません:

root #sbsign --key {db key} --cert {db cert} /efi/EFI/example/bzImage.efi

さらなる情報が Secure Boot で確認できます。

警告
It is not possible to EFI Stub boot via sys-boot/shim due to the vanilla EFI Stub missing the required .sbat sbat section. As such the used signing keys must be registered directly with the UEFI firmware to EFI Stub boot with Secure Boot enabled. See the Unified Kernel Image wiki page for an alternate EFI Stub booting method that does support booting via shim.

トラブルシューティング

ヒント
UEFI BIOS によっては稀に、個別の UEFI エントリを受け付けないことがあります。この場合はカーネルを次のように再コピーしなくてはなりません: cp /usr/src/linux/arch/x86/boot/bzImage /efi/EFI/boot/bootx64.efi。これは、すべての UEFI が UEFI エントリを作成しなくても受け付けなくてはならないパス名です。
root #efibootmgr -c -L "Gentoo Linux" -l '\EFI\Gentoo\bootx64.efi' -u 'root=PARTUUID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
efibootmgr で、スワップパーティションへのハイバネーションに対応したブートエントリを作成するには:
root #efibootmgr -c -L "Gentoo Linux" -l '\EFI\Gentoo\bootx64.efi' -u 'root=PARTUUID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX resume=PARTUUID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'

関連項目

外部資料

参照