关闭后在 WSL 上重新启动 Ubuntu 时出现多个 UtilTranslatePathList 错误

Not*_*1ds 3 shutdown systemd windows-subsystem-for-linux

在 WSL 中的 Ubuntu 中执行sudo systemctl poweroff并重新启动后,我看到:

<3>WSL (814) ERROR: UtilTranslatePathList:2671: Failed to translate C:\Program Files\PowerShell\7
<3>WSL (814) ERROR: UtilTranslatePathList:2671: Failed to translate C:\Windows\System32\OpenSSH\
<3>WSL (814) ERROR: UtilTranslatePathList:2671: Failed to translate C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common
<3>WSL (814) ERROR: UtilTranslatePathList:2671: Failed to translate C:\Program Files\dotnet\
...
Run Code Online (Sandbox Code Playgroud)

Ubuntu 启动,但没有 Windows 驱动器安装到 WSL 中。此外,Ubuntu 不久后就会退出。重新启动后,一切似乎都很好。

这是怎么回事?我该如何解决这个问题?

Not*_*1ds 5

简短回答:

  • 您仍然不应该在 WSL2 发行版上使用 Linux 关闭方法。
  • 您最终需要wsl --shutdown重新启动才能完全恢复。

更多细节:

在提供 Systemd 支持的更新后的 WSL 下,您现在可以运行某些“关闭”命令,但这并不意味着您应该这样做。这包括:

  • sudo systemctl poweroff
  • sudo systemctl halt
  • sudo systemctl reboot
  • 在桌面管理器(Gnome、Xfce4 等)中选择任何相关的关闭电源或重新启动选项。

在所有这些情况下,Systemd 都会将其自身替换为systemd-shutdown(有关更多详细信息,请参阅手册页),即使在 WSL 报告发行版不再运行后(通过wsl.exe -l -v),它也会继续运行。

我在这里做了一些猜测,但是当 WSL 尝试重新启动 Ubuntu 时,它似乎无法加载自己的,init因为 PID1 仍然被“占用” systemd-shutdown(或者可能是因为systemd不存在来调用它)。

$ ps -fp 1
UID          PID    PPID  C STIME TTY          TIME CMD
root           1       0  1 22:23 ?        00:00:00 /lib/systemd/systemd-shutdown halt --timeout 90000000us --log-level 6 --log-target console
Run Code Online (Sandbox Code Playgroud)

因此,大部分“正常”WSL 启动都不会发生。这包括 Windows 驱动器安装以及binfmt_misc允许 WSL 运行 Windows 命令的注册。但显然,这并不是尝试将 Windows 路径附加到基本环境中的 Linux 路径。

在您在上面的命令参数中看到的超时(90 秒)之后,systemd-shutdown将终止,并且 WSL 分发将随之终止(再次)。

您还可以从 PowerShell 终止wsl --terminate <distro_name>

无论哪种情况,新重新启动的 Ubuntu 都不会显示问题中列出的错误消息。

但是,您仍然需要wsl --shutdown重新启动才能重新获得运行 Windows 命令的能力。的“损坏”binfmt_misc实际上会扩展到系统上运行的所有WSL2 发行版,直到wsl --shutdown.