fix2
This commit is contained in:
25
backend.py
25
backend.py
@@ -394,11 +394,34 @@ def chroot_and_repair_grub(mount_point: str, target_disk: str,
|
||||
|
||||
# 1. 安装GRUB到目标磁盘
|
||||
if is_uefi:
|
||||
# UEFI模式:首先尝试正常安装(注册NVRAM启动项)
|
||||
success, _, stderr = run_command(
|
||||
chroot_cmd_prefix + ["grub-install", "--target=x86_64-efi",
|
||||
"--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:
|
||||
success, _, stderr = run_command(
|
||||
chroot_cmd_prefix + ["grub-install", target_disk],
|
||||
|
||||
Reference in New Issue
Block a user