2
This commit is contained in:
53
backend.py
53
backend.py
@@ -1729,11 +1729,54 @@ def check_and_restore_kernel(mount_point: str, distro_type: str, has_separate_bo
|
||||
)
|
||||
elif distro_type in ["arch", "manjaro"]:
|
||||
# Arch 使用 mkinitcpio
|
||||
success, _, stderr = run_command(
|
||||
chroot_cmd_prefix + ["mkinitcpio", "-p", kernel_ver],
|
||||
f"生成 initramfs for {kernel_ver}",
|
||||
timeout=120
|
||||
)
|
||||
# 首先检查是否有 preset 文件
|
||||
preset_path = os.path.join(mount_point, f"etc/mkinitcpio.d/{kernel_ver}.preset")
|
||||
|
||||
if os.path.exists(preset_path):
|
||||
# 使用 preset 生成
|
||||
success, _, stderr = run_command(
|
||||
chroot_cmd_prefix + ["mkinitcpio", "-p", kernel_ver],
|
||||
f"生成 initramfs for {kernel_ver}",
|
||||
timeout=120
|
||||
)
|
||||
else:
|
||||
# 没有 preset 文件,直接生成 initramfs
|
||||
log_warning(f"没有找到 preset 文件,使用直接生成模式")
|
||||
initramfs_path = f"/boot/initramfs-{kernel_ver}.img"
|
||||
success, _, stderr = run_command(
|
||||
chroot_cmd_prefix + ["mkinitcpio", "-g", initramfs_path, "-k", kernel_ver],
|
||||
f"直接生成 initramfs for {kernel_ver}",
|
||||
timeout=120
|
||||
)
|
||||
|
||||
# 如果直接生成失败,尝试创建临时 preset
|
||||
if not success:
|
||||
log_info("尝试创建临时 preset 文件...")
|
||||
try:
|
||||
preset_dir = os.path.join(mount_point, "etc/mkinitcpio.d")
|
||||
os.makedirs(preset_dir, exist_ok=True)
|
||||
|
||||
# 创建基本 preset 文件
|
||||
preset_content = f"""# mkinitcpio preset file for {kernel_ver}
|
||||
ALL_config="/etc/mkinitcpio.conf"
|
||||
ALL_kver="{kernel_ver}"
|
||||
|
||||
PRESETS=('default')
|
||||
|
||||
default_image="/boot/initramfs-{kernel_ver}.img"
|
||||
"""
|
||||
with open(preset_path, 'w') as f:
|
||||
f.write(preset_content)
|
||||
log_info(f"✓ 创建临时 preset: {preset_path}")
|
||||
|
||||
# 再次尝试使用 preset 生成
|
||||
success, _, stderr = run_command(
|
||||
chroot_cmd_prefix + ["mkinitcpio", "-p", kernel_ver],
|
||||
f"使用临时 preset 生成 initramfs for {kernel_ver}",
|
||||
timeout=120
|
||||
)
|
||||
except Exception as e:
|
||||
log_warning(f"创建临时 preset 失败: {e}")
|
||||
else:
|
||||
# 通用方法:尝试 dracut
|
||||
success, _, stderr = run_command(
|
||||
|
||||
Reference in New Issue
Block a user