"Windows Subsystem for Linux has no installed distributions" 即使安装了 'Ubuntu'

"Windows Subsystem for Linux has no installed distributions" even though 'Ubuntu' is installed

我最近将我的 wsl 目录移动到另一个驱动器,因为 C: 驱动器中的存储空间不足。根据 中提供的答案,我使用了 lxrunoffline 工具并将我的 Ubuntu 分发移动到另一个驱动器(我的 E:\wsl案件)。分发成功后,我 运行 wsl 进行了测试,效果非常好。

一切都很顺利,直到有一天我不小心将 E:\wsl 文件夹重命名为其他文件夹。好吧,正如预期的那样,wsl 没有起作用。然后,我恢复到名称 wsl 并希望它能正常工作,但令我惊讶的是,即使它已安装,它也没有找到任何已安装的发行版...

E:> wsl
Windows Subsystem for Linux has no installed distributions.
Distributions can be installed by visiting the Microsoft Store:
https://aka.ms/wslstore

有没有办法恢复到旧目录或使 wsl 指向手动位置?

编辑: 我不想重置 Ubuntu 因为我想保留已安装的软件包和首选项...

好吧,我终于找到了解决这个问题的方法。

这就像使用 rgregister 命令使用 lxrunoffline 工具注册发行版一样简单。

E:\LxRunOffline\LxRunOffline-v3.3.3>lxrunoffline rg
[ERROR] the option '-d' is required but missing

Options:
  -n arg                Name of the distribution
  -d arg                The directory containing the distribution.
  -c arg                The config file to use. This argument is optional.

在 运行 register 命令后,我能够像往常一样启动 wsl。但这将使您以 "root" 用户身份登录,因此将从“/root”目录开始。我 运行 以下命令以不同的用户身份启动 wsl(这是针对 Ubuntu):

ubuntu config --default-user <user-name>