microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
17.27k stars 813 forks source link

Cannot access \\wsl$\Ubuntu in Explorer, cannot launch Windows commands from WSL #5718

Open michael-imbeault opened 4 years ago

michael-imbeault commented 4 years ago

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

  1. Go to \wsl$ in Explorer
  2. See the Ubuntu directory, click it
  3. 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"

benyaminl commented 2 years ago

Resolve this problem:

1. Do backup.
wsl --export Ubuntu "C:\Ubuntu.tar"
2. Remove WSL. Use [this article](https://pureinfotech.com/uninstall-wsl2-windows-10/).
wsl.exe --shutdown
Get-AppxPackage -Name MicrosoftCorporationII.WindowsSubsystemforLinux | Remove-AppxPackage
3. Restart the computer.

4. In Windows PowerShell:
wsl --install
5. Restart the computer.

6. Open Ubuntu and set username/password

7. Remove Ubuntu and import backup
wsl --unregister Ubuntu
wsl --import Ubuntu "C:\wsu" "C:\Ubuntu.tar"
8. Profit!

Why will this method help solve the problem?

WSL from the command line comes with the latest version. And the necessary settings will be made automatically. It already has all the necessary and known fixes.

But WSL from the Microsoft Store has a lower version and is unstable for many.

For example:

1. jetbrains (phpstorm, pycharm) have a freezing problem.

2. problem with access to the explorer.

Don't use WSL from the Microsoft Store! Install with a command in PowerShell.

Tried this, sadly no luck. Does it mean only nucking the whole OS then it will works? Ugh, so sad...

mingsxs commented 2 years ago

Is this issue solved? I can still see this problem on my PC today, my os build ver is: 22000.856 (WIN11 21H2)

mingsxs commented 2 years ago

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.

benyaminl commented 2 years ago

Sometimes, it works, sometimes it is not sadly. I think the key is always do clean install each time Windows do upgrade from one version to another… (their in-place upgrade suck, cause this to kept happening…, I really lost hope on it)

Best Regards,

Benyamin Limanto 《李嘉铭》

sent from Outlook on my Thinkpad X220

From: Jerry @.*** Sent: 22 Agustus 2022 20:58 To: microsoft/WSL Cc: Benyamin Limanto; Comment Subject: Re: [microsoft/WSL] Cannot access \wsl$\Ubuntu in Explorer, cannot launch Windows commands from WSL (#5718)

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.

— Reply to this email directly, view it on GitHub https://github.com/microsoft/WSL/issues/5718#issuecomment-1222400659 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AAVP2NA4YOEVLIBADGW56VLV2OBNFANCNFSM4PUZSKBQ . You are receiving this because you commented. https://github.com/notifications/beacon/AAVP2NG7P46BICLEPV2GYBLV2OBNFA5CNFSM4PUZSKB2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOJDOFVEY.gif Message ID: @.***>

sarah-noor-12232 commented 2 years ago

I was receiving similar issue. The file explorer would either give the permissions error or load infinitely until windows restarted file explorer entirely.

restarting wsl or rebooting did not work, so I ran MS Defender Offline scan. It seems to work correctly as of now. Will report back in few days to see if it happens again.

sarah-noor-12232 commented 1 year ago

I was receiving similar issue. The file explorer would either give the permissions error or load infinitely until windows restarted file explorer entirely.

restarting wsl or rebooting did not work, so I ran MS Defender Offline scan. It seems to work correctly as of now. Will report back in few days to see if it happens again.

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 --shutdown in 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 /f worked 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 just chkdsk gave no error. However it sounds like the MS Defender Offline Scan does something similar, which is why it might have worked. I may schedule a chkdsk /f upon 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.

sarah-noor-12232 commented 1 year ago

update:

looked through superuser and a bit of #4027, I couldn't find wsl in Optional Features so I disabled and re-enabled wsl from control panel (requires 2 reboots). The file explorer issue seems to be fixed for now (all data and settings are apparently intact), still need to confirm if its temporary or permanent. if its a temporary fix, Offline Scan is still more feasible as it requires less user interaction and 1 reboot.

before disabling and enabling wsl, rebooting only allowed me to visit and use wsl directory in explorer for like a minute before crashing again.

sarah-noor-12232 commented 1 year ago

update:

The crash happened again. I guess wsl --shutdown was just running slower than before. Running it and then opening wsl again fixed it this time. I have no idea why wsl --shutdown and neofetch are now slower, could be something related to size of stuff stored in ubuntu desktop I guess. However the wsl+file explorer issue seems resolved on my end now.

Edit: this sounds like some form of a memory issue, will monitor wsl memory usage to see if I find anything.

tonyvarghese commented 1 year ago

Absolutely the same issue Just restart the wsl2 without doing anything else can solve all of my problems: Open powershell and run with: wsl --shutdown wsl

This worked for me, thanks

nickpainter commented 1 year ago

In my case running Get-Service LxssManager | Restart-Service worked to resolve this issue.

Kimi450 commented 1 year ago

I was struggling with this issue for a while but today I stopped using the "default" install of Ubuntu that comes with WSL and installed a separate version (Ubuntu 20.04) and I havent encountered this issue on 20.04. Maybe thats the workaround? Install something separately from the store and that wont give you issues?

EDIT: Nevermind... its back...

LiamKarlMitchell commented 1 year ago

For me, sometimes when I access and copy/paste files between windows/linux it will somehow lock up my system at some point later on. Any time app trys to read drives/filesystem it freezes. For example my machine can be running for months without issues, then I do something with the mapped network drive for wsl2 at some point applications will start freezing on me.

When it is in this state of frozen, if I end task explorer, it wont come back. Then I can't even open task manager again as it is frozen shortcut keys dont work for it, clicking it on Ctrl+alt+delete menu does not launch it. Running a command from wsl terminal that I still had open such as notepad.exe fails when this issue occures.

notepad.exe
<3>WSL (32112) ERROR: UtilAcceptVsock:246: accept4 failed 110
olgreet commented 1 year ago

I had this today - solved it by following the registry editing steps from this page:

https://superuser.com/questions/1682390/wsl-ubuntu-is-not-accessible-anymore-from-file-explorer

And then tried turning off and turning on WSL from PowerShell - turns out I had (or an update had) turned off the Virtual Machine Platform. Turned that back on, rebooted - working now.

sarah-noor-12232 commented 1 year ago

For me when this happens, opening wsl console or vscode remote seems to solve it

LiamKarlMitchell commented 1 year ago

For me, when its locked up opening new wsl terminals fails. Recently I increased the amount of RAM available in my %USERPROFILE%/.wslconfig to see if that helps any. It's only been a day though so have not had it lock up again yet.

rokups commented 1 year ago

So i ran into same issue. I have a feeling people here complain about multiple different causes that lead to the same outcome. I since have solved the problem so im just telling my story in hopes it gives a hint to someone/anyone how to find and fix one or more root causes of this.

I am new to WSL, so very first thing i did after installing windows was installing WSL from windows store. After that i was doing all kinds of random things, following directions on the internet, enabling windows features related to WSL directly, since apparently i got WSL1 running at first. And a range of seemingly benign actions led to system corruption where even though i could finally create WSL2 containers - only WSL1 containers were accessible through \\wsl$. A straightforward symptom of my problem was ArchWSLcreating a WSL1 container in %localappdata%\Packages when double-clicking Arch.exe, this container would be accessible from explorer but would not show up in wsl --list --all -v. I tread to get creative and wsl --import a new container into location of WSL1 container in `%localappdata%\Packages. This yielded a half-success, because i was now able to browser new WSL2 container (which also shows up in wsl --list --all -v), but only when container is offline. This must be due to differences how WSL1 and WSL2 handle access of containers. In the end everything seemed terribly broken and not working like for other people on the internet. Hope to fix it was lost.

So i did only sensible thing that was left - reinstall windows (thankfully install i did this on was only 24h old anyway). After reinstalling wsl i no longer did all kinds of random things, instead i installed wsl by running wsl --install --web-download followed by wsl --set-default-version 2. This immediately gave me a working WSL2 where double-clicking Arch.exe created a WSL2 container and it was accessible from explorer.

tl;dr;

The fix:

The conclusion: installing wsl-related things in a random order can mess up wsl beyond repair.

damianboz commented 1 year ago

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.

AC-Lover commented 11 months ago

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.

It worked for me, thanks :heart:

janspoerer commented 7 months ago

Did anybody find a permanent solution for this issue? I am struggling with this issue as well. (Using Windows 11 and the "plain" Ubuntu version from the Microsoft Store.)

fonziemedia commented 6 months ago

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.

mkhoatd commented 5 months ago

For me the problem was I manually set WSL_DISTRO_NAME in ~/.bashrc. Remove that fix the Invalid argument error for all Windows app