3
This commit is contained in:
21
backend.py
21
backend.py
@@ -1232,7 +1232,8 @@ def chroot_and_repair_grub(mount_point: str, target_disk: str,
|
||||
is_uefi: bool = False, distro_type: str = "unknown",
|
||||
install_hybrid: bool = False,
|
||||
use_fallback: bool = True,
|
||||
efi_bootloader_id: str = "GRUB") -> Tuple[bool, str]:
|
||||
efi_bootloader_id: str = "GRUB",
|
||||
has_separate_boot: bool = False) -> Tuple[bool, str]:
|
||||
"""
|
||||
Chroot到目标系统并执行GRUB修复命令。
|
||||
支持多种安装模式、架构、EFI fallback、Secure Boot 等。
|
||||
@@ -1245,6 +1246,7 @@ def chroot_and_repair_grub(mount_point: str, target_disk: str,
|
||||
install_hybrid: 是否同时安装 BIOS 和 EFI 模式(混合启动)
|
||||
use_fallback: 是否安装 EFI fallback 文件
|
||||
efi_bootloader_id: EFI 启动项名称
|
||||
has_separate_boot: 是否有独立的 /boot 分区
|
||||
"""
|
||||
global _grub_install_cmd, _grub_mkconfig_cmd
|
||||
|
||||
@@ -1266,6 +1268,12 @@ def chroot_and_repair_grub(mount_point: str, target_disk: str,
|
||||
log_info(f"使用 grub-install: {_grub_install_cmd}")
|
||||
log_info(f"使用 grub-mkconfig: {_grub_mkconfig_cmd}")
|
||||
|
||||
# 检查是否有独立的 /boot 分区
|
||||
boot_mount_point = os.path.join(mount_point, "boot")
|
||||
if os.path.ismount(boot_mount_point):
|
||||
has_separate_boot = True
|
||||
log_info("检测到独立的 /boot 分区")
|
||||
|
||||
chroot_cmd_prefix = ["sudo", "chroot", mount_point]
|
||||
|
||||
# 检测 Live 环境
|
||||
@@ -1401,10 +1409,17 @@ def chroot_and_repair_grub(mount_point: str, target_disk: str,
|
||||
_grub_install_cmd,
|
||||
"--target=i386-pc",
|
||||
"--recheck",
|
||||
"--force",
|
||||
target_disk
|
||||
"--force"
|
||||
]
|
||||
|
||||
# 如果有独立的 /boot 分区,需要指定 --boot-directory
|
||||
# 这样 GRUB 才能在启动时正确找到配置文件
|
||||
if has_separate_boot:
|
||||
log_info("独立 /boot 分区: 添加 --boot-directory=/boot 参数")
|
||||
bios_cmd.append("--boot-directory=/boot")
|
||||
|
||||
bios_cmd.append(target_disk)
|
||||
|
||||
success, stdout, stderr = run_command(
|
||||
bios_cmd,
|
||||
f"安装 BIOS GRUB 到 {target_disk}",
|
||||
|
||||
Reference in New Issue
Block a user