Skip to content

Commit 9b04a5b

Browse files
committed
Setup/Install ZFSBootMenu script
1 parent 0e5fdad commit 9b04a5b

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

root_with_zfs/02_setup_ZBM.nu

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# -----------------------------------------------------------------------------
2+
# Script : Setup ZFSBootMenu.nu
3+
# Desc : Create GPT partitions and install ZFSBootMenu as UEFI bootloader
4+
# Date : 10-29-2025
5+
#
6+
# Usage:
7+
# ./setup_ZBM.nu
8+
# - Wipes existing partition table on /dev/nvme0n1
9+
# - Creates ESP (512MiB) and ZFS pool partition
10+
# - Downloads and installs ZFSBootMenu EFI binaries
11+
# - Registers boot entries via efibootmgr
12+
#
13+
# Notes:
14+
# - Requires root/sudo privileges
15+
# - Destroys ALL data on target disk (/dev/nvme0n1)
16+
# - Requires create_gpt_partitions.sh in current directory
17+
# - ESP mount point: /mnt/boot/efi
18+
# - Requires efibootmgr, wget2, sgdisk, wipefs utilities
19+
#
20+
# Deps: wget2, efibootmgr
21+
#
22+
# Refs:
23+
# - https://docs.zfsbootmenu.org
24+
# - https://github.com/zbm-dev/zfsbootmenu
25+
#
26+
# tag: linux-only, destructive
27+
# -----------------------------------------------------------------------------
28+
29+
30+
# Run this script after running "./create_gpt_partitions.sh"
31+
# which creates GPT partitions (ESP 512MiB + ZFS pool)
32+
33+
const DISK = "/dev/nvme0n1"
34+
const ESP_PART = $"($DISK)p1"
35+
const ESP_MOUNT = "/mnt/boot/efi"
36+
const ZBM_DIR = $"($ESP_MOUNT)/EFI/ZBM"
37+
38+
# Verify disk exists
39+
if not ($DISK | path exists) {
40+
error make {msg: $"Disk ($DISK) not found"}
41+
}
42+
43+
print $"WARNING: This will DESTROY ALL DATA on ($DISK)"
44+
print "Press Ctrl+C to cancel, or Enter to continue..."
45+
input
46+
47+
48+
# Mount ESP
49+
print $"Mounting ESP at ($ESP_MOUNT)..."
50+
sudo mkdir --parents $ESP_MOUNT
51+
sudo mount $ESP_PART $ESP_MOUNT
52+
if $env.LAST_EXIT_CODE != 0 {
53+
error make {msg: "Failed to mount ESP"}
54+
}
55+
56+
# Create ZBM directory
57+
sudo mkdir --parents $ZBM_DIR
58+
59+
# Download ZFSBootMenu EFI binaries
60+
print "Downloading ZFSBootMenu binaries..."
61+
sudo wget2 --trust-server-names --output-document=$"($ZBM_DIR)/vmlinuz.efi" https://get.zfsbootmenu.org/efi
62+
if $env.LAST_EXIT_CODE != 0 {
63+
sudo umount $ESP_MOUNT
64+
error make {msg: "Failed to download ZBM EFI binary"}
65+
}
66+
67+
sudo wget2 --trust-server-names --output-document=$"($ZBM_DIR)/vmlinuz-rec.efi" https://get.zfsbootmenu.org/efi/recovery
68+
if $env.LAST_EXIT_CODE != 0 {
69+
sudo umount $ESP_MOUNT
70+
error make {msg: "Failed to download ZBM recovery binary"}
71+
}
72+
73+
# Verify downloads
74+
print "\nVerifying downloads:"
75+
sudo ls -lh $ZBM_DIR
76+
77+
# Register UEFI boot entries
78+
print "\nRegistering UEFI boot entries..."
79+
sudo efibootmgr --disk $DISK --part 1 --create --label "ZFSBootMenu" --loader '\EFI\ZBM\vmlinuz.efi'
80+
sudo efibootmgr --disk $DISK --part 1 --create --label "ZFSBootMenu Recovery" --loader '\EFI\ZBM\vmlinuz-rec.efi'
81+
82+
if $env.LAST_EXIT_CODE == 0 {
83+
print "\nBoot entries registered successfully"
84+
sudo efibootmgr | grep -i zbm
85+
} else {
86+
print "WARNING: efibootmgr failed - you may need to register manually in BIOS"
87+
}
88+
89+
# Unmount ESP
90+
print $"\nUnmounting ($ESP_MOUNT)..."
91+
sudo umount $ESP_MOUNT
92+
93+
print "\nZFSBootMenu installation complete"

0 commit comments

Comments
 (0)