在Windows Subsystem for Linux中,Ubuntu文件系统根目录在哪里,反之亦然?

我在Windows 10上安装了Ubuntu子系统(在设置中启用该功能后),但Ubuntu文件系统根目录在驱动器中位于何处?

对该问题的评论 (13)
解决办法

对于从Windows商店安装的Ubuntu。

你通过商店安装的每个发行版都会安装到该 应用程序的appdata目录。比如说。 C:\Users\lt;username>\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState- benhillis

对于WSL2,你可以从Windows(Windows 10 build 18342)访问主目录,像这样。

\\wsl$

在Windows Subsystem for Linux的早期版本中,Ubuntu的文件系统在%localappdata%\Lxss(例如,C:\Users\Username\AppData\Local\Lxss - 在Windows中用你的用户名替换Username)。见WSL博客中关于文件系统支持的文章

WSL使用的主要文件系统是VolFs。它是用来存储 Linux系统文件,以及你的Linux主目录的内容。 目录的内容。因此,VolFs支持大多数的Linux VFS 提供的,包括Linux权限、符号链接、FIFO、套接字。 和设备文件。

VolFs被用来挂载VFS根目录,使用 %LocalAppData%\lxss\rootfs作为支持存储。此外,一个 还有一些额外的VolFs挂载点存在,最明显的是/root/home,它们使用%LocalAppData%\lxssroot/home挂载。 %LocalAppData%\lxss\home分别挂载。之所以使用这些独立的 的原因是,当你卸载WSL时,主目录不会被默认删除。 移除,所以存储在那里的任何个人文件都会被保留下来。 保留下来。

注意

在Linux子系统中使用Windows应用程序&工具创建/修改任何文件都会导致Ubuntu子系统的数据损坏和数据丢失!(感谢Rich Turner提出的这些建议!)这将导致Ubuntu子系统的数据丢失。(感谢Rich Turner提出的这些警告!) 这绝对是不支持的。来自同一篇博客文章。

与Windows的互操作性

虽然VolFs文件在Windows上是以普通文件的形式存储在上述的 上面提到的目录,与Windows的互操作性是不 支持。如果一个新的文件被添加到这些目录中,从 如果一个新的文件被添加到这些目录中,它缺乏VolFs所需要的EA,所以VolFs不知道该如何处理这个文件。 所以VolFs不知道该如何处理这个文件,只是简单地忽略它。许多编辑器也会 在保存一个现有的文件时,将EA剥离,这又使该文件 在WSL中无法使用。


你的Windows文件系统在Bash shell环境中位于/mnt/c

![在此输入图像描述][3]

来源。Dustin Kirkland'的博客, howtogeek

评论(21)

自从Bash最初问世以来,这一点似乎已经发生了变化,并且不适用于来自Windows商店的发行版,也可能不是对所有系统都一致,因为我的主目录位于另一个地方。

%localappdata%\lxss\home\{username}

或。

C:\Users\{user}\AppData\Local\lxss\{username}

其中{user}是您的Windows用户名,{username}是您在安装时设置的UNIX用户名。

所以根目录应该是:

%localappdata%\lxss

请注意,根目录在Windows Explorer中可能无法从%localappdata%目录看到。无论如何,你应该能够通过在资源管理器的'地址栏中输入它来访问它。

评论(7)

如果你从MS Market安装Linux。

他们将 distros 放在。

$ cat /proc/registry/HKEY_CURRENT_USER/Software/Microsoft/Windows/CurrentVersion/Lxss/\{861c29b4-ebe2-49a5-8a22-7e53a27934a0\}/BasePath
C:\Users\user\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState

默认发行版的定义是:

bash# cat /proc/registry/HKEY_CURRENT_USER/Software/Microsoft/Windows/CurrentVersion/Lxss/DefaultDistribution
{861c29b4-ebe2-49a5-8a22-7e53a27934a0}
bash# cat /proc/registry/HKEY_CURRENT_USER/Software/Microsoft/Windows/CurrentVersion/Lxss/DefaultDistribution
{861c29b4-ebe2-49a5-8a22-7e53a27934a0}

Linux根基较深。

c:/Users/user/AppData/Local/Packages/46932SUSE.openSUSELeap42.2_022rs5jcyhyac/LocalState/rootfs

PS.我用Cygwin探索注册表键。 我使用Cygwin来探索注册表键。

如果使用PowerShell来实现同样的目标,命令应该是:

# obtain the value of the ID of the default Linux distribution (and store it in a variable to avoid escaping characters issues):
$DEFAULT_LXSS_ID = (Get-ItemPropertyValue -Path REGISTRY::HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss\ -name DefaultDistribution)

# which will have a value like:
echo  $DEFAULT_LXSS_ID
{bde539d6-0c87-4e12-9599-1dcd623fbf07}

# display the directory containing the rootfs Windows directory (mapped to the / Linux directory)
Get-ItemPropertyValue -Path REGISTRY::HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss\$DEFAULT_LXSS_ID -name BasePath | Format-List -property "BasePath"
%LocalAppData%\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState

# obtain the value of the ID of the default Linux distribution (and store it in a variable to avoid escaping characters issues):
$DEFAULT_LXSS_ID = (Get-ItemPropertyValue -Path REGISTRY::HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss\ -name DefaultDistribution)

# which will have a value like:
echo  $DEFAULT_LXSS_ID
{bde539d6-0c87-4e12-9599-1dcd623fbf07}

# display the directory containing the rootfs Windows directory (mapped to the / Linux directory)
Get-ItemPropertyValue -Path REGISTRY::HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss\$DEFAULT_LXSS_ID -name BasePath | Format-List -property "BasePath"
%LocalAppData%\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState

PPS. https://blogs.msdn.microsoft.com/commandline/2016/11/17/do-not-change-linux-files-using-windows-apps-and-tools/

评论(0)

唯一对我有效的是%localappdata%/lxss/home/{username},其中{username}是你在安装时给的BASH用户名。 不知为什么,显示隐藏文件夹后'的lxss拒绝出现在C:/Users/WINDOWS-USER/AppData/Local/中,同时给出完整的C:/路径与windows和BASH用户名也不行。

还请你建立一个桌面快捷方式来解决什么问题。

评论(1)

你可以在打开的文件夹的文件资源管理器窗口中通过在位置栏中输入bash来快速打开Bash。

这就够了。

你也可以添加一个上下文菜单项。如果不需要的话,我个人不建议这样做,因为在上下文菜单中添加快捷方式会占用更多的内存。

https://www.howtogeek.com/270810/how-to-quickly-launch-a-bash-shell-from-windows-10s-file-explorer/

评论(3)