UEFI Bootloaders (日本語)
このページには Linux カーネルを起動することができる様々な UEFI ブートローダの情報が含まれています。このページを読む前に UEFI と GPT のページを読むことを推奨します。ここでは以下のブートローダが説明されています:
Contents |
Linux Kernel EFISTUB
Linux カーネル (linux>=3.3) は EFISTUB (EFI BOOT STUB) ブートをサポートしています。カーネル設定で CONFIG_EFI_STUB=y を設定することで有効にすることができ、Arch Linux のカーネルではデフォルトに有効にされています (詳しくは The EFI Boot Stub を参照してください)。
EFISTUB カーネルだけでは他のカーネルを起動することはできません。よってブートメニューエントリごとに EFISTUB カーネル + Initramfs のペアが必要です。このため、複数のカーネルを使う場合は、UEFI Boot Manager を使うことが推奨されています。
EFISTUB の設定
- EFI System Partition を作成してください。
-
/boot(Gummiboot を使用するか、ブートマネージャを使わないときに推奨) かどこか好きなところに (他のディストロやツールは大抵/boot/efiを使っています) EFI System Partition をマウントしてください。以後このマウントポイントは$espとして示します。
ファイルを適切な場所に移動する
-
$esp/EFI/arch/を作成してください - 以下のファイルを移動元から移動先にコピーしてください
| ブートファイルの移動元 | UEFI の移動先 |
|---|---|
| /boot/vmlinuz-linux | $esp/EFI/arch/vmlinuz-arch.efi |
| /boot/initramfs-linux.img | $esp/EFI/arch/initramfs-arch.img |
| /boot/initramfs-linux-fallback.img | $esp/EFI/arch/initramfs-arch-fallback.img |
Systemd
Systemd にはイベントトリガータスク機能があります。ここで、パス上の変更を検知する能力を使って、boot にある EFISTUB カーネルと initramfs のファイルが更新されたときにそれらを同期させることが可能です。
[Unit] Description=Copy EFISTUB Kernel to UEFISYS Partition [Path] PathChanged=/boot/initramfs-linux-fallback.img [Install] WantedBy=multi-user.target
[Unit] Description=Copy EFISTUB Kernel to UEFISYS Partition [Service] Type=oneshot ExecStart=/usr/bin/cp -f /boot/vmlinuz-linux $esp/EFI/arch/vmlinuz-arch.efi ExecStart=/usr/bin/cp -f /boot/initramfs-linux.img $esp/EFI/arch/initramfs-arch.img ExecStart=/usr/bin/cp -f /boot/initramfs-linux-fallback.img $esp/EFI/arch/initramfs-arch-fallback.img
Incron
incron は更新後に EFISTUB カーネルを同期するスクリプトを実行することができます。
#!/usr/bin/env bash /usr/bin/cp -f /boot/vmlinuz-linux $esp/EFI/arch/vmlinuz-arch.efi /usr/bin/cp -f /boot/initramfs-linux.img $esp/EFI/arch/initramfs-arch.img /usr/bin/cp -f /boot/initramfs-linux-fallback.img $esp/EFI/arch/initramfs-arch-fallback.img
/boot/initramfs-linux-fallback.img IN_CLOSE_WRITE /usr/local/bin/efistub-update.sh
Mkinitcpio hook
Mkinitcpio はフックを生成することができシステムレベルデーモンを機能させる必要はありません。バックグラウンドプロセスを生成して vm-linuz, initramfs-linux.img, initramfs-linux-fallback.img の生成を待ち; そして #EFISTUB の設定 の手順4に従います。
#!/usr/bin/env bash
build() {
/root/watch.sh &
}
help() {
cat <<HELPEOF
This hook waits for mkinitcpio to finish and copies the finished ramdisk and kernel to the ESP
HELPEOF
}
#!/usr/bin/env bash while [[ -d "/proc/$PPID" ]]; do sleep 1 done /usr/bin/cp -f /boot/vmlinuz-linux $esp/EFI/arch/vmlinuz-arch.efi /usr/bin/cp -f /boot/initramfs-linux.img $esp/EFI/arch/initramfs-arch.img /usr/bin/cp -f /boot/initramfs-linux-fallback.img $esp/EFI/arch/initramfs-arch-fallback.img echo "Synced kernel with ESP"
/etc/fstab バインドマウント
- Method
- Whereas the general convention is to mount the EFI system partition to a
/boot/efisubfolder, the following will achieve the opposite.
- Create a
ef00type EFI system partition of FAT32 format as described elsewhere.
- Create a mount-point and mount the EFI system partition somewhere on the filesystem. For example:
-
$ mkdir /esp
$ mount -L esp /esp
- Create a folder in
/EFI/booton the EFI system partition to contain your system's/bootfiles. For example:
-
$ mkdir /esp/EFI/boot/arch64-laptop
- Move all files in
/bootto the newly created folder on your EFI system partition. For example:
-
$ mv /boot/* /esp/EFI/boot/arch64-laptop/
- Bind mount the newly populated folder on your EFI system partition to
/boot. For example:
-
$ mount --bind /esp/EFI/boot/arch64-laptop /boot
- Verify your files are available as expected with
$ ls /boot/then persist the configuration by editing/etc/fstab. For example:
-
##/etc/fstab
LABEL=arch64-laptop_rootfs / ext4 defaults 0 0
LABEL=esp /esp vfat defaults 0 0
/esp/EFI/boot/arch64-laptop /boot none defaults,bind 0 0
- Update your bootloader to apply the
root=kernel boot parameter as necessary. For example:
-
##/boot/refind_linux.conf
... root=LABEL=arch64-laptop_rootfs ...
EFISTUB の起動
以下の方法のどれか一つを使うことで EFISTUB カーネルを起動することができます:
efibootmgr エントリを使って直接起動する
efibootmgr によって作成したブートエントリに直接カーネルパラメータを埋め込むことが可能です。つまりあなたの UEFI ブート順・GUI を使って GRUB などの他のブートローダーを使わずに直接 Arch Linux を起動することができます (下のコマンドで、EFI System Partition は /dev/sdX 上に、パーティションは Y にあると仮定しています)。
# efibootmgr -c -d /dev/sdX -p Y -l /EFI/arch/vmlinuz-arch.efi -L "Arch Linux (EFISTUB)" -u "$(cat /proc/cmdline)"
作成されたエントリが問題ないか確認するために次のコマンドを実行すると良いでしょう:
# efibootmgr -v
また、ブートオプションの順番を新しく割り当てて (efibootmgr -o) Arch のエントリを最後に持ってくることで、失敗した時にシステムが楽にリカバーできます。
efibootmgr の詳細は UEFI#efibootmgr で説明しています。フォーラムの投稿 https://bbs.archlinux.org/viewtopic.php?pid=1090040#p1090040 。
gummiboot を使う
Gummiboot は EFISTUB カーネルのナイスなメニューを提供する UEFI Boot Manager です。gummiboot として [core] から利用でき、EFISTUB ブートの推奨ブートマネージャです。詳細は gummiboot を見て下さい。
rEFInd を使う
rEFInd は (Intel Mac で使われている) rEFIt Boot Manager の Rod Smith (GPT-fdisk の作者) によるフォークです。rEFInd は Mac 以外の UEFI ブートについて rEFIt の多くの問題を修正してあり EFISTUB カーネルをサポートしています。
-
# pacman -S refind-efiで refind-efi パッケージをインストールしてください - 以下のファイルを rEFInd の移動元ディレクトリから移動先にコピーしてください
| rEFInd ファイルの移動元 | UEFI の移動先 |
|---|---|
| /usr/share/refind/refind_<arch>.efi | $esp/EFI/refind/refind_<arch>.efi |
| /usr/share/refind/refind.conf-sample | $esp/EFI/refind/refind.conf |
| /usr/share/refind/icons | $esp/EFI/refind/icons |
| /usr/share/refind/drivers_<arch> | $esp/EFI/refind/drivers |
refind_linux.conf 設定ファイルを下のテンプレートのように編集してください。PARTUUID の後の文字列はあなたの root の PARTUUID に置き換えてください。
refind_linux.conf
"Boot with defaults" "root=PARTUUID=3518bb68-d01e-45c9-b973-0b5d918aae96 rw rootfstype=ext4 add_efi_memmap systemd.unit=graphical.target" "Boot to Terminal" "root=PARTUUID=3518bb68-d01e-45c9-b973-0b5d918aae96 rw rootfstype=ext4 add_efi_memmap systemd.unit=multi-user.target"
Systemd Automation
#!/usr/bin/env bash
## COPYRIGHT 2013 : MARK E. LEE (BLUERIDER) : mlee24@binghamton.edu; mark@markelee.com
## LOG
## 1/17/2013 : Version 2 of refind_name_patch is released
## : Supports long subdirectory location for refind
## : Updates nvram when needed
## : 10% speed boost
## 7/15/2013 : Changed arch to match 32-bit (ia32) and 64-bit (x64) naming scheme
## : Changed directory copying in update-efi-dir to copy tools and drivers directories explicitly
## : Changed efibootmgr writing code to be more concise and added (-w) to write the entry as per dusktreader's excellent guide : https://docs.google.com/document/d/1pvgm3BprpXoadsQi38FxqMOCUZhcSqFhZ26FZBkmn9I/edit
## : Function to check if NVRAM boot entry was already listed was fixed to use awk and an if then clause
## : ref_bin_escape was modified from : ref_bin_escape=${ref_bin//\//\\\\} to remove extra backslashes (error does not show up when using cmdline)
## 7/29/2013 : Changed location of tools,drivers, and binary directory to match capricious upstream move to /usr/share/refind
function main () { ## main insertion function
declare -r refind_dir="/boot/efi/EFI/refind"; ## set the refind directory
arch=$(uname -m | awk -F'_' '{if ($1 == "x86") {print "x"$2} else if ($1 == "i686") {print "ia32"}}') && ## get bit architecture
update-efi-dir; ## updates or creates the refind directory
update-efi-nvram; ## updates nvram if needed
}
function update-efi-dir () { ## setup the refind directory
if [ ! -d $refind_dir ]; then ## check if refind directory exists
echo "Couldn't find $refind_dir";
mkdir $refind_dir && ## make the refind directory if needed
echo "Made $refind_dir";
fi;
if [ "$arch" ]; then ## check if anything was stored in $arch
cp -r /usr/share/refind/{refind_$arch.efi,keys,images,icons,fonts,docs,{tools,drivers}_$arch} $refind_dir/ && ## update the bins and dirs
echo "Updated binaries and directory files for refind at $refind_dir";
else
echo "Failed to detect an x86 architecture";
exit;
fi;
}
function update-efi-nvram () { ## update the nvram with efibootmgr
declare -r ref_bin=${refind_dir/\/boot\/efi}/refind_$arch.efi; ## get path of refind binary (without /boot/efi)
declare -r ref_bin_escape=${ref_bin//\//\\}; ## insert escape characters into $ref_bin
[ "$(efibootmgr -v | awk "/${ref_bin_escape//\\/\\\\}/")" ] && ( ## check if boot entry is in nvram \
echo "Found boot entry, no need to update nvram";
) || ( ## if boot entry is not in nvram; add it
declare -r esp=$(mount -l | awk '/ESP/ {print $1}') && ## get ESP partition
efibootmgr -cgw -d ${esp:0:8} -p ${esp:8} -L "rEFInd" -l $ref_bin_escape && ## update nvram
echo "
Updated nvram with entry rEFInd to boot $ref_bin
Did not copy configuration files, please move refind.conf to $refind_dir/";
)
}
main; ## run the main insertion function
[Unit] Description=Update rEFInd bootloader files [Path] PathChanged=/usr/share/refind/refind_<arch>.efi Unit=refind_update.service [Install] WantedBy=multi-user.target
[Unit] Description=Update rEFInd directories, binaries, and nvram [Service] Type=oneshot ExecStart=/usr/bin/bash /usr/lib/systemd/scripts/refind_name_patchv2 RemainAfterExit=no
Apple Macs
Apple Mac の場合、Linux 用の実験的な "bless" ユーティリティが含まれている mactel-boot を試して下さい。これが動作しないときは、OSX の中から "bless" を使って rEFInd をデフォルトのブートローダに設定してください。OSX の中で UEFISYS パーティションが /mnt/efi にマウントされているとして、次を実行します:
$ sudo bless --setBoot --folder /mnt/efi/EFI/refind --file /mnt/efi/EFI/refind/refind_x64.efi
VirtualBox
VirtualBox の場合については、VirtualBox (日本語)#Virtualbox の EFI モードで Arch を使う を参照してください。
UEFI Shell を使う
通常の UEFI アプリケーションのように UEFI Shell から EFISTUB カーネルを起動することが可能です。この場合カーネルパラメータは通常のパラメータとして起動する EFISTUB カーネルファイルに渡します。
> fs0: > cd \EFI\arch > vmlinuz-arch.efi root=PARTUUID=3518bb68-d01e-45c9-b973-0b5d918aae96 ro rootfstype=ext4 add_efi_memmap initrd=EFI/arch/initramfs-arch.img
また、ブートパラメータを記述したシンプルな archlinux.nsh ファイルを書いて UEFI System Partition に置き、それを実行することもできます:
fs0: archlinux
スクリプト例:
echo -on \EFI\arch\vmlinuz-arch.efi root=PARTUUID=3518bb68-d01e-45c9-b973-0b5d918aae96 rootfstype=ext4 add_efi_memmap initrd=EFI/arch/initramfs-arch.img
この方法では名前をメモしておいたり20-30文字も入力せずとも UUID を指定することができます。
GRUB 2.xx
GRUB 2.x には自分自身のファイルシステムドライバーが含まれており、ファイルにアクセスするのにファームウェアに依存していません。GRUB は直接 /boot からファイルを読み込むことができ UEFISYS パーティションの中にカーネルや initramfs のファイルを必要としません。詳細は GRUB (日本語)#UEFI_システム_2 で説明しています。bzr の開発バージョンを使う場合 AUR のパッケージを試して下さい - grub-bzr。
SYSLINUX 6.xx
([testing] から) syslinux または syslinux-firmware-git AUR パッケージをインストールして /usr/lib/syslinux/efi64/* を $esp/EFI/syslinux/ にコピーしてください ($esp は UEFISYS パーティションのマウントポイント) (efi64 は x86_64 UEFI ファームウェア用です、ia32 UEFI ファームウェアなら efi32 に置き換えてください)。そして efibootmgr を使ってファームウェアブートマネージャにブートエントリを作成してください。
ELILO
ELILO は LILO Boot Loader の UEFI バージョンです。初めは Intel の Itanium 環境用に作成され EFI (UEFI の前身) だけをサポートしていました。最古の Linux 向け UEFI ブートローダーです。依然としてゆったりとしたペースで開発されています。上流ではコンパイル済みのバイナリを http://sourceforge.net/projects/elilo/ で提供しています。Elilo の設定ファイル elilo.conf は LILO の設定ファイルに似ています。AUR のパッケージ - elilo-efi。
トラブルシューティング
- Intel Z77 など、いくつかの UEFI マザーボードでは、efi シェルから efibootmgr や bcfg でエントリを追加して NVRAM に書き加えられてもブートメニューのリストに表示されません。
- これを解決するには、Windows ブートマネージャが ESP パーティションに存在していると UEFI ファームウェアを騙す必要があります。
- EFI シェルを起動してから、以下を実行して USB ドライブから bootx64.efi ファイルを bootmgfw.efi ファイルとして ESP パーティションにコピーしてください:
FS1: cd EFI mkdir Microsoft cd Microsoft mkdir Boot cp FS0:\EFI\BOOT\bootx64.efi FS1:\EFI\Microsoft\Boot\bootmgfw.efi
- 再起動後、NVRAM に追加されたエントリがブートメニューに表示されるようになるはずです。