Fix UEFI boot by mounting efivarfs and forcing systemd-boot install
This commit is contained in:
@@ -76,7 +76,7 @@ def run_command(cmd, check=True):
|
||||
@contextmanager
|
||||
def mount_pseudo_fs(mount_root):
|
||||
"""
|
||||
Context manager to bind mount /dev, /proc, and /sys into mount_root.
|
||||
Context manager to bind mount /dev, /proc, /sys, and efivarfs into mount_root.
|
||||
"""
|
||||
logger.info(f"Mounting pseudo-filesystems to {mount_root}...")
|
||||
mounts = ["dev", "proc", "sys"]
|
||||
@@ -88,6 +88,18 @@ def mount_pseudo_fs(mount_root):
|
||||
os.makedirs(target, exist_ok=True)
|
||||
run_command(["mount", "--bind", f"/{fs}", target])
|
||||
mounted_paths.append(target)
|
||||
|
||||
# Mount efivarfs if it exists on the host
|
||||
efivars_path = "/sys/firmware/efi/efivars"
|
||||
if os.path.exists(efivars_path):
|
||||
target = os.path.join(mount_root, "sys/firmware/efi/efivars")
|
||||
os.makedirs(target, exist_ok=True)
|
||||
try:
|
||||
run_command(["mount", "-t", "efivarfs", "efivarfs", target])
|
||||
mounted_paths.append(target)
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to mount efivarfs: {e}")
|
||||
|
||||
yield
|
||||
finally:
|
||||
logger.info(f"Unmounting pseudo-filesystems from {mount_root}...")
|
||||
@@ -111,6 +123,7 @@ def install_minimal_os(mount_root, releasever="43"):
|
||||
"coreutils",
|
||||
"kernel",
|
||||
"systemd",
|
||||
"systemd-boot-unsigned",
|
||||
"dnf",
|
||||
"efibootmgr",
|
||||
"passwd",
|
||||
@@ -211,10 +224,13 @@ UUID={efi_uuid} /boot vfat defaults 0 2
|
||||
os.makedirs(os.path.join(mount_root, "etc/kernel"), exist_ok=True)
|
||||
with open(os.path.join(mount_root, "etc/kernel/cmdline"), "w") as f:
|
||||
f.write(f"root=UUID={root_uuid} rw quiet\n")
|
||||
|
||||
# Set kernel layout to BLS for systemd-boot
|
||||
with open(os.path.join(mount_root, "etc/kernel/layout"), "w") as f:
|
||||
f.write("bls\n")
|
||||
|
||||
# Install systemd-boot to the ESP (mounted at /boot)
|
||||
# Use --path=/boot to be explicit, though standard behavior usually finds it.
|
||||
run_command(["chroot", mount_root, "bootctl", "install", "--path=/boot"])
|
||||
run_command(["chroot", mount_root, "bootctl", "install", "--path=/boot", "--force"])
|
||||
|
||||
# Add kernel entries
|
||||
modules_dir = os.path.join(mount_root, "lib/modules")
|
||||
@@ -240,6 +256,9 @@ UUID={efi_uuid} /boot vfat defaults 0 2
|
||||
cmd.append(initrd_arg)
|
||||
|
||||
run_command(cmd)
|
||||
|
||||
# Ensure all data is synced to disk
|
||||
run_command(["sync"])
|
||||
|
||||
logger.info("System configuration complete.")
|
||||
log_os_install("CONFIGURE", "complete", "systemd-boot and user configured successfully")
|
||||
|
||||
Reference in New Issue
Block a user