21

Version
Microsoft Windows [Version 10.0.19044.1586]

WSL Version
WSL 2

Kernel Version
5.10.16

Distro Version
Ubuntu20.04LTS

Other Software
Docker Desktop (Windows), version 4.6.1 (76265) Docker Engine v20.10.13

Repro Steps I already had WSL installed from Microsoft Store few days and it was working fine. I got an update about the WSL from Microsoft Store and I updated it then it stopped working.

Expected Behavior bash shell. Windows Subsystem for Linux is already installed so it should operate normally.

Actual Behavior Hello I had successfully installed WSL few days ago and everything was working fine. But after the I got an update regarding WSL from Microsoft Store I updated WSL and since then it is throwing this error. I also restarted the computer and checked to make sure my Virtual Machine Platform and Windows Subsystem for Linux are ON and I found out that both of these services were already ON. still I get the same error. May I please get any guidance on this one? as I have to use WSL for my educational purpose that would be really helpful thanks

Installing, this may take a few minutes...<br>
WslRegisterDistribution failed with error: 0x80070050<br>
Error: 0x80070050 The file exists.

Press any key to continue...

Diagnostic Logs No response

0

5 Answers 5

36

A second possible answer based on the latest information. I cannot test this personally since I am not having the issue.

Please backup (using the steps I mention in my previous answer) before trying this.

  • wsl --shutdown (from PowerShell or CMD)
  • In Windows, run the Registry Editor
  • Find \HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss
  • Find the key in there that has DistributionName of Ubuntu20.04LTS. Change the Ubuntu20.04LTS to Ubuntu-20.04.

In theory, that may fix the problem by changing the distribution name back to what it should be.

11
  • 2
    This worked for me! Thanks so much. I did do the backup steps, but this change was all that was needed to get this working again, didn't need to reinstall at all Commented Apr 11, 2022 at 16:42
  • 1
    Worked for me too. Quick and easy!
    – Phoenix
    Commented Apr 11, 2022 at 17:25
  • @BrianWhite That's good to hear. It's tough for me to post an answer that I can't necessarily test myself, so thank you for confirming that it works. Commented Apr 11, 2022 at 18:22
  • 1
    For anyone who found this helpful, note that I could not have possibly come up with it if @Pat had not provided critical information in a comment on my previous answer. Commented Apr 11, 2022 at 18:52
  • Update: I don't know if it's related, but I can no longer hit Docker from inside this WSL instance. WSL integration is turned on in Docker, with Ubuntu-20.04 ticked Yes (was turned off after the rename). Yet inside WSL I only get "The command 'docker' could not be found in this WSL 2 distro.". It worked before this incident, and although Ubuntu itself runs again, Docker does not.
    – Phoenix
    Commented Apr 11, 2022 at 21:21
11

Update: This answer was my first attempt at the solution (which does work), and the "safe" way of doing it. However, the "quick and easy" (but less "safe") registry edit that I posted as a second answer appears to be working for multiple users as well. This answer contains the background on the problem and why both of these techniques work for correcting it.

From reading through several Github issues (including, from the looks of it, one that you posted there), this appears to be a problem with the recent Store update of the Ubuntu app. The ubuntu.exe or ubuntu2004.exe (edit: I now believe this only happens with ubuntu2004.exe, but please let me know if you experience this on the ubuntu.exe version) is broken after update.

The ubuntu.exe command really does two things -- It first checks to see if Ubuntu is installed in WSL. If not, it extracts the Ubuntu rootfs and asks you to configure a username and password. If it's already installed, it launches WSL using that distribution.

The problem seems to have actually started in the previous version of the "Ubuntu 20.04" app in the Microsoft Store. The name of the distribution that is installed should be (historically), Ubuntu-20.04. The previous version appears to have had a bug where this was renamed Ubuntu2004.LTS (thanks @Pat for pointing this out in the comments).

This would have caused a similar problem for all users that updated. However, it seems Canonical quickly pushed a fix for the issue.

Unfortunately, if you installed during that window where the "bad version" was in the Store, then the fix breaks things for you, because now:

  • ubuntu2004.exe is looking for a distribution named Ubuntu-20.04.
  • It doesn't find it (because your version is incorrectly named Ubuntu20.04LTS), so it attempts to run the rootfs/configuration stage again. But the WSL files are already extracted and configured, leading to the error.

