Fix UEFI GRUB installation: ensure ESP is mounted to /boot/efi and improve error logging
This commit is contained in:
@@ -66,6 +66,8 @@ def run_command(cmd, check=True):
|
||||
stderr_str = "".join(stderr_lines)
|
||||
|
||||
if check and returncode != 0:
|
||||
error_msg = f"Command '{' '.join(cmd)}' failed with exit code {returncode}\nStderr: {stderr_str}"
|
||||
log_to_discord("ERROR", error_msg, module="os_install")
|
||||
raise subprocess.CalledProcessError(
|
||||
returncode, cmd, output=stdout_str, stderr=stderr_str
|
||||
)
|
||||
@@ -95,7 +97,8 @@ def mount_pseudo_fs(mount_root):
|
||||
target = os.path.join(mount_root, "sys/firmware/efi/efivars")
|
||||
os.makedirs(target, exist_ok=True)
|
||||
try:
|
||||
run_command(["mount", "-t", "efivarfs", "efivarfs", target])
|
||||
# Use --bind if already mounted, or mount -t efivarfs
|
||||
run_command(["mount", "--bind", efivars_path, target])
|
||||
mounted_paths.append(target)
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to mount efivarfs: {e}")
|
||||
@@ -241,6 +244,15 @@ def configure_system(mount_root, partition_info, user_info=None, disk_device=Non
|
||||
with open(os.path.join(mount_root, "etc/fstab"), "w") as f:
|
||||
f.write("\n".join(fstab_lines) + "\n")
|
||||
|
||||
# Ensure EFI is mounted for GRUB installation
|
||||
if uefi and partition_info.get("efi"):
|
||||
efi_target = os.path.join(mount_root, "boot/efi")
|
||||
os.makedirs(efi_target, exist_ok=True)
|
||||
# Check if already mounted
|
||||
res = subprocess.run(["mount"], capture_output=True, text=True)
|
||||
if efi_target not in res.stdout:
|
||||
run_command(["mount", partition_info["efi"], efi_target])
|
||||
|
||||
with mount_pseudo_fs(mount_root):
|
||||
# 2. Configure User
|
||||
if user_info:
|
||||
@@ -295,4 +307,4 @@ def configure_system(mount_root, partition_info, user_info=None, disk_device=Non
|
||||
run_command(["sync"])
|
||||
|
||||
logger.info("System configuration complete.")
|
||||
log_os_install("CONFIGURE", "complete", "systemd-boot and user configured successfully")
|
||||
log_os_install("CONFIGURE", "complete", "GRUB2 and user configured successfully")
|
||||
|
||||
Reference in New Issue
Block a user