Where is the Ubuntu file system root directory in Windows Subsystem for Linux and vice versa?
Solution 1:
For Ubuntu installed from the Windows store:
Each distribution you install through the store is installed to that application's appdata directory. For example:
C:\Users\<username>\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState
- benhillis
For WSL2 you can access to home directory from windows (Windows 10 build 18342) like this :
\\wsl$
In earlier iterations of Windows Subsystem for Linux, the Ubuntu file system was at %localappdata%\Lxss
(e.g., C:\Users\Username\AppData\Local\Lxss
- replace the Username with your Username on Windows). See the WSL blog post on File System Support:
The primary file system used by WSL is VolFs. It is used to store the Linux system files, as well as the content of your Linux home directory. As such, VolFs supports most features the Linux VFS provides, including Linux permissions, symbolic links, FIFOs, sockets, and device files.
VolFs is used to mount the VFS root directory, using
%LocalAppData%\lxss\rootfs
as the backing storage. In addition, a few additional VolFs mount points exist, most notably/root
and/home
which are mounted using%LocalAppData%\lxss\root
and%LocalAppData%\lxss\home
respectively. The reason for these separate mounts is that when you uninstall WSL, the home directories are not removed by default, so any personal files stored there will be preserved.
CAUTION
Creating/modifying any files within the Linux subsystem using Windows apps & tools can cause Data corruption and data loss in Ubuntu subsystem! (Thanks to Rich Turner for suggesting these words of caution!) This is absolutely not supported. From the same blog post:
Interoperability with Windows
While VolFs files are stored in regular files on Windows in the directories mentioned above, interoperability with Windows is not supported. If a new file is added to one of these directories from Windows, it lacks the EAs needed by VolFs, so VolFs doesn’t know what to do with the file and simply ignores it. Many editors will also strip the EAs when saving an existing file, again making the file unusable in WSL.
Your Windows file system is located at /mnt/c
in the Bash shell environment.
Source: Dustin Kirkland's blog, howtogeek
Solution 2:
This seems to have changed since Bash was originally introduced, and does not apply to distributions from the Windows Store, or maybe it is not consistent for all systems as my home directory is located in another location:
%localappdata%\lxss\home\{username}
or:
C:\Users\{user}\AppData\Local\lxss\{username}
Where {user}
is your Windows Username and {username}
is your UNIX Username set during install.
So the root directory would be:
%localappdata%\lxss
Note that the root directory may not be visible in Windows Explorer from the %localappdata%
directory. You should be able to access it anyways by typing it in the 'address bar' of Explorer.
Solution 3:
If you install Linux from MS Market:
- Free Ubuntu in Windows store
- Free Open Suse in Windows store
they placed distros under:
$ 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
Default distro defined by:
bash# cat /proc/registry/HKEY_CURRENT_USER/Software/Microsoft/Windows/CurrentVersion/Lxss/DefaultDistribution
{861c29b4-ebe2-49a5-8a22-7e53a27934a0}
Linux root is deeper:
c:/Users/user/AppData/Local/Packages/46932SUSE.openSUSELeap42.2_022rs5jcyhyac/LocalState/rootfs
PS. I used Cygwin to explore registry keys.
If using PowerShell for the same goal, the commands would be:
# 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/
Solution 4:
You can quickly open Bash from a File Explorer window of the opened folder by typing bash
in the location bar.
It's enough.
Also you can add a context menu item. I personally don`t recommend it if not needed, because adding shortcuts to the context menu uses more RAM.
https://www.howtogeek.com/270810/how-to-quickly-launch-a-bash-shell-from-windows-10s-file-explorer/
Solution 5:
The only thing that worked for me was %localappdata%\lxss\home\{username}
, where the {username}
is your BASH username you gave it during the installation. For some reason, after showing hidden folder's lxss refuses to appear in C:\Users\WINDOWS-USER\AppData\Local\
, and also giving the full C:\
path with windows and BASH username does not work either.
And please create a desktop shortcut for what works.