12
This commit is contained in:
12
backend.py
12
backend.py
@@ -2174,6 +2174,16 @@ def chroot_and_repair_grub(mount_point: str, target_disk: str,
|
||||
if not os.path.exists(grubenv_path):
|
||||
log_info(f"grubenv 文件不存在,尝试创建...")
|
||||
|
||||
# 首先确保目录存在(在 chroot 环境中创建)
|
||||
grubenv_dir_in_chroot = os.path.dirname(config_path) # /boot/grub2 或 /boot/grub
|
||||
success, _, _ = run_command(
|
||||
chroot_cmd_prefix + ["mkdir", "-p", grubenv_dir_in_chroot],
|
||||
"创建 GRUB 配置目录",
|
||||
timeout=5
|
||||
)
|
||||
if success:
|
||||
log_info(f"✓ 创建目录: {grubenv_dir_in_chroot}")
|
||||
|
||||
# 方法1: 使用 grub2-editenv 创建
|
||||
editenv_cmd = None
|
||||
for cmd_name in ["grub2-editenv", "grub-editenv"]:
|
||||
@@ -2187,7 +2197,7 @@ def chroot_and_repair_grub(mount_point: str, target_disk: str,
|
||||
|
||||
if editenv_cmd:
|
||||
success, _, stderr = run_command(
|
||||
chroot_cmd_prefix + [editenv_cmd, "/boot/grub2/grubenv", "create"],
|
||||
chroot_cmd_prefix + [editenv_cmd, grubenv_dir_in_chroot + "/grubenv", "create"],
|
||||
"创建 grubenv 文件",
|
||||
timeout=10
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user