Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Starting WSL results in error "The file cannot be accessed by the system." #9197

Closed
1 of 2 tasks
taikodragon opened this issue Nov 23, 2022 · 58 comments
Closed
1 of 2 tasks

Comments

@taikodragon
Copy link

Version

Microsoft Windows [Version 10.0.22621.819]

WSL Version

  • WSL 2
  • WSL 1

Kernel Version

No response

Distro Version

Debian

Other Software

Docker Desktop (Windows), version 4.12.0
Visual Studio Code 1.73.1 (system setup) with Remote-WSL Extension 0.72.0

Repro Steps

Open powershell.
Run wsl.exe
Returned response is
The file cannot be accessed by the system.

Expected Behavior

It should start the distro.

Actual Behavior

Returned response is
The file cannot be accessed by the system.

Diagnostic Logs

https://1drv.ms/u/s!ArYWk3X9lH3jicFEE6GNcS0tDY6Dtg?e=6VEqXD

@arothenhaeuser
Copy link

I am experiencing the same issue. No matter which WSL command I run right after installing Ubuntu with wsl --install -d ubuntu, I get the same error.
Distro: Ubuntu 22.04
Host: Windows 11 Enterprise (21H2 22000.1281)
Powershell: 5.1.22000.832

I'm running the WSL commands from a ScheduledJob (powershell) after waiting for the initial user creation prompt, but having closed it without creating a user.

@StephaneKazmierczak
Copy link

StephaneKazmierczak commented Dec 7, 2022

I am having the same error message since this morning, except it is only happening while using a remote ssh connection, if I start the command locally then they work, if I connect to windows using OpenSSH then type wsl then I get the error
I am on insider build 25201.1000

@taikodragon
Copy link
Author

I was able to resolve my issue with a dism /Online /Cleanup-Image /RestoreHealth and a restart.

@AidanStrong
Copy link

I am having the same error message since this morning, except it is only happening while using a remote ssh connection, if I start the command locally then they work, if I connect to windows using OpenSSH then type wsl then I get the error I am on insider build 25201.1000

@StephaneKazmierczak did you ever fix this issue?

@MathanGeurtsen
Copy link

I have had this happen twice, last time I did the dism command and a couple of restarts and it eventually worked again, and now I have the same problem again. So I think that is not a permanent solution. And I think this issue should be reopened, there seem to be multiple people with an issue here.

@pavelgood
Copy link

pavelgood commented Jan 17, 2023

I have the same issue. WSL works fine when executing from the usual graphical session but ends up with The file cannot be accessed by the system when using remote ssh session. The problem appeared approximately a month ago. Have no clue what could be the reason. No updates where applied or any configuration changes made. dism tool doesn't help in my case. Windows version: 10.0.19045.2486. The issue definitely has to be reopened.

@simmel
Copy link

simmel commented Jan 18, 2023

For solution see #7900

@pavelgood
Copy link

pavelgood commented Jan 19, 2023

Thanks @simmel . Removing Windows Subsystem for Linux works to me.

@StephaneKazmierczak
Copy link

I am having the same error message since this morning, except it is only happening while using a remote ssh connection, if I start the command locally then they work, if I connect to windows using OpenSSH then type wsl then I get the error I am on insider build 25201.1000

@StephaneKazmierczak did you ever fix this issue?

I keep a wsl shell running on remote machine at all times. Also I was having more issues with 1.1.0 so downgraded to 1.0.3

@marklechtermann
Copy link

Same problem with our Azure DevOps pipeline job.

c:\agent> wsl --version
The file cannot be accessed by the system.

In our case, we want to install a custom WSL image on a build agent.
Over a RDP connection the call to "wsl --version" works.
Via the build agent (same user) it does not work anymore.
The error exists since about the beginning of January 2023.

As described in the known issues, calls to the WSL that originate from a session zero no longer works.
For example, when something is started from a Windows service (ADOs agents or SSH-Daemon) .

Does anyone know workarounds?

