5

I've installed Ububtu-20.04 on my Windows 11 machine using WSL2. I've recently uninstalled it and installed Ubuntu-22.04 to replace it.

When I go on My PC to Linux I still see a share of Ubuntu-20.04 with all the files inside of it. How can I get rid of those files along with the share?

enter image description here

2 Answers2

9

Short answer: wsl --unregister <distro> (from PowerShell or CMD, a non-admin session) should remove the distribution, all files in it, and the share.

More detail:

Some brief history and background is needed to understand what's going on. When you install a distribution (e.g. Ubuntu) in WSL, two things get installed:

  • First, the Store package itself (in C:\Program Files\WindowsApps\<distroPackage>). You can see this by going to an Admin PowerShell and running:

    Get-ChildItem -Recurse 'C:\Program Files\WindowsApps\' | Where-Object {$_.Name -eq 'install.tar.gz' }
    
  • Then, when you start the distribution for the first time (e.g. ubuntu.exe or ubuntu2204.exe, etc.), it installs the actual rootfs and registers the distribution. You can see these with (no Admin required):

    Get-ChildItem HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss\ |
     ForEach-Object {
         (Get-ItemProperty $_.PSPATH) | Select-Object DistributionName,BasePath
     }
    

There was a time, under Windows 10 (and it may still be the case) that when you uninstalled the Store package (via "Add or Remove Programs" or a right-click "Uninstall" on the Start Menu item) that it would also uninstall the distribution files.

That was bad.

For starters, the "Uninstall" info for Store apps in Windows says, "Your documents will not be affected", which wasn't true for WSL distributions. This caused loss of data, for at least this user.

At some point, and I believe it was in Windows 11, this changed so that uninstalling the Store package, like you've done, did not remove the distribution and its files. I think this is a better approach.

Now, you remove a WSL distribution in two, independent steps:

  • Uninstall the Store Package
  • wsl --unregister the distribution

I would still, being paranoid, recommend a backup of a distribution (wsl --export) before removing the Store package. Just in case ...

NotTheDr01ds
  • 21,923
0

The user needs to perform a list operation before trying to unregister:

wsl --list --all

if the app that the user wishes to uninstall is the default. That needs to be changed or it will not unregister.

The user needs to type in the complete name as it is displayed in the list results. In this case:

wsl --unregister Ubuntu-20.04
Toto
  • 17,839
bondo
  • 21