This commit is contained in:
zj
2026-02-11 03:23:56 +08:00
parent cdb32839d5
commit d0210d6582
2 changed files with 24 additions and 1 deletions

Binary file not shown.

View File

@@ -394,10 +394,33 @@ def chroot_and_repair_grub(mount_point: str, target_disk: str,
# 1. 安装GRUB到目标磁盘 # 1. 安装GRUB到目标磁盘
if is_uefi: if is_uefi:
# UEFI模式首先尝试正常安装注册NVRAM启动项
success, _, stderr = run_command( success, _, stderr = run_command(
chroot_cmd_prefix + ["grub-install", "--target=x86_64-efi", chroot_cmd_prefix + ["grub-install", "--target=x86_64-efi",
"--efi-directory=/boot/efi", "--bootloader-id=GRUB"], "--efi-directory=/boot/efi", "--bootloader-id=GRUB"],
"安装UEFI GRUB" "安装UEFI GRUB带NVRAM"
)
# 如果失败是因为EFI变量不支持常见于Live环境修复外部磁盘使用 --no-nvram 重试
if not success and ("EFI variables are not supported" in stderr or
"efibootmgr" in stderr or
"NVRAM" in stderr):
print(f"[Backend] 警告: EFI变量访问失败尝试不使用NVRAM (--no-nvram) 安装...")
success, _, stderr = run_command(
chroot_cmd_prefix + ["grub-install", "--target=x86_64-efi",
"--efi-directory=/boot/efi", "--bootloader-id=GRUB",
"--no-nvram"],
"安装UEFI GRUB不带NVRAM"
)
# 如果仍然失败,尝试 --removable 选项(某些固件需要)
if not success:
print(f"[Backend] 警告: 标准安装失败,尝试 --removable 选项...")
success, _, stderr = run_command(
chroot_cmd_prefix + ["grub-install", "--target=x86_64-efi",
"--efi-directory=/boot/efi",
"--removable"],
"安装UEFI GRUB可移动模式"
) )
else: else:
success, _, stderr = run_command( success, _, stderr = run_command(