https://learn.microsoft.com/en-us/windows/wsl/store-release-notes#known-issues

Release Notes for Windows Subsystem for Linux in the Microsoft Store
Launching Windows Subsystem for Linux from session zero does not currently work (for example from an ssh connection).

@AidanStrong
Copy link

@marklechtermann

Our case seems to be almost exactly the same as yours. We want to install a custom WSL image using a build agent. We noticed this issue with remote commands in Jan 2023 and found that no command with WSL at the front would work.

We use packer and powershell scripts to provision a windows sysprep image with WSL baked in. I do not know exactly what fixed the problem but we now do the following and it works fine:

  1. wsl --install
  2. RESTART
  3. Download the appx package directly from https://aka.ms/wslubuntu2004
  4. unpack the AMD64 package to get exe file.
  5. Start-Process "Installer\ubuntu.exe" -Verb runAs -ArgumentList 'install --root /qn /quiet /log C:\logs\wslubuntu.txt' -wait
  6. After installation, we customise our WSL build.
  7. We then export to a tar and unregister before reimporting to a central location (you may not have to do this)
  8. RESTART
  9. Slightly unrelated but we then had to remove the appx package with the following code otherwise sysprep would not work:
$wslAppxToDelete = Get-AppxPackage -AllUser | where-object {$_.name -match "MicrosoftCorporationII.WindowsSubsystemForLinux"}
Remove-AppxPackage -Package $wslAppxToDelete.PackageFullName -AllUsers

I hope this helps.

@luceat-lux-vestra
Copy link

I solved this issue by Reset the Windows Subsystem for Linux in App Settings.
I can't access that setting page after resetting. but I remember what I did.

Windows logo key -> type linux -> 'Windows Subsystem for Linuxappears -> you can seeApp Settings` in the right pane, hit that menu.

When Settings windows open, you can see the Reset button.
after the reset, It works like a charm!

@appleternity
Copy link

Just want to report that this solves my problem as well!!

I solved this issue by Reset the Windows Subsystem for Linux in App Settings. I can't access that setting page after resetting. but I remember what I did.

Windows logo key -> type linux -> 'Windows Subsystem for Linuxappears -> you can seeApp Settings` in the right pane, hit that menu.

When Settings windows open, you can see the Reset button. after the reset, It works like a charm!

@jmihalich
Copy link

Just want to report that this solves my problem as well!!

I solved this issue by Reset the Windows Subsystem for Linux in App Settings. I can't access that setting page after resetting. but I remember what I did.
Windows logo key -> type linux -> 'Windows Subsystem for Linuxappears -> you can seeApp Settingsin the right pane, hit that menu. When Settings windows open, you can see theReset` button. after the reset, It works like a charm!

This worked for me too. seriously, wtf???

@cimmyx
Copy link

cimmyx commented May 12, 2023

Just want to report that this solves my problem as well!!

I solved this issue by Reset the Windows Subsystem for Linux in App Settings. I can't access that setting page after resetting. but I remember what I did.
Windows logo key -> type linux -> 'Windows Subsystem for Linuxappears -> you can seeApp Settingsin the right pane, hit that menu. When Settings windows open, you can see theReset` button. after the reset, It works like a charm!

This worked for me too. seriously, wtf???

Tried it, did not work.

@brnpimentel
Copy link

Just want to report that this solves my problem as well!!

I solved this issue by Reset the Windows Subsystem for Linux in App Settings. I can't access that setting page after resetting. but I remember what I did.
Windows logo key -> type linux -> 'Windows Subsystem for Linuxappears -> you can seeApp Settingsin the right pane, hit that menu. When Settings windows open, you can see theReset` button. after the reset, It works like a charm!

didn't work.

@Edgaras91
Copy link

Edgaras91 commented May 25, 2023

Just want to report that this solves my problem as well!!

I solved this issue by Reset the Windows Subsystem for Linux in App Settings. I can't access that setting page after resetting. but I remember what I did.
Windows logo key -> type linux -> 'Windows Subsystem for Linuxappears -> you can seeApp Settingsin the right pane, hit that menu. When Settings windows open, you can see theReset` button. after the reset, It works like a charm!

