2

A couple of months ago, I had created a WSL1 and used the Ubuntu app under the username void Later on, I have decided to upgrade it to WSL2, but I have encountered an error while upgrading it. Later on, I have discovered that it was due to BIOS virtualization settings.

In any case, I have performed these operations to delete the WSL2.

https://pureinfotech.com/uninstall-wsl2-windows-10/

  1. Delete Ubuntu App
  2. Uninstall Windows Subsystem for Linux update
  3. Clear the Virtual Machine Platform option from the Windows Features
  4. Clear the Windows Subsystem for Linux option from the Windows Features

After these operations, I enabled the BIOS virtualization and downloaded the WSL2 again, which runs perfectly fine.

The problem is I wonder what happened to the files that I have created under WSL1 under the void username. Are they also deleted after doing the above operations, or are they just somewhere in my Windows machine.

Similar second question:

If I delete my Ubuntu app (from Windows Store), does that also delete all my data (folders, etc.) that I have created under that username?

1 Answer 1

2

Short answer: When you uninstalled WSL1 Ubuntu, the files you created in it were almost certainly removed as well.

More Details:

As with most Windows 10 apps installed from the Microsoft Store the App itself usually gets installed to a subdirectory of C:\Program Files\WindowsApps. This directory is protected from normal user access, so you don't typically interact with it.

Then, when you run ubuntu.exe (or one of its variants) for the first time, WSL creates an "instance" (often called "distro", but that term really should be reserved for its normal definition IMHO). That instance is installed to %userprofile%\AppData\Local\Packages\Canonical...\. The Canonical... subdirectory name will vary slightly depending on which version you installed from the Store.

All of the files that you see in the root filesystem in WSL live in the ..\Canonical...\LocalState subdirectory.

  • For WSL1, the files are actually visible in Windows itself under ..\LocalState\rootfs, but should never be accessed directly (or risk corruption).
  • For WSL2, the files live in a virtual HDD named ext4.vhdx in that same directory.

Regardless of the version, uninstalling the Store app removes both the App package in C:\Program Files\WindowsApps\... and the filesystem at %userprofile%\Local\Packages\Canonical....

I actually wasn't sure, but I tried it out on a few systems with distros that I wasn't using to confirm. I'm honestly a bit surprised, since there's a bit of an expectation that uninstalling an app shouldn't uninstall the data that goes with that app. But, with WSL distributions installed from the Store, it does.

Note that you can back up your instances quite easily, and I do so regularly, especially immediately after installing so that I have a "clean/fresh" image that I can use to create additional instances. One of the nice things about WSL is how quickly you can spin up a new instance of a distribution to try something out, then throw it away again when you are done.

The wsl --export command is used to back up an instance. It will create a tarball of all files (including system and user files) in the instance. That tarball can then be used to create a new instance with wsl --import. The nice thing about these imported images is that they are not tied to the App itself. In other words, uninstalling the Store app will not deleted instances that you created manually with wsl --import.

Coincidentally, I've been moving all of my "Store-installed" instances over to "manual" instances recently. There are also additional advantages:

  • You can create these new instances on any drive/subdirectory. It's not limited to your AppData directory.
  • As mentioned, uninstalling the Store app will not remove these instances.
  • You can name them whatever you want, such as Ubuntu20.04_WSL1

Also note that the Windows 11 version of WSL has the ability to wsl --mount additional drives (both physical and virtual). As I move to Windows 11, my plan is to see how well this will work for creating a separate drive to mount on /home, so that my user data is on a separate .vhdx than the root filesystem.

1
  • thanks for the detailed answer
    – Neptune
    Commented Oct 13, 2021 at 12:27

You must log in to answer this question.

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