Sunday, February 24, 2019

Access Linux files from Windows

Windows 10 Insider Preview Build 18342 has been released recently and many new features have been added with it. Among them is one of the most requested feature of accessing all the files in your Linux distros from Windows.
Earlier creating, changing Linux files from Windows resulted in losing or corrupting of files. Now this has been made possible to access Linux files from Windows without corruption. These files can be accessed through the command line, and also Windows apps, like File Explorer, VSCode, etc. can interact with these files.Access your files by navigating to \\wsl$\<distro_name>, or see a list of running distributions by navigating to \\wsl$.
Just for info: Why is the WSL resource name in the filepath called wsl$?
“Since wsl is a short acronym we realize that some resources on networks may already have that name. So we’ve added a dollar sign, since a machine name can’t have a dollar sign in it, which ensures that the name will be accessible with any existing network configuration.”
Accessing via File Explorer:
Try opening your Linux files in Explorer. To do this, open your favorite distro, ensure your current folder is your Linux home directory and type in explorer.exe . This will open a File Explorer window, located inside of your Linux distro.

So from here, you can access whatever Linux files you want, just like you do for any other file through File explorer. You can also do operations like dragging files back & forth to other locations, can copy and paste. One can also even use the context menu.

When using this feature as said above, you’ll notice the distro files are exposed through the path: \\wsl$\<running_distro_name>\. This is due to the way Windows accesses the files inside of each distro. This will be improved by the WSL team.
Accessing via Command line:
WSL is primarily a command line tool, and so of course this feature also works in the command line. You can find your distro’s files by accessing \\wsl$\{distro name}\ where {distro name} is the name of a running distro.

Here Debian is accessed with PowerShell
Since its a new feature, there might be some issues. Some of these known issues are:
  • As of now, the distros files will only be accessible from Windows when the distro is running. In future non-running distros too will be supported.
  • Accessing Linux files is treated the same as accessing a network resource, and any rules for accessing network resources will still apply
    e.g: When using CMD, cd \\wsl$\Ubuntu\home will not work (as CMD does not support UNC paths as current directories), however copy \\wsl$\Ubuntu\home\somefile.txt C:\dev\ will work
  • You should NOT access your Linux files inside of the AppData folder!
    If you try to access your Linux files through your AppData folder, you are bypassing using the 9P server, which means that you will not have access to your Linux files, and you could possibly corrupt your Linux distro.
For more details check source.

No comments: