WSL not working after update from Microsoft store

13,588

Solution 1

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.

Solution 2

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).

Share:
13,588

Related videos on Youtube

J. Doe
Author by

J. Doe

Updated on September 18, 2022

Comments

  • J. Doe
    J. Doe over 1 year

    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

    • NotTheDr01ds
      NotTheDr01ds about 2 years
      @steeldriver Actually, this turns out to be (most likely) a problem specifically in the ubuntu.exe, which comes from Canonical.
    • steeldriver
      steeldriver about 2 years
      @NotTheDr01ds fair enough - comment deleted
    • NotTheDr01ds
      NotTheDr01ds about 2 years
      @steeldriver Thanks - Keeping my comment here for now since there are currently 3 close votes. Hopefully I can keep this from being closed (and subsequently Roomba'd) since other people are running into this.
  • Siva Ganesh
    Siva Ganesh about 2 years
    wsl --export Ubuntu ubuntu_backup.tar -> My storage is getting full, where can i find this? @NotTheDr01ds
  • NotTheDr01ds
    NotTheDr01ds about 2 years
    @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.
  • Pat
    Pat about 2 years
    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.
  • NotTheDr01ds
    NotTheDr01ds about 2 years
    @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.
  • Brian White
    Brian White about 2 years
    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
  • Phoenix
    Phoenix about 2 years
    Worked for me too. Quick and easy!
  • NotTheDr01ds
    NotTheDr01ds about 2 years
    @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.
  • NotTheDr01ds
    NotTheDr01ds about 2 years
    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.
  • NotTheDr01ds
    NotTheDr01ds about 2 years
    @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.
  • Phoenix
    Phoenix about 2 years
    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.
  • NotTheDr01ds
    NotTheDr01ds about 2 years
    @Phoenix Could certainly be related if Docker Desktop stored the "wrong" name somewhere. Try this -- Turn "off" the option for that distro again, then fully reboot. Then try re-enabling in Docker Desktop. Hopefully this will force it to re-scan the names and pick up the right one. If the "wrong one" is set to "on", however, it will probably still stick around.
  • NotTheDr01ds
    NotTheDr01ds about 2 years
    @Phoenix Actually, before trying a reboot, turning Docker off for that distro and try just hitting "Refresh".
  • Pat
    Pat about 2 years
    Thanks. I noticed it because I run Pycharm's interpreters and VSCode in WSL, since our code is meant to run under Linux. They completely broke since they use the name as a link.
  • Anthony Shew
    Anthony Shew about 2 years
    I went with this method and it worked perfect, just for anyone that happens upon this question after me. Can't say anything about the other answer - but this one absolutely works.
  • mgrotheer
    mgrotheer about 2 years
    This solved it for me as well. Thanks
  • Sergey Kudriavtsev
    Sergey Kudriavtsev about 2 years
    I can confirm this solves the issue. Thank you very much!
  • thistleknot
    thistleknot about 2 years
    I don't have a single file but a LocalState folder
  • NotTheDr01ds
    NotTheDr01ds about 2 years
    @thistleknot You may be on WSL1 then. Can you confirm with wsl -l -v? If so, then this answer won't work for you, but the other one (registry edit) should.
  • thistleknot
    thistleknot about 2 years
    I installed wsl2, but my distros are shown as wsl 1 (I have docker showing up as wsl 2)
  • Leo
    Leo about 2 years
    This worked for me . Thank you very much!!
  • JPMC
    JPMC about 2 years
    @NotTheDr01ds Thank you, your answer saved my installation 🙏
  • Admin
    Admin about 2 years
    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.