didn't work.

I ended up following the steps to uninstalling that linux windows application, which did not uninstall wsl2, just got reverted to an older working version.

@AshishPandagre
Copy link

I solved this issue by Reset the Windows Subsystem for Linux in App Settings. I can't access that setting page after resetting. but I remember what I did.

Windows logo key -> type linux -> 'Windows Subsystem for Linuxappears -> you can seeApp Settings` in the right pane, hit that menu.

When Settings windows open, you can see the Reset button. after the reset, It works like a charm!

Thanks a lot ❤

@stevenh
Copy link

stevenh commented Jun 21, 2023

Add or remove programs -> search for linux -> Advanced options -> Repair fixed it for me.

@ktunprasert
Copy link

Reset worked for me and didn't wipe the data, don't worry if you're afraid of losing data after doing a system restore and bricking WSL like me

@zwancho
Copy link

zwancho commented Jul 21, 2023

I was able to resolve my issue with a dism /Online /Cleanup-Image /RestoreHealth and a restart.

It works for me after a blue screen and System Restore

can also see https://superuser.com/a/1758189/1821863

@dexter69
Copy link

dexter69 commented Aug 9, 2023

Removing Windows worked for me...

@ayushxx7
Copy link

Add or remove programs -> search for linux -> Advanced options -> Repair fixed it for me.

worked for me as well. Somehow my Windows got bricked during a restart. Then I had no other choice but to "restore" to a previous version and then following the above steps worked for me.

@energister
Copy link

energister commented Sep 6, 2023

Got this message on Windows 11. Nothing helped, even reactivation through the "Turn Windows features on or off" -> "Windows Subsystem for Linux" from the Control Panel.

The only thing that has helped is to delete "Windows Subsystem for Linux" by the Settings ("Add or remove programs" -> search for "linux")

@Van-Dame
Copy link

I solved this issue by Reset the Windows Subsystem for Linux in App Settings. I can't access that setting page after resetting. but I remember what I did.

Windows logo key -> type linux -> 'Windows Subsystem for Linuxappears -> you can seeApp Settings` in the right pane, hit that menu.

When Settings windows open, you can see the Reset button. after the reset, It works like a charm!

Worked for me flawlessly!

@heniGR
Copy link

heniGR commented Oct 14, 2023

https://www.youtube.com/watch?v=T9r5d_YoIbc
DISM.exe /Online /Cleanup-image /Scanhealth
DISM.exe /Online /Cleanup-image /Restorehealth
this worked for me!

@cimmyx
Copy link

cimmyx commented Oct 14, 2023

https://www.youtube.com/watch?v=T9r5d_YoIbc DISM.exe /Online /Cleanup-image /Scanhealth DISM.exe /Online /Cleanup-image /Restorehealth this worked for me!

Another "fix" that doesn't fix anything....

milo> ssh -Y [email protected]

Microsoft Windows [Version 10.0.22621.2428]
(c) Microsoft Corporation. All rights reserved.

cimmy@IRIS C:\Users\cimmy>wsl
The file cannot be accessed by the system.

cimmy@IRIS C:\Users\cimmy>

@MezTemplar
Copy link

MezTemplar commented Oct 20, 2023

If you delete the "Windows Subsystem for Linux" Windows App (APPX, not the EXE) you can run WSL commands headless again. (e.g. wsl --version, wsl --list) However then you get "WSL 2 requires an update to its kernel component. For information please visit https://aka.ms/wsl2kernel" if you try to start a VM. Not a fix, but a clue.

@Saviio
Copy link

Saviio commented Oct 27, 2023

I had same issue, after I installed ubuntu 22.04 (from window store),I lose acces to wsl from ssh.
can someone help to fix it?

@vrajjbhatt
Copy link

I solved this issue by Reset the Windows Subsystem for Linux in App Settings. I can't access that setting page after resetting. but I remember what I did.

