From bd3c09ebf474a5d3417393ebbf1aa671c001de0a Mon Sep 17 00:00:00 2001 From: zj <1052308357@qq.com> Date: Thu, 12 Feb 2026 03:07:06 +0800 Subject: [PATCH] 15 --- backend.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/backend.py b/backend.py index 2b0f0e7..ccca45a 100644 --- a/backend.py +++ b/backend.py @@ -2137,20 +2137,32 @@ def chroot_and_repair_grub(mount_point: str, target_disk: str, log_step("更新 GRUB 配置文件") # 确定配置文件路径 + # 根据发行版类型确定正确的 GRUB 目录名 + if distro_type in ["centos", "rhel", "fedora", "rocky", "almalinux", "opensuse"]: + # RHEL 系使用 grub2 + preferred_grub_dir = "grub2" + fallback_grub_dir = "grub" + else: + # Debian/Ubuntu/Arch 等使用 grub + preferred_grub_dir = "grub" + fallback_grub_dir = "grub2" + possible_config_paths = [ - "/boot/grub/grub.cfg", - "/boot/grub2/grub.cfg", + f"/boot/{preferred_grub_dir}/grub.cfg", + f"/boot/{fallback_grub_dir}/grub.cfg", ] config_path = "" for cfg_path in possible_config_paths: full_path = os.path.join(mount_point, cfg_path.lstrip('/')) + # 优先检查目录是否存在,但也考虑发行版偏好 if os.path.exists(os.path.dirname(full_path)): config_path = cfg_path break + # 如果没有找到,使用发行版偏好路径 if not config_path: - config_path = "/boot/grub/grub.cfg" + config_path = f"/boot/{preferred_grub_dir}/grub.cfg" # 确定更新命令 if distro_type in ["debian", "ubuntu"]: