diff --git a/__pycache__/backend.cpython-39.pyc b/__pycache__/backend.cpython-39.pyc index 1fad2ed..2345c4b 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 3485fec..5ab4f82 100644 --- a/backend.py +++ b/backend.py @@ -1194,6 +1194,16 @@ def check_and_install_efi_modules(mount_point: str, distro_type: str, is_uefi: b log_warning(f"未知的发行版 '{distro_type}',无法自动安装 EFI 模块") return False, f"无法确定 {distro_type} 的 EFI 包名" + # 安装 EFI 包前,先确保网络连接(复制 DNS 配置) + resolv_source = "/etc/resolv.conf" + resolv_target = os.path.join(mount_point, "etc/resolv.conf") + if os.path.exists(resolv_source): + try: + shutil.copy2(resolv_source, resolv_target) + log_info("已复制 DNS 配置到 chroot 环境") + except Exception as e: + log_debug(f"复制 DNS 配置失败: {e}") + # 安装 EFI 包 if distro_type in ["centos", "rhel", "fedora", "rocky", "almalinux"]: success, _, stderr = run_command( @@ -1202,6 +1212,11 @@ def check_and_install_efi_modules(mount_point: str, distro_type: str, is_uefi: b timeout=300 ) elif distro_type in ["debian", "ubuntu"]: + success, _, stderr = run_command( + chroot_cmd_prefix + ["apt-get", "update"], + f"更新包列表", + timeout=120 + ) success, _, stderr = run_command( chroot_cmd_prefix + ["apt-get", "install", "-y"] + efi_packages, f"安装 UEFI GRUB 包", @@ -1209,7 +1224,7 @@ def check_and_install_efi_modules(mount_point: str, distro_type: str, is_uefi: b ) elif distro_type in ["arch", "manjaro"]: success, _, stderr = run_command( - chroot_cmd_prefix + ["pacman", "-S", "--noconfirm"] + efi_packages, + chroot_cmd_prefix + ["pacman", "-Sy", "--noconfirm"] + efi_packages, f"安装 UEFI GRUB 包", timeout=300 )