Windows logo key -> type linux -> 'Windows Subsystem for Linuxappears -> you can seeApp Settings` in the right pane, hit that menu.

When Settings windows open, you can see the Reset button. after the reset, It works like a charm!

This worked for me ! thanks @Van-Dame

@kev-in-shu
Copy link

variables: wslPath: '"C:\Program Files\WSL\wsl.exe"'

Using this other wsl.exe worked for me

@MezTemplar
Copy link

I was running into this issue after switching my self-hosted build agent to run as a service. I tried many of the suggestions above without success. What worked for me was to modify my yml files to explicitly indicate the location of the WSL instance I want to execute:

variables: wslPath: '"C:\Program Files\WSL\wsl.exe"'

From here, I modified the docker commands I was using like so:

'$(wslPath) docker buildx...

Not ideal but currently the only thing working for me...

I'm doing the same thing you are, but I don't have a "C:\Program Files\WSL\wsl.exe". I tried C:\Windows\System32\wsl.exe with no luck. My agents are running Windows Server 2022

@PrestonTaylor
Copy link

PrestonTaylor commented Dec 7, 2023

For others like me absolutely terrified at the thought of clicking uninstall for WSL, after backing up my vhdx to be safe (C:\Users\<username>\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu<version and ID>\LocalState\ext4.vhdx) I did it, after uninstalling the 2 "Windows Subsystem for Linux" entries I had it immediately worked. I lost nothing, I didn't have to do or re-install anything else, it just started working. ¯\_(ツ)_/¯

@sinanejadebrahim
Copy link

GUYS , this happens after a restore for some reason - nothing worked for me. the only simple thing was to uninstall windows subsystem for linux and reinstall it, this doesn't cause any data loss - were not removing ubuntu , just the sub system app.so just remove it and reinstall from store. fixed easily

@incik
Copy link

incik commented Jan 2, 2024

GUYS , this happens after a restore for some reason - nothing worked for me. the only simple thing was to uninstall windows subsystem for linux and reinstall it, this doesn't cause any data loss - were not removing ubuntu , just the sub system app.so just remove it and reinstall from store. fixed easily

Yes! Exactly this happend to me - I had to restore the system and WSL broke. Wasn't able to run the wsl command in Powershell to do anything (deleting and reimpoting my backup). I tried to remove and re-add the Windows Subsystem for Linux system feature itself, but that didn't help. Reinstalling the WSL app from the Microsoft Store fixed my problems. 🎉

@fabioDMFerreira
Copy link

Upgrading WSL to a pre-released version worked for me!

wsl --update --pre-release

After rebooting it should be fine.

https://superuser.com/questions/1714736/cannot-run-wsl2-over-ssh-on-windows-11

@omgmajk
Copy link

omgmajk commented Jan 11, 2024

Add or remove programs -> search for linux -> Advanced options -> Repair fixed it for me.

This worked for me too, had this happen today after a system restore. Found the answer on SO but also found this thread so thought I might reply here.

@navalega0109
Copy link

navalega0109 commented Jan 16, 2024

Sub system app.so just remove it and reinstall from store

Hi I'm also facing the same issue and uninstalled the WSL from windows. Now trying to install from microsoft store, please check below screen shot if I'm installing correct app.

Need to uninstall
image

Need to install
image

Is this correct? Please let me know so that I can proceed.

@navalega0109
Copy link

wsl --update --pre-release

This is not working for me. Getting same error: The file cannot be accessed by the system

@navalega0109
Copy link

after the reset, It works like a charm!

Bingo Best Solution Thanks Mate!!!

@aaronir
Copy link

aaronir commented Feb 11, 2024

Just want to report that this solves my problem as well!!

I solved this issue by Reset the Windows Subsystem for Linux in App Settings. I can't access that setting page after resetting. but I remember what I did.
Windows logo key -> type linux -> 'Windows Subsystem for Linuxappears -> you can seeApp Settingsin the right pane, hit that menu. When Settings windows open, you can see theReset` button. after the reset, It works like a charm!