There are several options:

  • Personally, I'd just change any link to use the wsl.exe command instead of ubuntu.exe (or ubuntu2004.exe). Assuming that Ubuntu is your default WSL distribution (found via wsl -l -v), then will have the same effect and just launch it. - Edit -- It's worthwhile to actually fix this.

  • From the Github reports, you can truly fix the issue by unregistering the Ubuntu distribution. Note that this is a destructive operation that will remove your existing Ubuntu distribution.

    Assuming that the distribution still runs, via the wsl command, it is possible to back it up before unregistering, then restore it afterwards.

    I would do this in two steps:

    • First, create a backup of the distribution via the wsl --export command. Exit the distribution, then go to PowerShell and:

      wsl -l -v
      # Change "Ubuntu-20.04" in the next line to match the distribution name in use
      wsl --export Ubuntu-20.04 ubuntu_backup.tar
      
      • Second, find the virtual drive for your Ubuntu WSL distribution. Start in File Explorer with:

        %userprofile%\AppData\Local\Packages
        

        Then find the CanonicalGroupLimited...Ubuntu (the name may vary.

        Inside that, find ..\LocalState\ext4.vhdx. Copy that file to a safe location.

      • With two different backups in place, it's time to unregister Ubuntu from WSL. Remember that this is a destructive operation:

        wsl -l -v
            # Change "Ubuntu-20.04" in the next line to match the distribution name in use
        wsl --unregister Ubuntu-20.04
        
      • Rerun the ubuntu2004.exe or ubuntu.exe (either from the command-line or the Start menu)

        Ubuntu will again run its installation and initial configuration (and it should now work with the "bad" version unregistered). While you can enter a username and password here, we're just going to throw this "installation" away anyway.

      • Exit the Ubuntu distribution

      • From PowerShell:

        wsl --terminate Ubuntu-20.04 # or Ubuntu
        
      • Copy the ext4.vhdx that you saved above back into %userprofile%\AppData\Local\CanonicalGroup...Ubuntu...\LocalState over the newly created one.

At that point, the ubuntu.exe or ubuntu2004.exe command should work once again (as well as from the Start menu).

11
  • 1
    wsl --export Ubuntu ubuntu_backup.tar -> My storage is getting full, where can i find this? @NotTheDr01ds Commented Apr 11, 2022 at 4:38
  • 1
    @SivaGanesh You can place it on whatever drive you want: For example, wsl --export Ubuntu d:\wsl\ubuntu_backup.tar. By default it will create the .tar file in whatever directory you are in when you run it. Commented Apr 11, 2022 at 5:46
  • 2
    The name before the install was Ubuntu20.04LTS. After following the steps it changes to Ubuntu-20.04. Not sure if this might have something to do with the error.
    – Pat
    Commented Apr 11, 2022 at 9:05
  • 1
    @Pat That's a good observation. The "problem" (naming issue) may have actually occurred in the previous update -- Then Canonical "fixed" it, but that fix is causing problems for anyone who installed from the "broken" version in the first place. Commented Apr 11, 2022 at 15:05
  • 2
    @Pat Make that a great observation. Since folks are confirming that my second answer is working, it appears you hit the nail on the head. Commented Apr 11, 2022 at 18:53
0

One thing to add if you use Docker you will most likely also need to update your container images. You can run docker-compose pull Now you will also need to run the following which will update the container images. docker-compose up --detach up command automatically recreates container on image or configuration change.

0

Try to run this code: wsl.exe -d Ubuntu20.04LTS in your CMD or Powershell. I ran it in the Terminal app

1
  • Just a heads-up that that will fix the symptom, but not really the problem. You still won't be able to use the ubuntu2004.exe command (and the corresponding Start menu shortcut) to launch Ubuntu 20.04. Also, I believe (but I can't confirm) that you won't be able to (at some point in the future) uninstall the Ubuntu 20.04 app from Windows if this error is still in place. Commented Apr 25, 2022 at 19:16
0

I went through all these and still had problems. I finally resolved it by removing .wslconfig from c:\users\username\ directory. Then ran wsl --install (after unchecking Windows Subsystem for Linux in Windows features) and it worked fine. I may have had to reboot my system after unchecking.

1
  • Did you update your WSL to WSL2 this way?
    – Yarik
    Commented Apr 22 at 14:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .