systemd-boot(7),曾用名 gummiboot (德語裡「橡皮筏」的意思),是一款易於設定的 UEFI 啟動載入程式。它提供了一個用於選擇啟動項的文字選單,以及一個用於設定核心命令列的編輯器。
注意,systemd-boot 只能啟動 EFI 可執行程式(例如 Linux 核心 EFI boot stub,UEFI shell,GRUB 或者 Windows Boot Manager)。
支援的檔案系統
systemd-boot 從韌體繼承了檔案系統相容性(例如至少支援 FAT12,FAT16 和 FAT32),還可以載入 esp/EFI/systemd/drivers/
目錄下的 UEFI 驅動。
安裝
systemd-boot 隨 systemd包 包一同安裝,其為 base包 元軟體包的依賴,因此無需手動安裝額外軟體包。
安裝 UEFI 啟動管理器
要安裝 systemd-boot,首先確保啟動方式是 UEFI 模式,可以訪問 UEFI 變數。用 efivar --list
命令進行檢查,如果沒有安裝 efivar包 ,使用 ls /sys/firmware/efi/efivars
(如果目錄存在,則表明系統是以 UEFI 模式啟動的)。
下面的例子中會用 esp
表示 ESP 掛載點的路徑,例如 /efi
或 /boot
。這將假設你已經 chroot 到了系統的掛載點下。
使用 bootctl(1) 將 systemd-boot 安裝到 ESP:
# bootctl install
這將把 systemd-boot UEFI 啟動管理器複製到 ESP,同時為其建立一項 UEFI 啟動入口,並將其設定為 UEFI 啟動順序的第一項。
- 在 x64 UEFI 環境中,
/usr/lib/systemd/boot/efi/systemd-bootx64.efi
將被複製到esp/EFI/systemd/systemd-bootx64.efi
和esp/EFI/BOOT/BOOTX64.EFI
。 - 在 IA32 UEFI 環境中,
/usr/lib/systemd/boot/efi/systemd-bootia32.efi
將被複製到esp/EFI/systemd/systemd-bootia32.efi
和esp/EFI/BOOT/BOOTIA32.EFI
。
UEFI 啟動選項將被命名為「Linux Boot Manager」,根據 UEFI 位數不同,啟動選項將指向到 ESP 的 \EFI\systemd\systemd-bootx64.efi
或 \EFI\systemd\systemd-bootia32.efi
位置下。
- 在執行
bootctl install
時,systemd-boot 會嘗試在/efi
,/boot
和/boot/efi
目錄下尋找 ESP。可以透過--esp-path=esp
參數指定esp
目錄(詳細資訊請參考 bootctl(1) § OPTIONS)。 - 安裝 systemd-boot 將覆蓋現有的
esp/EFI/BOOT/BOOTX64.EFI
(或是 IA32 UEFI 下的esp/EFI/BOOT/BOOTIA32.EFI
),例如 Microsoft 版本的檔案。
要完成安裝,請設定 systemd-boot。
透過 XBOOTLDR 安裝
可以單獨建立一個「Linux extended boot」(XBOOTLDR)類型的 /boot 分割區將核心和 initramfs 從 ESP 中分離出來,有助於在現有 ESP 過小的情況下設定 Arch + Windows 雙系統。
跟隨通常步驟設定 ESP,然後在同一物理硬碟上為 XBOOTLDR 建立另一分割區。XBOOTLDR 分割區的類型 GUID 必須是 bc13c2ff-59e6-4262-a352-b275fd6f7172
[1](gdisk 下是 ea00
,fdisk 下是 xbootldr
)。XBOOTLDR 的容量必須至少為要安裝的所有核心的總大小。
- systemd-boot 不會像 ESP 那樣檢查 XBOOTLDR 的檔案系統,因此可以使用你的 UEFI 實現可讀取的任意檔案系統類型。
- 在啟用「快速啟動」時,UEFI 可能會跳過載入除 ESP 外的所有分割區,可能會導致 systemd-boot無法在 XBOOTLDR 分割區上找到啟動項。在這種情況下,請禁用「快速啟動」。
- XBOOTLDR 分割區必須與 ESP 位於同一物理硬碟,否則 systemd-boot 將無法識別到該分割區。
在安裝時,將 ESP 掛載到 /mnt/efi
,將 XBOOTLDR 分割區掛載到 /mnt/boot
。
chroot 後,執行:
# bootctl --esp-path=/efi --boot-path=/boot install
最後設定 systemd-boot。
更新 EFI 啟動管理器
每當 systemd-boot 有新版本時,使用者可以選擇重新安裝啟動管理器。該操作可以手動或自動進行,具體方式將在下文中描述。
手動更新
使用bootctl 更新 systemd-boot:
# bootctl update
bootctl install
類似,systemd-boot 會嘗試在 /efi
,/boot
和 /boot/efi
三個位置下尋找 ESP。可以用 --esp-path=esp
參數指定 esp
位置。自動更新
如果你需要自動更新 systemd-boot,你可以嘗試使用 systemd 服務或 Pacman 鉤子,下方介紹了這兩種方法。
systemd 服務
在版本 250 後, systemd包 添加了 systemd-boot-update.service
。啟用這個服務後將會在下次啟動系統之後更新 bootloader。
pacman 鉤子
軟體包 systemd-boot-pacman-hookAUR 提供了一個 Pacman 鉤子,將在每次更新 systemd包 後自動執行。
或者,不安裝 systemd-boot-pacman-hook 實現相同功能,在 /etc/pacman.d/hooks/
目錄下手動添加以下檔案:
/etc/pacman.d/hooks/95-systemd-boot.hook
[Trigger] Type = Package Operation = Upgrade Target = systemd [Action] Description = Gracefully upgrading systemd-boot... When = PostTransaction Exec = /usr/bin/systemctl restart systemd-boot-update.service
為安全啟動進行簽名
如果你啟用了安全啟動,你需要添加一個 Pacman 鉤子以在更新後自動為其重新簽名:
/etc/pacman.d/hooks/80-secureboot.hook
[Trigger] Operation = Install Operation = Upgrade Type = Path Target = usr/lib/systemd/boot/efi/systemd-boot*.efi [Action] Description = Signing systemd-boot EFI binary for Secure Boot When = PostTransaction Exec = /bin/sh -c 'while read -r i; do sbsign --key /path/to/keyfile.key --cert /path/to/certificate.crt "$i"; done;' Depends = sh Depends = sbsigntools NeedsTargets
將 /path/to/keyfile.key
和 /path/to/certificate.crt
替換為你的簽名金鑰和憑證,具體資訊可參考 sbsign(1) 。
The created /usr/lib/systemd/boot/efi/systemd-boot*.efi.signed
will automatically be picked up by bootctl install
or bootctl update
. See bootctl(1) § SIGNED .EFI FILES.
As an alternative, use sbctl.
設定
bootctl
來確保 systemd-boot 能夠正常讀取設定內容。啟動選單設定
設定檔儲存於 esp/loader/loader.conf
,具體資訊可參考 loader.conf(5) § OPTIONS 。
以下是一個簡單的範例:
esp/loader/loader.conf
default arch.conf timeout 4 console-mode max editor no
- systemd-boot 不支援使用制表符進行縮排,請使用空格進行替代。
-
default
和timeout
可在啟動選單中修改,變更將覆蓋儲存到LoaderEntryDefault
和LoaderConfigTimeout
這兩個 UEFI 變數中。 -
bootctl set-default ""
和bootctl set-timeout ""
可分別用於清除覆蓋了default
andtimeout
選項的 UEFI 變數。 - 如果你設定了
timeout 0
,可以透過按下空格鍵
來訪問啟動選單。 - 基本設定檔範例位於
/usr/share/systemd/bootctl/loader.conf
。 - 如果在選擇啟動項頁面時選單顯示異常或解析度不對,可以嘗試將
console-mode
設定為auto
(啟發式選擇最佳解析度),keep
(保持韌體提供的解析度)或2
(嘗試使用第一個非 UEFI 標準的解析度)。
記住上一次的啟動項
從 systemd 251 版本開始,可以將預設啟動項設為 @saved
來記住上次使用的啟動項。該選項對 Windows 雙系統或 Windows 更新自動啟動到了 Linux 的情況非常有用。
esp/loader/loader.conf
default @saved ...
更多資訊請參考 loader.conf(5)。
增加啟動選項
systemd-boot 會在 esp/loader/entries/*.conf
中尋找啟動選項,如果使用了 XBOOTLDR,那同時也會尋找 boot/loader/entries/*.conf
。注意,esp
下的啟動項只能調用 esp
下的檔案(例如核心,initramfs,映像等),boot
下的啟動項也一樣只能調用 boot
下的檔案。
.cmdline
的統一核心映像(UKI)將忽略所有傳入的命令列選項(無論是使用 options
傳入啟動選項還是交互式傳入的)。當未啟用安全啟動時,透過命令列傳入的選項會覆蓋掉 .cmdline
內建的選項。以下為從卷啟動 Arch 的啟動選項檔案範例,其中卷的 UUID 為 xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
:
esp/loader/entries/arch.conf
title Arch Linux linux /vmlinuz-linux initrd /initramfs-linux.img options root=UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx rw
esp/loader/entries/arch-fallback.conf
title Arch Linux (fallback initramfs) linux /vmlinuz-linux initrd /initramfs-linux-fallback.img options root=UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx rw
所有設定選項可參考啟動載入程式規範。
systemd-boot 會在啟動時自動搜尋位於 /EFI/Microsoft/Boot/Bootmgfw.efi
的 Windows Boot Manager,韌體中的 Apple macOS Boot Manager,/shellx64.efi
(UEFI shell)和 /EFI/BOOT/bootx64.efi
(EFI Default Loader),同時也會在 /EFI/Linux/
內尋找核心檔案。在檢測到後,會自動生成名稱分別為 auto-windows
,auto-osx
,auto-efi-shell
和 auto-efi-default
的啟動選項,因此這些選項不需要手動設定啟動載入程式。但和 rEFInd 不同,不會為其它 EFI 應用程式建立啟動選項,所以這些還需要進行進一步設定。
initrd
中指定 /boot/amd-ucode.img
或/boot/intel-ucode.img
,並將其放置到主 initramfs 之前的首位。UEFI Shells 或其他 EFI 應用程式
如果你透過 edk2-shell包 安裝了 UEFI shell,那麼在對應 EFI 檔案放置到了 esp/shellx64.efi
的情況下 systemd-boot 會自動檢測到並為其建立新啟動選項。
要啟用自動檢測,可以在安裝軟體包後執行如下命令:
# cp /usr/share/edk2-shell/x64/Shell.efi /boot/shellx64.efi
另外如果你安裝了其他 EFI 應用程式到 ESP,也可以像這樣進行載入:
efi
參數的檔案路徑是相對於你的 EFI 系統分割區的。如果你的 EFI 系統分割區掛載到了 /boot
,且你的 EFI 二進制檔案位於 /boot/EFI/xx.efi
和 /boot/yy.efi
,那麼你需要指定對應參數分別為 efi /EFI/xx.efi
和 efi /yy.efi
。esp/loader/entries/fwupd.conf
title Firmware updater efi /EFI/tools/fwupdx64.efi
esp/loader/entries/gdisk.conf
title GPT fdisk (gdisk) efi /EFI/tools/gdisk_x64.efi
Memtest86+
首先需要安裝 memtest86+-efi包。如果使用了安全啟動,需要同時對 EFI 二進制檔案進行簽名。
esp/loader/entries/memtest.conf
title Memtest86+ efi /memtest86+/memtest.efi
網路啟動
systemd-boot 可以串聯載入網路啟動。下載 ipxe-arch.efi
EFI 二進制檔案和簽名,驗證並將其放置到如 esp/EFI/arch_netboot/arch_netboot.efi
的位置下:
esp/loader/entries/arch_netboot.conf
title Arch Linux Netboot efi /EFI/arch_netboot/arch_netboot.efi
GRUB
systemd-boot 可以串聯載入 GRUB。grubx64.efi
二進制檔案的位置與安裝 GRUB 到 ESP 時使用的 --bootloader-id=
參數一致。
esp/loader/entries/grub.conf
title GRUB efi /EFI/GRUB/grubx64.efi
從其它硬碟啟動
systemd-boot 不能從它啟動的 ESP 或 XBOOTLDR 分割區所在硬碟外的分割區中啟動 EFI 二進制檔案,但可以啟動其它 UEFI shell 進行這一操作。
首先,按照上面的步驟安裝 edk2-shell包。接著,在 UEFI shell 環境下,使用 map 命令取得帶有對應 PARTUUID 的分割區的 FS alias(例如 HD0a66666a2、HD0b、FS1 或 BLK7)並記錄下來。
下一步,使用 exit
命令啟動回到 LInux 環境,然後建立一條新啟動選項來透過 UEFI shell 啟動目標 EFI 應用:
esp/loader/entries/windows.conf
title Windows efi /shellx64.efi options -nointerrupt -nomap -noversion HD0b:EFI\Microsoft\Boot\Bootmgfw.efi
確保 efi
路徑和複製到 esp 路徑下的 shellx64.efi
位置一致。順帶一提,可以將 shellx64.efi
EFI 檔案移動到其它位置來防止 systemd-boot 自動建立啟動選項。
將 HD0b
替換為之前記錄的 FS alias。
-
-nointerrupt
選項可以避免透過Ctrl+c
選項終端目標 EFI 程式允許。 -
-nomap -noversion
選項會隱藏掉預設 UEFI shell 歡迎資訊。 - 如需讓 UEFI shell 在目標 EFI 程式退出後(如出現錯誤等原因)自動回到啟動載入程式,可以添加
-exit
選項。 - 如果 UEFI shell 還會出現無用輸出,可以添加
-noconsoleout
選項。
啟動到 UEFI 韌體設定
如果你裝置的韌體支援從作業系統重新啟動到韌體設定,那 systemd-boot 會自動檢測到並添加啟動到 UEFI 韌體設定的選項。
對休眠的支援
參閱掛起與休眠。
為核心參數編輯器加上密碼保護
你也可以安裝 systemd-boot-passwordAUR,它支援 password
基本設定選項。使用 sbpctl generate
可以為該選項生成值。
使用如下命令安裝 systemd-boot-password:
# sbpctl install esp
啟用編輯器後,系統會提示你輸入密碼,然後才能編輯核心參數。
小提示
啟動選單中的按鍵操作
在啟動選單中,你可以使用 t
和 T
調整逾時時間,使用 e
編輯目前啟動項的核心參數。按下 h
可以看到一個簡略的快速鍵列表,完整的啟動選單內可用快速鍵列表可參考 systemd-boot(7) § KEY BINDINGS 。
選擇下一次啟動選項
啟動管理器與 systemctl 命令集成,允許你選擇重新啟動後的啟動選項。舉個例子,假設你組建了一個自訂核心,並建立了一個啟動項檔案 esp/loader/entries/arch-custom.conf
來啟動它,只需執行:
$ systemctl reboot --boot-loader-entry=arch-custom.conf
然後系統就會重新啟動到對應的啟動項,同時系統後續啟動將保留現有設定不變。所有可用啟動項清單可透過 --boot-loader-entry=help
選項檢視。
可以透過以下命令直接啟動到主機板韌體:
$ systemctl reboot --firmware-setup
統一核心映像
位於 esp/EFI/Linux/
的統一核心映像會被 systemd-boot 自動載入,無需在 esp/loader/entries
中添加條目。請注意,統一核心映像必須具有 .efi
副檔名,才能被 systemd-boot 識別。
esp/loader/loader.conf
中未設定 default
,則會優先啟動位於 esp/loader/entries/
的檔案。請移除這些條目,或使用完整檔名來設定預設項目,例如 default arch-linux.efi
Grml on ESP
PKGBUILD
is available: grml-systemd-bootAUR.Grml is a small live system with a collection of software for system administration and rescue.
In order to install Grml on the ESP, we only need to copy the kernel vmlinuz
, the initramfs initrd.img
, and the squashed image grml64-small.squashfs
from the iso file to the ESP. To do so, first download grml64-small.iso and mount the file (the mountpoint is henceforth denoted mnt); the kernel and initramfs are located in mnt/boot/grml64small/
, and the squashed image resides in mnt/live/grml64-small/
.
Next, create a directory for Grml in your ESP,
# mkdir -p esp/grml
and copy the above-mentioned files in there:
# cp mnt/boot/grml64small/vmlinuz esp/grml # cp mnt/boot/grml64small/initrd.img esp/grml # cp mnt/live/grml64-small/grml64-small.squashfs esp/grml
In the last step, create an entry for the systemd-boot loader: In esp/loader/entries
create a grml.conf
file with the following content:
esp/loader/entries/grml.conf
title Grml Live Linux linux /grml/vmlinuz initrd /grml/initrd.img options apm=power-off boot=live live-media-path=/grml/ nomce net.ifnames=0
For an overview of the available boot options, consult the cheatcode for Grml.
Archiso on ESP
PKGBUILD
is available: archiso-systemd-bootAUR.As with Grml it is possible to use the Arch Linux ISO. To do this we need to copy the kernel vmlinuz-linux
, the initramfs initramfs-linux.img
, and the squashfs image airootfs.sfs
from the ISO file to the EFI system partition.
First download archlinux-YYYY.MM.DD-x86_64.iso.
Next, create a directory for archiso in your ESP:
# mkdir -p esp/EFI/archiso
Extract the contents of the arch
directory in there:
# bsdtar -v -x --no-same-permissions --strip-components 1 -f archlinux-YYYY.MM.DD-x86_64.iso -C esp/EFI/archiso arch
In the last step, create a boot entry for the systemd-boot loader: In esp/loader/entries
create a arch-rescue.conf
file with the following content:
esp/loader/entries/arch-rescue.conf
title Arch Linux (rescue system) linux /EFI/archiso/boot/x86_64/vmlinuz-linux initrd /EFI/archiso/boot/x86_64/initramfs-linux.img options archisobasedir=/EFI/archiso archisosearchfilename=/EFI/archiso/boot/x86_64/vmlinuz-linux
For an overview of the available boot options, consult the README.bootparams for mkinitcpio-archiso.
在 BIOS 系統上使用 systemd-boot
If you need a bootloader for BIOS systems that follows The Boot Loader Specification, then systemd-boot can be pressed into service on BIOS systems. The Clover boot loader supports booting from BIOS systems and provides a emulated UEFI environment.
排除問題
systemd-boot 無法顯示我的啟動項
該問題可能是由設定檔問題(如核心路徑錯誤)導致的。可以執行以下命令進行檢查:
# bootctl
在傳統啟動(BIOS 模式)下安裝
如果你以 BIOS 模式啟動電腦,你還是可以正常安裝 systemd-boot,但需要在安裝後手動向你的韌體提供如何啟動 systemd-boot EFI 檔案的相關資訊,為此你需要下列工具之一:
- 一個 UEFI Shell
- 你的 UEFI 韌體設定中提供了更改啟動選項的選項.
- 如果 UEFI 沒有其它啟動項,某些韌體會直接使用
esp/EFI/BOOT/BOOTX64.EFI
。
滿足條件後,進入你的 UEFI Shell 或是 UEFI 韌體設定,修改你的預設 EFI 啟動載入器為 esp/EFI/systemd/systemd-bootx64.efi
。
透過 efibootmgr 手動添加啟動選項
如果執行bootctl install
命令失敗,你可以透過 efibootmgr包手動增加選項:
# efibootmgr --create --disk /dev/sdX --part Y --loader '\EFI\systemd\systemd-bootx64.efi' --label "Linux Boot Manager" --unicode
用 EFI 系統分割區的裝置名稱替換 /dev/sdXY
。
在 Windows 上透過 bcdedit 添加啟動選項
If for any reason you need to create an UEFI boot entry from Windows, you can use the following commands from an Administrator prompt:
> bcdedit /copy {bootmgr} /d "Linux Boot Manager" > bcdedit /set {guid} path \EFI\systemd\systemd-bootx64.efi
Replace guid
with the id returned by the first command. You can also set it as the default entry using
> bcdedit /default {guid}
在 Windows 升級後看不到啟動選單
添加 Windows BitLocker TPM 解鎖支援
在 loader.conf 中添加以下內容以阻止 BitLocker 請求恢復金鑰:
esp/loader/loader.conf
reboot-for-bitlocker yes
這一步會設定 BootNext UEFI 變數,從而無需使 BitLocker 請求恢復金鑰就能載入 Windows Boot Manager。該操作只需進行一次,且 systemd-boot 仍是預設啟動載入程式。如果已自動檢測到 Windows,則無需將其指定為條目。
注意,這是實驗性功能,使用前請查閱 loader.conf(5)。