This worked for me too. seriously, wtf???

Me too. I just hit repair, also worked. cool

@MezTemplar
Copy link

Upgrading WSL to a pre-released version worked for me!

wsl --update --pre-release

After rebooting it should be fine.

https://superuser.com/questions/1714736/cannot-run-wsl2-over-ssh-on-windows-11

Since I'm on Windows Server 2022 I didn't have a Reset option in the GUI so I tried Reset-AppxPackage with no luck. The version I was using was 2.0.14.0, but with -pre-release it went to 2.1.3.0 and my problems went away!

@emmanuelux
Copy link

emmanuelux commented Mar 3, 2024

if you get :

The file cannot be accessed by the system

the solution was not "repair" for me or not only :

Add or remove programs -> search for linux -> Advanced options -> Repair

it was :

Add or remove programs -> search for linux -> Advanced options -> Reinitialize

@chandankushwahaa
Copy link

chandankushwahaa commented Mar 13, 2024

  • Go to FIle manager search bar type \\wsl$ - It will open the file directory of linux distribution
  • Open terminal and type
  • wsl --list --v : It will list all installed Linux distributions
  • wsl --unregister ubuntu - ubnuntu is the name it can be anything from the list
  • Again install ununtu from microsoft store

It works for me

@gabsoftware
Copy link

