This commit is contained in:
zj
2026-02-11 23:23:48 +08:00
parent 9f86574ece
commit 85d0f00a48
4 changed files with 23 additions and 4 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -1232,7 +1232,8 @@ def chroot_and_repair_grub(mount_point: str, target_disk: str,
is_uefi: bool = False, distro_type: str = "unknown", is_uefi: bool = False, distro_type: str = "unknown",
install_hybrid: bool = False, install_hybrid: bool = False,
use_fallback: bool = True, 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修复命令。 Chroot到目标系统并执行GRUB修复命令。
支持多种安装模式、架构、EFI fallback、Secure Boot 等。 支持多种安装模式、架构、EFI fallback、Secure Boot 等。
@@ -1245,6 +1246,7 @@ def chroot_and_repair_grub(mount_point: str, target_disk: str,
install_hybrid: 是否同时安装 BIOS 和 EFI 模式(混合启动) install_hybrid: 是否同时安装 BIOS 和 EFI 模式(混合启动)
use_fallback: 是否安装 EFI fallback 文件 use_fallback: 是否安装 EFI fallback 文件
efi_bootloader_id: EFI 启动项名称 efi_bootloader_id: EFI 启动项名称
has_separate_boot: 是否有独立的 /boot 分区
""" """
global _grub_install_cmd, _grub_mkconfig_cmd 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-install: {_grub_install_cmd}")
log_info(f"使用 grub-mkconfig: {_grub_mkconfig_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] chroot_cmd_prefix = ["sudo", "chroot", mount_point]
# 检测 Live 环境 # 检测 Live 环境
@@ -1401,10 +1409,17 @@ def chroot_and_repair_grub(mount_point: str, target_disk: str,
_grub_install_cmd, _grub_install_cmd,
"--target=i386-pc", "--target=i386-pc",
"--recheck", "--recheck",
"--force", "--force"
target_disk
] ]
# 如果有独立的 /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( success, stdout, stderr = run_command(
bios_cmd, bios_cmd,
f"安装 BIOS GRUB 到 {target_disk}", f"安装 BIOS GRUB 到 {target_disk}",

View File

@@ -510,6 +510,9 @@ Secure Boot: {'已启用' if self.system_info.get('sb_enabled') else '已禁用/
self.log_message(f"EFI Fallback: {'' if use_fallback else ''}", "info") self.log_message(f"EFI Fallback: {'' if use_fallback else ''}", "info")
self.log_message(f"启动项名称: {bootloader_id}", "info") self.log_message(f"启动项名称: {bootloader_id}", "info")
# 检查是否有独立的 /boot 分区
has_separate_boot = self.selected_boot_partition_info is not None
repair_ok, repair_err = backend.chroot_and_repair_grub( repair_ok, repair_err = backend.chroot_and_repair_grub(
self.mount_point, self.mount_point,
target_disk_path or "", # UEFI 模式下可能为空 target_disk_path or "", # UEFI 模式下可能为空
@@ -517,7 +520,8 @@ Secure Boot: {'已启用' if self.system_info.get('sb_enabled') else '已禁用/
distro_type, distro_type,
install_hybrid=install_hybrid, install_hybrid=install_hybrid,
use_fallback=use_fallback, use_fallback=use_fallback,
efi_bootloader_id=bootloader_id efi_bootloader_id=bootloader_id,
has_separate_boot=has_separate_boot
) )
if not repair_ok: if not repair_ok: