3
This commit is contained in:
Binary file not shown.
BIN
__pycache__/frontend.cpython-39.pyc
Normal file
BIN
__pycache__/frontend.cpython-39.pyc
Normal file
Binary file not shown.
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}",
|
||||
|
||||
@@ -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"启动项名称: {bootloader_id}", "info")
|
||||
|
||||
# 检查是否有独立的 /boot 分区
|
||||
has_separate_boot = self.selected_boot_partition_info is not None
|
||||
|
||||
repair_ok, repair_err = backend.chroot_and_repair_grub(
|
||||
self.mount_point,
|
||||
target_disk_path or "", # UEFI 模式下可能为空
|
||||
@@ -517,7 +520,8 @@ Secure Boot: {'已启用' if self.system_info.get('sb_enabled') else '已禁用/
|
||||
distro_type,
|
||||
install_hybrid=install_hybrid,
|
||||
use_fallback=use_fallback,
|
||||
efi_bootloader_id=bootloader_id
|
||||
efi_bootloader_id=bootloader_id,
|
||||
has_separate_boot=has_separate_boot
|
||||
)
|
||||
|
||||
if not repair_ok:
|
||||
|
||||
Reference in New Issue
Block a user