24
15
It's pretty clear that Windows' 10 "host" filesystem is mounted at /mnt/c/
from "Linux" perspective of view. But is it possible to get an access to "Linux" filesystem from Windows? If so, where it is?
24
15
It's pretty clear that Windows' 10 "host" filesystem is mounted at /mnt/c/
from "Linux" perspective of view. But is it possible to get an access to "Linux" filesystem from Windows? If so, where it is?
26
The single root file system was located here until Windows 10 Fall Creators update (released in Oct. 2017):
%LOCALAPPDATA%\Lxss\rootfs
For example, C:\Users\Vigo\AppData\Local\Lxss\rootfs\
Other mount points are located one level up in the lxss
directory. For example, your own home
directory within Linux will be in %LOCALAPPDATA%\Lxss\home
.
Starting from the Fall Creators update, it is possible to install more than one instance of Linux and run them in parallel. The existing instance (a.k.a. legacy) will stay in its directory but new instances created are located under:
%LOCALAPPDATA%\Packages\<distribution_specific_name>_<random_string>\LocalState\rootfs
For example, my Ubuntu 18.04 installation is located under the
CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgscdirectory.
Warning: Beware not to create, modify or delete files located under the lxss or distribution specific tree from Windows.
Exploring and reading files is the only harmless operation. See this Microsoft blog page for details.
Note that starting from Build 1903, there is an alternative way to access the files of a running distribution that doesn't exhibit the previously mentioned issues.
Just use the path \\wsl$\<distribution_specific_name>\
and you'll be able to create and modify files. The AppData is still not a supported way to access files with build 1903.
It was hidden :) – Y2K – 2016-05-15T13:03:48.477
I cannot add it to Quick Access of Windows Explorer as a bookmark to find it easy. – john – 2016-05-16T16:07:09.777
4A user-neutral copy-paste-able version: %USERPROFILE%\AppData\Local\Lxss\rootfs
– Silveri – 2016-08-03T09:04:57.697
3
Warning: According to Microsoft, you should not modify your linux filesystem using Windows applications. https://blogs.msdn.microsoft.com/commandline/2016/11/17/do-not-change-linux-files-using-windows-apps-and-tools/
– Korey – 2017-11-30T20:12:50.310@Korey Thanks for reminding that point, answer updated. – jlliagre – 2017-11-30T20:55:10.580
Even reading is not necessarily harmless. As the MS blog post mentions, some programs will lock (or even modify) files on 'open', i.e. it's not truly read-only. The only safe-ish operation I can think of is copying the file elsewhere, and even that depends on what you use to copy it (I believe open for reading will lock against deletion?). Better to not touch it at all - use WSL to copy to a DrvFs mountpoint. I feel like your warning should be more prominent and at the start of the answer - there is almost never a good reason to do anything beyond deleting the entire directory. – Bob – 2018-08-06T01:36:51.070
1You can simplify the first part of that path a lot by using %LOCALAPPDATA%
instead of %USERPROFILE%\AppData\Local
– Herohtar – 2019-10-18T02:12:20.840
@Herohtar Thanks, updated. – jlliagre – 2019-10-18T05:37:28.733
8
Nowadays, you can install multiple Linux distributions. Therefore, each distribution will have their own filesystem located in a different folder.
%USERPROFILE%\AppData\Local\Packages\...\LocalState\rootfs
Obtaining the information from the Registry
The location of each filesystem can be obtained from the Windows Registry. The data is located under
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss
You can start a PowerShell window and execute the following command to obtain the locations of the filesystems
PS> (Get-ChildItem HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss | ForEach-Object {Get-ItemProperty $_.PSPath}) | select DistributionName, @{n="Path";e={$_.BasePath + "\rootfs"}}
You will get a table with information like the following
DistributionName Path
---------------- ----
Ubuntu C:\Users\Jaime\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs
Ubuntu-18.04 C:\Users\Jaime\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState\rootfs
mydistro C:\wsl\mydistro\rootfs
Using lxRunOffline
LxRunOffline is a tool for managing linux distributions installed on WSL. You can use LxRunOffline to get the directory used by an installed distribution
# lxrunoffline get-dir -n <name of the distro>
C:\> lxrunoffline get-dir -n backup
c:\wsl\installed\backup
C:\> lxrunoffline get-dir -n Ubuntu
C:\Users\Jaime\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState
2
For WSL2 you can access to home directory from windows explorer like this :
\\wsl$
Sorry to be late at the party!
This should be updated to be the correct answer – getglad – 2020-01-15T16:23:20.060
1
The later version of the linux subsystem installs the file system under packages
so the full path would be something like:
C:\Users\myUserName\AppData\Local\Packages\UbuntuLinux.someUID\LocalState\rootfs\root
or:
C:\Users\myUserName\AppData\Local\Packages\UbuntuLinux.someUID\LocalState\rootfs\home\myLinuxUserName
... depending of course on the mount point. Doing a directory search for .bashrc
would reveal these paths...
Alternatively use readlink .
within the linux shell to post the current linux path as a 'DOS' path to windows clipboard. Paste somewhere sensible to read the actual physical path.
1
Looks like Microsoft has changed/hidden it some more, currently it's at:
%USERPROFILE%\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_?????????????\LocalState\rootfs
As this could further change in the future, just do PGP's suggestion of doing a file search of .profile or .bashrc files.
1
I created this script that open WLS folder in Explorer
cd C:\Users\%USERNAME%\AppData\Local\Packages\Canonical*\LocalState\rootfs\etc
explorer %cd%
just save it as yourScript.cmd and run
What is the output from
mount
in abash
shell? – DavidPostill – 2016-04-19T17:39:15.373This doesn't return any clues:
rootfs on / type rootfs
– There Are Four Lights – 2016-04-19T17:45:09.150Hmm. Ok. What about
cat /etc/fstab
? – DavidPostill – 2016-04-19T17:58:11.163Nope, unfortunately from the "linux" perspective it's looking sitting on hardware:
LABEL=cloudimg-rootfs / ext4 defaults 0 0
– There Are Four Lights – 2016-04-19T18:46:34.643OK. No other ideas. – DavidPostill – 2016-04-19T18:49:07.287
It's not actually correct to think of this using the virtual machine concepts of "host" and "guest" in the first place, note. This is one filesystem, merely presented in different ways by different Windows NT subsystems as they each map from their own naming conventions to the native Object Manager names.
– JdeBP – 2016-04-20T20:10:43.350Warning Please note that Microsoft strong discourages manipulating the WSL files using non-WSL utilities. – Daniel B – 2016-11-21T19:56:06.887