I tried many things, repairing Windows, dism commands, sfc /scannow, uninstalling / reinstalling the Windows Subsystem for Linux optional feature of Windows, repairing my distro app, repairing the WSL store app, but the thing that finally worked was:

  • Uninstalling "Windows Subsystem for Linux" (it's a store app but you can only see it by typing "linux" in "applications and features" in Windows settings)
  • At this point, the wsl command worked again but advised to run "wsl update"
  • So I did, but that command fails miserably ("/bin/bash: line 1: update: command not found") because it's actually "wsl --update"
  • Running "wsl --update" installs again the store app
  • Finally working and I did not loose my distro!

@DmitrY66
Copy link

В моем случае проблема была решена одной простой командой: "wsl --shutdown". Значение ее можно посмотреть набрав "wsl --help". Может показаться странным, но это работает как сразу, так и после перезагрузки. Удачи!

@HumbleBee14
Copy link

Upgrading WSL to a pre-released version worked for me!

wsl --update --pre-release

After rebooting it should be fine.
https://superuser.com/questions/1714736/cannot-run-wsl2-over-ssh-on-windows-11

Since I'm on Windows Server 2022 I didn't have a Reset option in the GUI so I tried Reset-AppxPackage with no luck. The version I was using was 2.0.14.0, but with -pre-release it went to 2.1.3.0 and my problems went away!

Tried everything possible, none worked. Eventually this helped - wsl --update --pre-release
which is funny! Stable version is Unstable

@bjagasia
Copy link

bjagasia commented Apr 2, 2024

Add or remove programs -> search for linux -> Advanced options -> Repair fixed it for me.

This worked after a system restore -- thank you.

@pengweiqhca
Copy link

I fixed it after installing wsl.msi manuall

@rayinfinite
Copy link

I fixed it by clicking a reinstall button in Windows Subsystem for Linux app in Microsoft Store

@DonovanPS
Copy link

In my case I managed to solve it in the following way:
delete the folder: C:\Program Files\WSL
If it does not allow you to eliminate, stop the wsl service, in the windows search engine you search for services and within the application you search for wsl and stop it

After that you search for wsl in windows and it will reinstall the wsl and it no longer gave me the error

@plato1123
Copy link

I fixed it after installing wsl.msi manuall

wow that saved the day thank you <3

@Useems
Copy link

Useems commented Jun 14, 2024

Add or remove programs -> search for linux -> Advanced options -> Repair fixed it for me.

It worked for me, resolved in less than 1 minute.

@herofahad777
Copy link

Sub system app.so just remove it and reinstall from store

Hi I'm also facing the same issue and uninstalled the WSL from windows. Now trying to install from microsoft store, please check below screen shot if I'm installing correct app.

Need to uninstall image

Need to install image

Is this correct? Please let me know so that I can proceed.

It worked thanks just needed to click repair, the internal windows repair functions for me are also broken i think

@robertoandrade
Copy link

robertoandrade commented Jun 27, 2024

Had this very issue on a Windows 11 installation and after reading through all comments here I noticed that indeed the wsl.exe copies that get installed and are available on the standard PATH aren't really the actual executables, unless they get replaced or something gets changed after reboot/repair, but debugging through the instances of wsl.exe on the system:

>where wsl.exe
C:\Windows\System32\wsl.exe
C:\Users\vagrant\AppData\Local\Microsoft\WindowsApps\wsl.exe

>dir C:\Windows\System32\wsl.exe
 Volume in drive C has no label.
 Volume Serial Number is 6E9D-788A

 Directory of C:\Windows\System32

02/25/2024  01:48 PM           196,608 wsl.exe
               1 File(s)        196,608 bytes
               0 Dir(s)  96,262,938,624 bytes free

>C:\Windows\System32\wsl.exe --version
The file cannot be accessed by the system.

Since while running dir /s \wsl.exe found many other copies in many directories including C:\Program Files\WSL\wsl.exe I ended up testing executing the same command with that one:

>"c:\Program Files\WSL\wsl.exe" --version
WSL version: 2.2.4.0
Kernel version: 5.15.153.1-2
WSLg version: 1.0.61
MSRDC version: 1.2.5326
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.26091.1-240325-1447.ge-release
Windows version: 10.0.22631.3155

That file seems to be much bigger than the ones on the path:

>dir /s wsl.exe
 Volume in drive C has no label.
 Volume Serial Number is 6E9D-788A

 Directory of C:\Program Files\WindowsApps\MicrosoftCorporationII.WindowsSubsystemForLinux_2.2.4.0_x64__8wekyb3d8bbwe

06/21/2024  07:55 PM         3,633,088 wsl.exe
               1 File(s)      3,633,088 bytes

 Directory of C:\Program Files\WSL

04/25/2024  06:19 PM         3,633,088 wsl.exe
               1 File(s)      3,633,088 bytes

 Directory of C:\Users\vagrant\AppData\Local\Microsoft\WindowsApps

06/21/2024  07:56 PM                 0 wsl.exe
               1 File(s)              0 bytes

 Directory of C:\Users\vagrant\AppData\Local\Microsoft\WindowsApps\MicrosoftCorporationII.WindowsSubsystemForLinux_8wekyb3d8bbwe

06/21/2024  07:56 PM                 0 wsl.exe
               1 File(s)              0 bytes

 Directory of C:\Windows\System32

02/25/2024  01:48 PM           196,608 wsl.exe
               1 File(s)        196,608 bytes

 Directory of C:\Windows\WinSxS\amd64_microsoft-windows-lxss-wsl_31bf3856ad364e35_10.0.22621.2506_none_62c8e9f54a7fa6e6

02/25/2024  01:48 PM           196,608 wsl.exe
               1 File(s)        196,608 bytes

 Directory of C:\Windows\WinSxS\amd64_microsoft-windows-lxss-wsl_31bf3856ad364e35_10.0.22621.2506_none_62c8e9f54a7fa6e6\f

02/09/2024  08:05 PM               344 wsl.exe
               1 File(s)            344 bytes

 Directory of C:\Windows\WinSxS\amd64_microsoft-windows-lxss-wsl_31bf3856ad364e35_10.0.22621.2506_none_62c8e9f54a7fa6e6\r

02/25/2024  01:48 PM               595 wsl.exe
               1 File(s)            595 bytes

     Total Files Listed:
               8 File(s)      7,660,331 bytes
               0 Dir(s)  96,284,803,072 bytes free

So not sure if the other ones are stubs or some sort of "symbolic link" to the actual ones but they don't seem to work out of the box after installing and rebooting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests