How do I access the WSL Linux file system from Windows?

39.2k views Asked by At

I found that static files served from a Rails application running in /home/pupeno/projectx take more or less half as much time than the ones served from /mnt/c/Users/pupeno/projectx. It's almost acceptable. I tried webrick and puma (as well as passenger and unicorn, which don't work yet).

So, if I'm going to host my source code in /home/pupeno, how do I access from Windows applications such as RubyMine?

For the record, this is the application being served from the Windows file system:

enter image description here

and this is the Linux file system:

enter image description here

8

There are 8 answers

2
Mike Slinn On

WSL mounts Windows partitions under /mnt. For example, you can modify files in c:\work on the mounted Windows filesystem by referencing them as /mnt/c/work.

Windows apps (cmd, file manager, etc), can access files in WSL in read-only mode by prepending with %LocalAppData%\lxss. Copying a file from the Windows filesystem to the WSL directories renders it unreadable, with a cryptic general I/O error. Files created in %LocalAppData%\lxss from Windows are not visible to WSL. Files created from WSL can be modified in Windows, and the modified file can subsequently be accessed by WSL.

0
Louis_Curry On

go to filesytem and enter this location: the operating sytem may differ, in my case it is unbuntu

\\wsl.localhost\Ubuntu\home\Aayana\Downloads
0
Kanna Reddy On

fire the CLI command explorer.exe \\wsl$ in Windows powershell/cmd

1
mliang2 On

On Windows 10 Creators Update, I use SFTP NetDrive to mount the WSL filesystem into windows as as a network drive.

There are some Window sshFS ports that'll achieve the same thing.

You'll need to start the ssh daemon via sudo service ssh start.

0
Chris On

With Windows 10 version 1903 and later, WSL filesystems are available in Windows via the \\wsl$ mount. Either browse there manually or launch explorer.exe from a WSL path:

$ cd /home/me
$ explorer.exe .

If you have an existing WSL installation and you upgrade to Windows 1903 you may find that the \\wsl$ mount doesn't work. Some users have found that disabling and re-enabling WSL fixes the issue.

In PowerShell:

Disable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
# Reboot when prompted
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
# Reboot when prompted

Disabling and re-enabling WSL didn't seem to harm my existing Ubuntu installation but it's probably worth backing up anything you want to save just in case.

1
Rich Turner On

PM for Windows Command-Line here:

Thus far, accessing Linux files from Windows has been unsupported. To understand why, please read this post: https://blogs.msdn.microsoft.com/commandline/2016/11/17/do-not-change-linux-files-using-windows-apps-and-tools/

However, as of Windows 10 build 1903 (March 2019), we (finally!) exposed your distros' filesystems to Windows!

To learn more, please read this post: https://blogs.msdn.microsoft.com/commandline/2019/02/15/whats-new-for-wsl-in-windows-10-version-1903/

enter image description here

Look forward to hearing how you get on with this feature. If you find any problems, please file issues on the WSL GitHub repo here: https://github.com/microsoft/wsl.

0
Lissanro Rayen On

\wsl$ mount point did not work for me so well, it has multiple issues, and many Windows applications fail because they see it as a network drive. For my usecase, it is Rclone what helped to solve the problem to properly mount Linux filesystem so it behaves without any issues, practically the same way as a local disk.

It is free and open source. It works with sftp remote filesystems (like sshfs), so it can mount network drives both on Linux and Windows (running sshd service).

Example command how to run it, assuming remote point "server" is already configured and rclone.exe is in PATH environment variable:

rclone mount server:/ Z: --file-perms=0777 --track-renames --track-renames-strategy=modtime,leaf --metadata --vfs-cache-mode=full --sftp-disable-hashcheck --volname drive_name

For the first time, you need to configure new remote point by running:

rclone config

To find out location of the config file you have just created, run:

rclone config file

Also, you may need to install WinFsp first, if not already intalled. The best thing about it, everything just works the same way like with local disk (assuming if you provide --vfs-cache-mode=writes or --vfs-cache-mode=full option, since without it, many applications will fail to work correctly, please read the documentation to understand why). Option --file-perms=0777 is necessary to allow running .exe files. Even though --vfs-cache-mode=writes may be enough for most applications, but --vfs-cache-mode=full is important for good performance with large files. For the same reason --track-renames-strategy is limited to only modtime and leaf strategies, because if other strategy is used, it will be obviously slow with large files, and --sftp-disable-hashcheck is necessary to prevent rclone from running md5sum, otherwise it will run it even when trying to read a file.

To register Rclone as a system service, edit and run the following command (do not run as is, please see below how you need to edit it first):

New-Service -Name Rclone -BinaryPathName 'C:\Program Files\Rclone\rclone.exe mount server:/ Z: --vfs-cache-mode=full --track-renames --track-renames-strategy=modtime,leaf --metadata --volname drive_name --config="C:\Program Files\Rclone\rclone.conf" --log-file="C:\Program Files\Rclone\rclone.txt" --file-perms=0777 --sftp-disable-hashcheck --no-console'

Obviously, you need to replace "server:/" with your actual remote point name and path, also replace drive_name with any name you like, and of cource you may need to edit paths to rclone.conf, rclone.log and rclone.exe, if you installed it in a different location.

Note: in my case running as a system service caused some permission issues (for example, when trying to save Excel files), and I did not figured out why yet, so I ended up creating startup .bat file to run Rclone as a user, since it works perfectly this way. I will update this answer if and when I figure out how to make running as a service to work as good as running as a user.

Even Windows software which does not like network drives, just works with RClone drives. All is needed, is to setup sshd in the remote system (which in this case is not really a remote syset, but in WSL distribution installed on the same PC). This how to setup sshd in WSL distribution: https://www.hanselman.com/blog/how-to-ssh-into-wsl2-on-windows-10-from-an-external-machine. And here is how to make WSL IP address static: https://github.com/ocroz/wsl2-boot, so you can have sshd running always at the same IP address.

9
surya On

You can easily access, read and write files from WSL Linux file system to Windows and vice-versa by simply navigating to the file location :

C:\Users\\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState\rootfs

Hope this helped you!!