Fixing WSL 2.7.x `ERROR_FILE_NOT_FOUND` After an Update
Fixing WSL 2.7.x ERROR_FILE_NOT_FOUND After an Update
修复 WSL 2.7.x 更新后出现的 ERROR_FILE_NOT_FOUND 错误
Overview
概述
If you recently updated WSL to version 2.7.x and your distro suddenly fails to start with ERROR_FILE_NOT_FOUND, this article walks through how I diagnosed and fixed the problem.
如果你最近将 WSL 更新到了 2.7.x 版本,并且你的发行版突然无法启动并报错 ERROR_FILE_NOT_FOUND,本文将详细介绍我是如何诊断并解决这个问题的。
Spoiler
剧透
To save you time, here is the root cause of the error before we dive into the step-by-step fix. WSL relies on files installed under C:\Program Files\WSL. In this case, the WSL installation was missing system.vhd. The WSL VM therefore could not start because Hyper-V was instructed to attach a virtual disk that did not exist.
为了节省你的时间,在深入了解分步修复方案之前,先说明错误的根本原因:WSL 依赖于安装在 C:\Program Files\WSL 下的文件。在本例中,WSL 安装目录中丢失了 system.vhd 文件。因此,WSL 虚拟机无法启动,因为 Hyper-V 被要求挂载一个不存在的虚拟磁盘。
How I Fixed WSL 2.7.x ERROR_FILE_NOT_FOUND
我是如何修复 WSL 2.7.x ERROR_FILE_NOT_FOUND 错误的
Before we start, let’s get this out of the way: Important: This procedure repairs the WSL installation files; it does not unregister or delete your existing distributions. Avoid commands such as wsl --unregister unless you have confirmed that the distribution itself is corrupted and you have a backup.
在开始之前,先明确一点:重要提示:此过程仅修复 WSL 安装文件;它不会注销或删除你现有的发行版。除非你已确认发行版本身已损坏且拥有备份,否则请避免使用 wsl --unregister 等命令。
Assuming you are getting ERROR_FILE_NOT_FOUND, let’s first check the Windows services used by WSL:
假设你遇到了 ERROR_FILE_NOT_FOUND 错误,我们先检查 WSL 使用的 Windows 服务:
Get-Service vmcompute, Wslservice
Windows should display that they are running like the following: Windows 应该显示它们正在运行,如下所示:
Status Name DisplayName
------ ---- -----------
Running vmcompute Hyper-V Host Compute Service
Running Wslservice WSL Service
Next, let’s check if the required windows optional features are also installed and enabled by issuing: 接下来,通过执行以下命令检查所需的 Windows 可选功能是否已安装并启用:
Get-WindowsOptionalFeature -Online | Where-Object FeatureName -match 'VirtualMachinePlatform|Microsoft-Windows-Subsystem-Linux' | Select-Object FeatureName, State
If both features are enabled, we can move on to checking whether the WSL installation itself is missing a required file. 如果这两项功能都已启用,我们可以继续检查 WSL 安装本身是否缺少必要文件。
Test-Path "C:\Program Files\WSL\system.vhd"
On my affected installation, this returned False, confirming that system.vhd was missing from the WSL installation directory. If the file exists, we’re likely dealing with a different cause or a different missing file. In that case, the Hyper-V administrator logs can help identify what is actually missing:
在我受影响的安装中,该命令返回 False,确认 WSL 安装目录中确实丢失了 system.vhd。如果该文件存在,那么我们可能面临的是其他原因或丢失了其他文件。在这种情况下,Hyper-V 管理员日志可以帮助识别到底缺少什么:
Get-WinEvent -LogName "Microsoft-Windows-Hyper-V-Worker-Admin" -MaxEvents 20 | Select-Object TimeCreated, Id, LevelDisplayName, Message | Format-List
In my case, I got a list of events and I identified the following: 在我的案例中,我获取了一系列事件并识别出以下内容:
TimeCreated : xx/xx/2026 ...
Id : 12010
LevelDisplayName : Error
Message : 'A5071428-32C9-4D4D-A910-79D65B2C5FA5' Synthetic Storage (Instance ID FD1D2CBD-CE7C-535C-966B-EB5F811C95F0): Failed to Power on with Error 'The system cannot find the file specified. ' (0x80070002). (Virtual machine ID A5071428-32C9-4D4D-A910-79D65B2C5FA5)
TimeCreated : xx/xx/2026 ...
Id : 12240
LevelDisplayName : Error
Message : 'A5071428-32C9-4D4D-A910-79D65B2C5FA5': Attachment 'C:\Program Files\WSL\system.vhd (Lun 0)' could not be found due to error: 'The system cannot find the file specified. ' (7864368). (Virtual machine ID A5071428-32C9-4D4D-A910-79D65B2C5FA5)
The logs show that system.vhd is missing. You may encounter other missing files, such as modules.vhd. You can check which VHD files are present in the WSL installation directory with:
日志显示 system.vhd 丢失。你可能会遇到其他丢失的文件,例如 modules.vhd。你可以使用以下命令检查 WSL 安装目录中存在哪些 VHD 文件:
Get-ChildItem "C:\Program Files\WSL" -Recurse -Force -Filter "*.vhd" | Select-Object FullName, Length, LastWriteTime
Returning to my case (missing system.vhd), before starting some possible destructive operation, check that your distros are still here. Next, let’s move to fix the problem. First, let’s download the MSI WSL package where we can get the system.vhd from (or any other missing file). Before repairing the installation, I first extracted the MSI and verified that it actually contained system.vhd. This avoids attempting a repair with a package that doesn’t contain the file we’re looking for. Let’s check it by executing:
回到我的案例(丢失 system.vhd),在开始任何可能具有破坏性的操作之前,请确保你的发行版仍然存在。接下来,让我们着手解决问题。首先,下载 WSL 的 MSI 安装包,从中获取 system.vhd(或任何其他丢失的文件)。在修复安装之前,我先提取了 MSI 并验证它确实包含 system.vhd。这可以避免使用不包含目标文件的安装包进行修复。让我们通过执行以下命令进行检查:
$ msiexec.exe /a "$env:USERPROFILE\Downloads\wsl.2.7.12.0.x64.msi" /qn TARGETDIR="$env:TEMP\wsl-2.7.12-admin"
$ Get-ChildItem "$env:TEMP\wsl-2.7.12-admin" -Recurse -Force | Where-Object { $_.Name -match 'system\.vhd|modules\.vhd' } | Select-Object FullName, Length
The first command executes an “administrative installation” (/a flag) in the target directory. Think of it as extracting files while respecting installation rules. The /qn means to do it silently without UI. The second command searches for system and module vhd files. After checking that system.vhd exists in the msi file, we issue the following commands:
第一条命令在目标目录中执行“管理安装”(/a 标志)。可以将其视为在遵守安装规则的同时提取文件。/qn 表示静默执行,不显示用户界面。第二条命令搜索系统和模块 vhd 文件。确认 system.vhd 存在于 MSI 文件中后,我们执行以下命令:
$ wsl --shutdown
$ msiexec.exe /fa "$env:USERPROFILE\Downloads\wsl.2.7.12.0.x64.msi" /qn /norestart /l*v "$env:TEMP\wsl-repair.log"
This tells Windows to stop WSL. Then it forces Windows Installer to repair the existing WSL installation. The /fa option tells Windows Installer to repair/reinstall all files from the msi file. /norestart means don’t reboot Windows automatically. /l*v tells Windows Installer to write the verbose repair log to the specified file.
这会通知 Windows 停止 WSL,然后强制 Windows 安装程序修复现有的 WSL 安装。/fa 选项告诉 Windows 安装程序修复/重新安装 MSI 文件中的所有文件。/norestart 表示不要自动重启 Windows。/l*v 告诉 Windows 安装程序将详细的修复日志写入指定文件。
Finally, we check if system.vhd is under WSL install folder:
最后,我们检查 system.vhd 是否已出现在 WSL 安装文件夹中:
Test-Path "C:\Program Files\WSL\system.vhd"
And we should get True. Last thing is to launch your wsl distro:
我们应该得到 True。最后一步是启动你的 WSL 发行版:
wsl -d Ubuntu-26.04
And voila! Fixed! You should have access to your distro terminal now. 搞定!修复成功!现在你应该可以访问你的发行版终端了。
Conclusion
结论
We saw multiple interesting commands that can be useful in other fixing/troubleshooting scenarios. Especially, the msi ones where we can repair already installed app. 我们了解了多个有趣的命令,它们在其他修复/故障排除场景中也非常有用。特别是那些可以修复已安装应用程序的 MSI 相关命令。