Skip to content

Commit b188209

Browse files
committed
Boot fix
1 parent 4001756 commit b188209

File tree

2 files changed

+38
-9
lines changed

2 files changed

+38
-9
lines changed

Earthfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,13 @@ build-kairos-dd-image:
10741074
echo "✅ Found raw image: $RAW_IMG" && \
10751075
echo "Raw image size: $(du -h "$RAW_IMG" | cut -f1)" && \
10761076
cp "$RAW_IMG" /kairos-dd.img && \
1077-
echo "✅ Kairos dd image created: /kairos-dd.img"
1077+
echo "✅ Kairos dd image created: /kairos-dd.img" && \
1078+
echo "=== Verifying EFI binary (optional; helps diagnose 'Platform does not support this image') ===" && \
1079+
( apk add --no-cache file util-linux 2>/dev/null || true ) && \
1080+
( LOOP=$$(losetup -f 2>/dev/null) && [ -n "$$LOOP" ] && losetup -P "$$LOOP" /kairos-dd.img 2>/dev/null && \
1081+
mkdir -p /mnt-efi && mount "$$LOOP"p1 /mnt-efi 2>/dev/null && \
1082+
( [ -f /mnt-efi/EFI/BOOT/bootx64.efi ] && file /mnt-efi/EFI/BOOT/bootx64.efi || [ -f /mnt-efi/EFI/BOOT/shimx64.efi ] && file /mnt-efi/EFI/BOOT/shimx64.efi || echo "No bootx64.efi/shimx64.efi in ESP" ) && \
1083+
umount /mnt-efi 2>/dev/null; losetup -d "$$LOOP" 2>/dev/null ) || echo "EFI verification skipped (loop mount not available)"
10781084
END
10791085

10801086
SAVE ARTIFACT /kairos-dd.img AS LOCAL kairos-dd.img

overlay/files/curtin/curtin-hooks

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Responsibilities:
1414
"""
1515

1616
import os
17+
import re
1718
import sys
1819
import textwrap
1920

@@ -175,9 +176,12 @@ def fix_bootloader(target_disk):
175176
LOG.info("Mounting EFI partition %s to %s", efi_partition, efi_mount)
176177
subp(["mount", efi_partition, efi_mount])
177178

178-
# Look for GRUB EFI file
179-
# Common locations: EFI/BOOT/bootx64.efi, EFI/kairos/grubx64.efi, etc.
179+
# Look for EFI boot file. Prefer signed shim for Secure Boot compatibility.
180+
# "Platform does not support this image" on reboot-after-deploy is often
181+
# Secure Boot rejecting an unsigned loader; using shimx64.efi when present
182+
# ensures the signed chain (shim -> grub -> kernel) is used.
180183
efi_paths = [
184+
os.path.join(efi_mount, "EFI/BOOT/shimx64.efi"),
181185
os.path.join(efi_mount, "EFI/BOOT/bootx64.efi"),
182186
os.path.join(efi_mount, "EFI/kairos/grubx64.efi"),
183187
os.path.join(efi_mount, "EFI/BOOT/grubx64.efi"),
@@ -241,9 +245,8 @@ def fix_bootloader(target_disk):
241245
try:
242246
out, _ = subp(["efibootmgr"], capture=True)
243247
for line in out.splitlines():
244-
if "Kairos" in line or "kairos" in line:
248+
if "Kairos" in line or "kairos" in line:
245249
# Extract boot number (e.g., "Boot0001")
246-
import re
247250
match = re.search(r"Boot(\d{4})", line)
248251
if match:
249252
boot_num = match.group(1)
@@ -252,16 +255,36 @@ def fix_bootloader(target_disk):
252255
except Exception as e:
253256
LOG.warning("Failed to check/remove existing boot entries: %s", e)
254257

255-
# Create new boot entry
256-
subp([
258+
# Create new boot entry (efibootmgr -c prints the new BootXXXX line)
259+
out, _ = subp([
257260
"efibootmgr",
258261
"-c",
259262
"-d", disk_dev,
260263
"-p", part_num,
261264
"-L", "Kairos",
262265
"-l", efi_path_windows
263-
])
264-
LOG.info("UEFI boot entry created successfully")
266+
], capture=True)
267+
LOG.info("UEFI boot entry created: %s", out.strip() if out else "")
268+
269+
# Set this entry first in boot order so firmware uses it (avoids booting
270+
# another ESP with wrong/unsupported EFI and "Platform does not support this image")
271+
match = re.search(r"Boot(\d{4})", out or "")
272+
if match:
273+
new_boot = match.group(1)
274+
try:
275+
order_out, _ = subp(["efibootmgr"], capture=True)
276+
# Build new order: our entry first, then existing order without our entry
277+
existing = []
278+
for line in (order_out or "").splitlines():
279+
m = re.search(r"BootOrder is (.+)", line)
280+
if m:
281+
existing = [b for b in m.group(1).split(",") if b != new_boot]
282+
break
283+
new_order = ",".join([new_boot] + existing[:9])
284+
subp(["efibootmgr", "-o", new_order])
285+
LOG.info("Set Kairos (Boot%s) as first boot option", new_boot)
286+
except Exception as e:
287+
LOG.warning("Could not set boot order: %s", e)
265288
except Exception as e:
266289
LOG.warning("efibootmgr failed (may not be available or firmware issue): %s", e)
267290
LOG.info("Bootloader files are in place, but UEFI boot entry may need manual configuration")

0 commit comments

Comments
 (0)