diff --git a/__pycache__/backend.cpython-39.pyc b/__pycache__/backend.cpython-39.pyc index 0fb80e0..6b5029b 100644 Binary files a/__pycache__/backend.cpython-39.pyc and b/__pycache__/backend.cpython-39.pyc differ diff --git a/backend.py b/backend.py index a1d1a32..efa6ae4 100644 --- a/backend.py +++ b/backend.py @@ -1272,11 +1272,12 @@ def _manual_install_efi_files(mount_point: str, efi_target: str, efi_grub_file: # 可能的源路径: source_paths = [] - # 1. 从 /boot/efi/EFI/centos 或 /boot/efi/EFI/redhat 复制 - for subdir in ["centos", "redhat", "fedora", "rocky", "almalinux", "boot"]: + # 1. 从 /boot/efi/EFI/ 复制 + for subdir in ["centos", "redhat", "fedora", "rocky", "almalinux", "BOOT", "boot"]: source_paths.append(os.path.join(efi_firmware_dir, subdir, efi_grub_file)) source_paths.append(os.path.join(efi_firmware_dir, subdir, "shimx64.efi")) source_paths.append(os.path.join(efi_firmware_dir, subdir, "shim.efi")) + source_paths.append(os.path.join(efi_firmware_dir, subdir, "grubx64.efi")) # 2. 从 /boot/efi/ 直接查找 source_paths.append(os.path.join(mount_point, "boot/efi", efi_grub_file)) @@ -1286,6 +1287,21 @@ def _manual_install_efi_files(mount_point: str, efi_target: str, efi_grub_file: grub_modules_dir = os.path.join(mount_point, f"usr/lib/grub/{efi_target}") source_paths.append(os.path.join(grub_modules_dir, "grubx64.efi")) + # 4. CentOS/RHEL 特定的路径 + source_paths.append(os.path.join(mount_point, "boot/efi/EFI/centos/grubx64.efi")) + source_paths.append(os.path.join(mount_point, "boot/efi/EFI/centos/shimx64.efi")) + source_paths.append(os.path.join(mount_point, "usr/share/grub2/grubx64.efi")) + + # 5. 尝试查找任何 .efi 文件 + try: + if os.path.exists(efi_firmware_dir): + for root, dirs, files in os.walk(efi_firmware_dir): + for f in files: + if f.endswith('.efi'): + source_paths.append(os.path.join(root, f)) + except: + pass + # 查找 shim 和 grub shim_source = None grub_source = None @@ -1320,17 +1336,17 @@ def _manual_install_efi_files(mount_point: str, efi_target: str, efi_grub_file: if not grub_source and not shim_source: log_warning("未找到现有 EFI 文件,尝试使用 grub-mkimage 生成...") - # 构建 grub.efi 路径 - grub_efi_output = os.path.join(target_dir, efi_grub_file) - # 获取模块列表(必需模块) modules = "part_gpt part_msdos fat ext2 xfs btrfs normal boot linux configfile search search_fs_uuid search_fs_file" + # 构建 chroot 内的输出路径 + chroot_output_path = f"/boot/efi/EFI/{efi_bootloader_id}/{efi_grub_file}" + # 尝试使用 grub-mkimage 生成 EFI 文件 chroot_cmd_prefix = ["sudo", "chroot", mount_point] mkimage_cmd = chroot_cmd_prefix + [ "grub2-mkimage", - "-o", grub_efi_output, + "-o", chroot_output_path, "-O", efi_target, "-p", "/boot/grub2", ] + modules.split() @@ -1341,8 +1357,10 @@ def _manual_install_efi_files(mount_point: str, efi_target: str, efi_grub_file: timeout=60 ) - if success and os.path.exists(grub_efi_output): - log_success(f"✓ 成功生成 EFI 文件: {grub_efi_output}") + # 检查主机路径上的文件是否生成成功 + host_output_path = os.path.join(mount_point, chroot_output_path.lstrip('/')) + if success and os.path.exists(host_output_path): + log_success(f"✓ 成功生成 EFI 文件: {host_output_path}") else: log_error(f"生成 EFI 文件失败: {stderr}") return False