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

WslRegisterDistribution failed with error: 0x80070005 #6744

Closed
agowa opened this issue Apr 1, 2021 · 20 comments
Closed

WslRegisterDistribution failed with error: 0x80070005 #6744

agowa opened this issue Apr 1, 2021 · 20 comments
Labels
needs-investigation likely actionable and/or needs more investigation

Comments

@agowa
Copy link

agowa commented Apr 1, 2021

Regression of #4004 and #3020

Environment

Windows build number: `Microsoft Windows [Version 10.0.21343.1000]`
Your Distribution version: Alpine Linux
Whether the issue is on WSL 2 and/or WSL 1: While installing (call to `_registerDistribution`)

Steps to reproduce

Call:

HRESULT WslApiLoader::WslRegisterDistribution(PCWSTR tarGzFilename)
{
	HRESULT hr = _registerDistribution(_distributionName.c_str(), tarGzFilename);
	if (FAILED(hr)) {
		Helpers::PrintMessage(MSG_WSL_REGISTER_DISTRIBUTION_FAILED, hr);
	}

	return hr;
}

(Or use Alpine Linux App from Store)

WSL logs: https://github.com/agowa338/wsl_etl/blob/main/wsl.etl?raw=true

Expected behavior

API Call succeeds

Actual behavior

API Call throws Access Denied instead of registering the tar.gz

Workaround

  1. Uninstalling:
  • Hyper-V
  • Hypervisor Platform
  • Container
  • WSL
  1. Reboot
  2. Reinstall all 4 features
  3. Reboot
  4. Call the API again. Now it works.
@adrastogi
Copy link
Collaborator

Thanks for reporting the issue, and for including a trace. The access denied is coming from an attempt to open HKCU (via RegOpenCurrentUser).

Can you check the permissions on that key for your device? And can you share more details about how you are invoking that code fragment?

On a clean VM of 21343, after running wsl.exe --install to get WSL configured, I was able to install the Alpine Linux trial from the Store, and was also able to programmatically register Alpine's .tar.gz from a test console app. So I'm suspecting there's something more subtle going on in the environment where you're seeing this.

@adrastogi adrastogi added the needs-investigation likely actionable and/or needs more investigation label Apr 2, 2021
@agowa
Copy link
Author

agowa commented Apr 4, 2021

Can you check the permissions on that key for your device?

Unfortunately I cannot, as I already ran the workaround steps above which fixed the issue. Maybe @airtonix can help (but for him the issue occurred in October)

And can you share more details about how you are invoking that code fragment?

Sure, but it's basically similar to the reference implementation: https://github.com/agowa338/WSL-DistroLauncher-Alpine/blob/master/DistroLauncher/DistroLauncher.cpp

On a clean VM

I suspect it's a bug with the windows release upgrades. At least that was the root of the issue the last few times this occurred. Sadly I haven't been able to find a consistent way to trigger this issue (some semi-annual upgrades go without this problem others cause it). But uninstalling and reinstalling the features listed above fixed the issue in all of these cases.

@F9Alejandro
Copy link

F9Alejandro commented Apr 4, 2021

Here is what I have for permissions on my HKCU:

Path   : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\
Owner  : BUILTIN\Administrators
Group  : NT AUTHORITY\SYSTEM
Access : NT AUTHORITY\RESTRICTED Allow  ReadKey
         NT AUTHORITY\SYSTEM Allow  FullControl
         BUILTIN\Administrators Allow  FullControl
         DESKTOP-7R3414T\Bytor Allow  FullControl
         APPLICATION PACKAGE AUTHORITY\ALL APPLICATION PACKAGES Allow  ReadKey

Omitted entries starting with S-*, as well as Audit and Sddl. Please let me know if these are needed.

Edit: @agowa338 what do your perms for HKCU look like? just for a comparison, you don't have to provide all of it just up to the application package authority.

Easy way is in powershell with:

$acl = Get-Acl HKCU:
$acl |Format-List

Fixed my issue: This error can be any number of issues, try using WSL dmesg as it will give you more insight to what might actually be causing the access denied error. Note it doesn't always have to do with the registry keys, it could be something as simple as files not existing like wsl expects.

@kiatng
Copy link

kiatng commented May 15, 2021

I encoutnred the following error when installing from Microsoft Store:

Temporary directory: C:\Users\kiat\AppData\Local\Temp\wsl_Alpine_setup
Downloading   : https://dl-cdn.alpinelinux.org/alpine/v3.13/releases/x86_64/alpine-minirootfs-3.13.4-x86_64.tar.gz
To local file : install.tar.gz
The current working directory is: C:\Users\kiat\AppData\Local\Temp\wsl_Alpine_setup
File successfully deleted
Mime type available
Begin download
Cache filename available
100% [====================]
End download
Downloaded OK
Hash of file install.tar.gz is: 8e21c85c4a5bb406180136aa03f814c56ffc7498ba7886c5ea13fec92d528ead

Verifying Hash: OK
Installing, this may take a few minutes...
WslRegisterDistribution failed with error: 0x80070005
WslRegisterDistribution failed
Error: 0x80070005 Access is denied.

Press any key to continue...

I am running Version 2004 (OS Build 19041.985). The HKCU is

PS C:\Users\kiat> $acl = Get-Acl HKCU:
PS C:\Users\kiat> $acl |Format-List


Path   : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\
Owner  : BUILTIN\Administrators
Group  : NT AUTHORITY\SYSTEM
Access : NT AUTHORITY\RESTRICTED Allow  ReadKey
         NT AUTHORITY\SYSTEM Allow  FullControl
         BUILTIN\Administrators Allow  FullControl
         WIN10\kiat Allow  FullControl
         APPLICATION PACKAGE AUTHORITY\ALL APPLICATION PACKAGES Allow  ReadKey
         S-1-15-3-1024-1065365936-1281604716-3511738428-1654721687-432734479-3232135806-4053264122-3456934681 Allow
         ReadKey
