15
This commit is contained in:
18
backend.py
18
backend.py
@@ -2137,20 +2137,32 @@ def chroot_and_repair_grub(mount_point: str, target_disk: str,
|
|||||||
log_step("更新 GRUB 配置文件")
|
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 = [
|
possible_config_paths = [
|
||||||
"/boot/grub/grub.cfg",
|
f"/boot/{preferred_grub_dir}/grub.cfg",
|
||||||
"/boot/grub2/grub.cfg",
|
f"/boot/{fallback_grub_dir}/grub.cfg",
|
||||||
]
|
]
|
||||||
|
|
||||||
config_path = ""
|
config_path = ""
|
||||||
for cfg_path in possible_config_paths:
|
for cfg_path in possible_config_paths:
|
||||||
full_path = os.path.join(mount_point, cfg_path.lstrip('/'))
|
full_path = os.path.join(mount_point, cfg_path.lstrip('/'))
|
||||||
|
# 优先检查目录是否存在,但也考虑发行版偏好
|
||||||
if os.path.exists(os.path.dirname(full_path)):
|
if os.path.exists(os.path.dirname(full_path)):
|
||||||
config_path = cfg_path
|
config_path = cfg_path
|
||||||
break
|
break
|
||||||
|
|
||||||
|
# 如果没有找到,使用发行版偏好路径
|
||||||
if not config_path:
|
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"]:
|
if distro_type in ["debian", "ubuntu"]:
|
||||||
|
|||||||
Reference in New Issue
Block a user