Still able to use Explorer to view WSL files after reverting from WSL2 to WSL1 – is this normal?

Viewed 25927

I am a big fan of Windows Subsystem for Linux (WSL) and was totally psyched when they announced WSL2. However, the official Docs said that WSL2 isn't as performant as WSL1 when it comes to working with files in the Windows File system. This is kind of a bummer because most of my work is in the Windows File System itself and I would like to keep it that way.

But for the sake of checking it out, from PowerShell (could also be run from cmd.exe) I converted my main Distro to WSL2:

wsl.exe --set-version Ubuntu-18.04 2

The conversion was successful. Then – from WSL, logged in as root – when I ran

cd
explorer.exe .

it launched File Explorer in Network\wsl$\Ubuntu-18.04\home\user. I knew that this is a feature in WSL2; that we could access the Linux file system using the Windows Explorer.

However, I then decided to revert back to WSL1 (file system access). So I ran the command:

wsl.exe --set-version Ubuntu-18.04 1

And just to cross check, running

wsl.exe --list --verbose

lists my main distro as running version 1.

But now if I head over to WSL and run cd ~; explorer.exe ., it still opens up the directory in the File Explorer! As far as I know, this normally gives the error that windows can't access file paths with the Linux structure or something like that when run with WSL1.

So I was wondering if this is normal, or did it happen because of the reversion, or did I somehow break my installation?

3 Answers

Type this command to grab the version of distro

wsl -l -v

Then type this command to roll back / set default version

  wsl --set-version Ubuntu-20.04 1

It will output something like - Conversion in progress, this may take a few minutes...

Then try wsl -l -v command again, and check the result

In my case results before and after are

  NAME                   STATE           VERSION
* Ubuntu-20.04           Stopped         2
  docker-desktop         Stopped         2
  docker-desktop-data    Stopped         2

and after

  NAME                   STATE           VERSION
* Ubuntu-20.04           Stopped         1
  docker-desktop         Stopped         2
  docker-desktop-data    Stopped         2

EDIT

Actually I read description of the question, after leaving this comment, and I guess I'm not answering on it at all, but I have decided to leave it here, because it can be helpful for someone who are trying to figure it out!

So I was wondering if this is normal, or did it happen because of the reversion, or did I somehow break my installation?

It's normal. You didn't break anything.
– As already noted in this answer, in both WSL1 and WSL2
the Linux (distro) files can be accessed through File Explorer via \\wsl$.
In fact, it's the recommended way – for both WSL1 and WSL2.

For example, here is how to access the home folder for the henke user :
\\wsl$\Ubuntu-20.04\home\henke
(Replace Ubuntu-20.04 with whatever name your distro has, and henke with your Linux user name.)

Note

You should always be cautious when accessing Windows Subsystem for Linux (WSL) files from Windows. Accessing them via \\wsl$ is no exception!
For example, you should know the difference between Windows line-breaks (CRLF) and Linux line-breaks (LF). 1

From my experience, a general (and simple) rule is that copying files from Linux to Windows (WSL → Windows) usually doesn't cause any problems, whereas copying in the other direction (Windows → WSL) typically means that Linux doesn't even discover any such files.

How about accessing the Linux (WSL) files via AppData?

Disclaimer.
I have been (implicitly) advised to delete this answer because of the potential risks associated with accessing WSL files via AppData. I started to use Windows Subsystem for Linux (WSL) in 2017. At that time, WSL was still in Beta (nowadays known as Legacy), 2 and in that version – to access Linux (WSL) files from Windows – I always used the path %LocalAppData%\lxss. To the best of my knowledge this was (and for the Legacy version still is) the only way to access WSL files from Windows. I cannot recall ever having messed up any Linux files. 3

I have been pointed to the blog post Do not change Linux files using Windows apps and tools, which strongly advises against ever accessing the WSL file system via the AppData folder.

In summary, the problem arises when, for example, you use a Windows app/tool to open, create and/or modify a file under your distro root: since the file was created with a Windows tool, the file won’t have any Linux file metadata (e.g. permissions, owner, access/update timestamps, etc.). Thus, to Linux, (which only receives Linux file metadata), the file may be reported as empty or may not even exist ... in short – use this at your own risk!
End of disclaimer.

If you want to access WSL files via AppData despite the disclaimer

You can access the /home/henke folder via :
%LocalAppData%\Packages\CanonicalGroupLimited.Ubuntu20.04onWindows_79rhkp1fndgsc\LocalState\rootfs\home\henke
Accessing the Linux (WSL) file system this way is only possible in WSL1, not in WSL2. 4

References


1 There is of course much more to the difference between Linux and Windows than the line-breaks.

2 The official name back then was Windows Subsystem for Linux (Beta).

3 I didn't upgrade my WSL until July this year (2022). I am now using WSL2.

4 The reason is that in WSL2, the WSL file system is inside a single ext4.vhdx file which Windows apparently cannot peek into. Whereas in WSL1, the Linux file system is in the folder rootfs.
I think it is fair to say that the rootfs folder plays the same role as does the lxss folder in the Legacy version. One obvious difference is that while the lxss folder was hidden, the rootfs folder is not hidden. Maybe this will change in future build versions of Windows 10?

Related