WSL: Cannot access \\wsl$\Ubuntu in Explorer, cannot launch Windows commands from WSL
Environment
Windows build number: Win32NT 10.0.19041.0 Microsoft Windows NT 10.0.19041.0
Your Distribution version: Ubuntu 20.04
Whether the issue is on WSL 2 and/or WSL 1: WSL2
Steps to reproduce
- Go to \wsl$ in Explorer
- See the Ubuntu directory, click it
- Receive an error message “\wsl$\Ubuntu is not accessible. You might not have permission to use this network resource. Attempt to access invalid address”.
Another problem which I think is linked - any command (“explorer.exe .” for example, or “code .”) return “/mnt/c/Windows/explorer.exe: Invalid argument” These work from windows paths (/mnt/c/Windows for example)
Expected behavior
Access the WSL directories through explorer, or be able to launch windows commands from WSL paths
Actual behavior
Errors as described above. Tried to search for similar open issues - a lot have similar symptoms (https://github.com/microsoft/WSL/issues/4027) for example, but none of the fixes posted work.
Looked at the registry keys mentioned in these issues, all fine. Tried to reinstall WSL completely (toggling the feature off, reboot, then on, reboot) Tried to install another distro, same result Tried to repair Ubuntu Tried to repair Windows using “sfc /scannow dism /Online /Cleanup-Image /CheckHealth && dism /Online /Cleanup-Image /RestoreHealth sfc /scannow netcfg -d”
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 34
- Comments: 73
Absolutely the same issue Just restart the wsl2 without doing anything else can solve all of my problems: Open powershell and run with:
wsl --shutdownwslFound a workaround! Weirdly, I can map \wsl$\Ubuntu as a network drive and access / copy files both ways! Also weirdly, I cannot map anything else than the base level folder - trying to map \wsl$\Ubuntu\home or anything else than \wsl$\Ubuntu fails.
Works for me for now, but still would like to see this issue properly resolved, as the second part of the problem is still present - cannot launch .exe from WSL if they are Windows side (a problem with VS Code for example).
Where would the problem be? Is there some register of the address where \wsl$\Ubuntu points to that is corrupted leading to the ‘access invalid address’ and ‘invalid argument’ errors?
Trying to do ‘dir \wsl$\Ubuntu’ from Powershell leads to “cd : Cannot find path '\wsl$\Ubuntu' because it does not exist.” - yet I can access my mapped network drive (Z:) just fine.
Happy to help troubleshoot this, many people are experiencing the same.
I solved this issue by navigating to \\wsl$ in explorer, right clicking my Ubuntu folder, and clicking Map Network Drive. Hit finish. Explorer should open a new window with wsl mapped to your new network drive. In my case it was Z: drive. You still cannot access the files from \wsl$[your_distro] but you will have a drive under “This PC” in explorer that gives you access.
Hi everyone,
I’m facing the same problem but I can manage to overcome it. I think it is a problem of permission (in my case at least). Indeed, If I change the default user of my distro to root, then it works.
To do so, open the windows registry manager and go here:
\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss\{ID_OF_YOUR_DISTRO}You can check you are editing the correct distro by looking at the “DistributionName” key.
Update the key “DefaultUid” to 0 in Decimal (please keep somewhere the value before putting 0).
Then restart your distro using PowerShell:
wsl --shutdown; wslYou will be logged as root.
Then try to access to \wsl$\DISTRO_NAME via explorer.exe.
It is not a long term solution but I think it could help to find the right one if this solve the problem for you.
To restore the original default user, just put the id which was in the key “DefaultUid”. You can also define the one you want by executing this command in the distro:
id -u NAME_OF_DEFAULT_USER_WANTEDThis will return an integer you should place in “DefaultUid” key (in decimal mod).
I precise the problem comes from a distro I have imported from another PC. On the original PC, no such problem.
you can run wsl --shutdown to fix issue
I have this issue since the preview build introducing “wsl.local”. The workaround is, as previously mentioned
$wsl --shutdownin a cmd window after every reboot, and of course I need to restart windows docker client to connect again to the WSL2 docker engine.I hit the same issue and discovered what caused it:
Environment
Steps to reproduce
explorer.exeusing the path\\wsl$\Ubuntusudoaccess for default user forsshdwithout a password. Within WSL:sudo visudo%sudo...your_username ALL=(ALL) NOPASSWD:/etc/init.d/ssh%windir%\System32\bash.exeArgs:-c "sudo /etc/init.d/ssh start"\\wsl$\UbuntuExpected behavior
WSL SSH should have been started and the WSL VHD should still be accessible.
Actual behavior
WSL SSH has started but access to the WSL VHD is denied. I suspect this is because WSL is first booted from an admin account / system account during startup, so the permissions end up incorrect. After removing the Task from Task Scheduler and rebooting, the WSL VHD became accessible again.
Additional notes
I am having the same issue accessing \wsl$\Ubuntu-20.04 from Explorer. However, this solution didn’t work for me. When I attempted to create the network drive, I got “Windows cannot access \wsl$\Ubuntu-20.04”, with error code 0x80070043 The network name cannot be found. When I run the Diagnose tool, I am told ‘You do not have permission to access “\wsl$\Ubuntu-20.04”’
I can get to \wsl$\Ubuntu-20.04 via an unprivileged PowerShell, but not via Explorer.
I have looked at the permissions in the UserApp folder under Canonical, and my account has full privileges on all files there.
Any ideas?
Hey! I had the same issue but I fixed using the WSL console and executing the command:
sudo chown -R my_username /root
After this I was able to navigate the folder using the file explorer and use the VS code.
My WSL2 is working fine with VSCode but I am also unable to access
\\wsl$\in Explorer.My OS: Win10 20H2 (build 19042.867)
Tried installing on my work computer - works perfectly without issues - what are my options? I guess I have the nuclear reinstall Windows from scratch but I’d love to avoid that.
Sent - let me know if you need anything else.
Been using my WSL Ubuntu setup for almost 2 years now and this just started to happen to me out of nowhere… a permanent fix would be nice.
Hey, seems I accidentally found out a workaround to solve this issue. By shuting down the WSL and restart it via command line “wsl --shutdown; wsl” in windows Powershell, I can now access the WSL2 folders in win11 file explorer.
This is exactly my issue. I added a line to the sudoers file to enable passwordless startup of the
cronservice via Task Scheduler. Once I restarted WSL via powershell, everything was back to normal but cron was once again down. My environment is different though, Microsoft Windows [Version 10.0.22000.466] and Ubuntu 20.04.the same issue happened today. Welcome to Ubuntu 20.04.2 LTS (GNU/Linux 5.4.72-microsoft-standard-WSL2 x86_64)
System information as of Sat May 8 14:19:31 CST 2021
System load: 0.06 Processes: 8 Usage of /: 0.4% of 250.98GB Users logged in: 0 Memory usage: 1% IPv4 address for eth0: 172.30.89.2 Swap usage: 0%
1 update can be installed immediately. 0 of these updates are security updates. To see these additional updates run: apt list --upgradable
The list of available updates is more than a week old. To check for new updates run: sudo apt update
terminal can login. can’t access files via explorer.
In my case running
Get-Service LxssManager | Restart-Serviceworked to resolve this issue.It did 😕
Details:
I was using wsl remote in vs code to do my work. Either some sort of crash happened randomly during work or due to wsl being open in file explorer for a while. However first thing I noticed is File Explorer restarted unexpectedly.
Then after that I cannot access \\wsl$ from file explorer. It loads infinitely until explorer hangs and restarts. This also happens when I go to Quick Access (as my wsl home directory is pinned there) and when I right click on the said pinned folder in left side view.
I can still access wsl and all its files through the wsl terminal and vs code. (I copied over my work to a native folder using terminal to submit it)
I tried running
wsl --shutdownin admin powershell but hangs. And now I can’t access wsl in any way, both the terminal and vs code remote hang.Other research
I remember finding somewhere (edit: #6216) that
chkdsk /fworked for them. I had recently tried it, but it failed as I only have one partition in drive and its what Windows is installed in, running justchkdskgave no error. However it sounds like the MS Defender Offline Scan does something similar, which is why it might have worked. I may schedule achkdsk /fupon next reboot if required but it looks risky.So far this seems to be some hard drive type issue… and also related to file explorer only. Is it just an inevitable crash from an ntfs reader reading ext4 files on ntfs patition?
Edit: interestingly enough, the behavior reported in the tagged issue is same as I’m having. The Offline Scan temporarily fixes wsl, but then the crash happens again some time later.
This happened to me recently on Windows 10. Only thing I did was export my WSL distribution…
I have the same issue recently. (maybe 2 weeks I think) After I update my Windows, it seems there is no issue any more.
hmm strange but this fixes root folder access, before windows 11 22494 update I can access the root folder in file explorer but since that update I can’t access the folder with the error display “attempt to access”
same issue on clean install of win11 22000.160, installed just docker and a few utilities. weird and annoying. Though additional observation - as i was able to run gedit. now i cannot. Gtk-WARNING **: 15:31:01.607: cannot open display: :0 i think the issue with display is correlated. some permission issue. - blind guess tho
Same issue but slightly different error message (note the path is not wsl$ anymore but wsl.localhost) on preview build 21370.1
VSCode works fine, Windows Terminal Preview cannot access the home folder from settings anymore (it was a \wsl$.… type path to my wsl home dir).
Correct. There are two likes on the OP. Imagine the status of this issue if no one could run
code.There are two possibilities. There is something unique about those 20 machines. There is something unique about the ISO. You can get unadulterated Windows ISOs here to test the hypothesis.
Impossible to say whether the issue “never” happens on a new machine installation; but if it does, based on the two likes on the OP, the error ("
/mnt/c/Windows/explorer.exe: Invalid argument") does not manifest on many fresh installs.Hi Ed,
Thanks for the clarification and the corrections. I’ve edited my post to correct them. The Markdown styling caused my '\\" to show as a single “\”. On approach #4, I had indeed forgotten the “.” to indicate the current directory. When I did that, I got “My Documents” rather than the default Quick Access.
In Approach #2, (from PowerShell), Yes, I can run commands against the files I find there. For example, I can run git init and then add and commit files.
Thanks, Jeff