Audit  :
Sddl   : O:BAG:SYD:P(A;OICI;KR;;;RC)(A;OICI;KA;;;SY)(A;OICI;KA;;;BA)(A;OICI;KA;;;S-1-5-21-2545381894-377512648-30371149
         96-1001)(A;;KR;;;AC)(A;;KR;;;S-1-15-3-1024-1065365936-1281604716-3511738428-1654721687-432734479-3232135806-40
         53264122-3456934681)

I am not able to resolve the issue as I have close to zero knowledge on WSL and OS in general.

@Amondale
Copy link

What worked for me when I got this error:

  • Open Elevated (Administrator) Powershell or Command window
  • cd %TEMP%\wsl_Alpine_setup
  • mkdir C:\AlpineWSL [or wherever you want to put Alpine]
  • run command: WSL --import Alpine C:\AlpineWSL .\install.tar.gz
  • run command: WSL -d Alpine

You will be logged on as the almighty root user, but Alpine is a very lightweight distro, and it is unlikely you will do much that you wouldn't want root privileges to execute. If you are running Windows Terminal (you should) you'll see the Alpine distro added to your available launchers. Check out https://docs.microsoft.com/en-us/learn/modules/get-started-with-windows-subsystem-for-linux/7-manage-multiple-distributions which will walk you through creating a (non-root) user in the distro, and then setting that user to default.

@agowa
Copy link
Author

agowa commented Sep 21, 2022

any update on this?

@MichaIng
Copy link

MichaIng commented Dec 1, 2022

@Amondale
Many thanks, this worked, which means it is a permissions issue with the directory, the install.tar.gz is located, or where it is tried to be installed to? In my case it's C:\Program Files\WindowsApps\TheDebianProject.DebianGNULinux_*, which is pretty much the Windows apps default, i.e. should work. But I'm not sure where it would create the VHDX normally.

@cabiamdos
Copy link

I got the same exact problem!
After entering registry editor, take ownership of the files, installing and reisntalling wsl and the update; what worked for me is to
move the kali linux files of the microsoft store, to somewhere else (like the Downloads folder for example), and then click install.

And worked everything

@jackeymason
Copy link

wsl --update
wsl.exe --list
...to see what linux distros you have.
Oddly, though wsl --update reported "The most recent version of Windows Subsystem for Linux is already installed."
I could start Ubuntu after running it.

@MichaIng
Copy link

wsl.exe --list

Due to the error this issue is about, the list was empty, hence no WSL could start. But maybe the issue has been fixed and the wsl --update installed one automatically? I will test with an additional distro.

@andersonn-roberto
Copy link

If anyone are facing this problem, check if you have an App called Windows Subsystem for Linux, if yes, uninstall it and you will get access to wsl2 again.

It was installed here after running wsl --update command.

image

@venimus
Copy link

venimus commented Mar 30, 2023

If anyone are facing this problem, check if you have an App called Windows Subsystem for Linux, if yes, uninstall it and you will get access to wsl2 again.

It was installed here after running wsl --update command.

image

Works after I removed it and run wsl --update again (required it). Which installed the app again after that. I guess store tries to update it and mess with the permissions. I had a running wsl which just stopped one day.

@chowieuk
Copy link

chowieuk commented Apr 9, 2023

If anyone are facing this problem, check if you have an App called Windows Subsystem for Linux, if yes, uninstall it and you will get access to wsl2 again.

It was installed here after running wsl --update command.

image

Thank you very much for this solution. - I can echo what venimus said in that it works as expected again after removing and then running wsl --update

For those concerned about their data, the individual distros installations I have seem to be unaffected by this procedure - just made accessible again.

@Mistic92
Copy link

How do you remove it? I don't have uninstall button in Microsoft Store.

@ThanosYeah
Copy link

How do you remove it? I don't have uninstall button in Microsoft Store.

just go check remove apps at settings and find it or write in the search bar windows subsystem and then press delete

@mari0rh
Copy link

mari0rh commented Apr 27, 2023

After the issue, I restarted my computer. Ran wsl --update and everything worked again (even when nothing was updated tho)

@tschoeller
Copy link

I faced this issue as well and ThreatLocker was blocking vmw.exe/vmcompute.exe. Switched to learning mode for the install.

@crramirez
Copy link
Contributor

Today I faced the same issue. Using the Uninstall Store version, restart, wsl --update

Just now instead of issuing wsl --update I directly installed the previous release 1.2.5 and finally the issue is gone. Looks like there is a new issue with the recently shipped 2.0.9 version

@gerroon
Copy link

gerroon commented Dec 23, 2023

The issue is still there with WSL 2 .

I literally followed MS help page and this stuff fails. I already have working Debian and Mint so it is not my WLS2 installation. This is really sad.

What I did based on https://learn.microsoft.com/en-us/windows/wsl/install-manual

Invoke-WebRequest -Uri https://aka.ms/wslubuntu2204 -OutFile Ubuntu.appx -UseBasicParsing

Add-AppxPackage .\ubuntu.appx

It fails to start with the error in the original post.

This worked for me, but it requires admin user and messing with the folder permissions.

I moved the Ubuntu install out of C:\Program Files\WindowsApps\CanonicalGroupLimited.Ubuntu_2204.1.7.0_x64__79rhkp1fndgsc to another place.

@Takuchan
Copy link

Takuchan commented Jun 3, 2024

I deleted C:\Users\username.wslconfig and it fixed the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-investigation likely actionable and/or needs more investigation
Projects
None yet
Development

No branches or pull requests