3

Related: Is there a way of installing Windows Subsystem for Linux on Win10 (v1709) without using the Store?

When installing a WSL distribution outside of the Microsoft Store (for example on a restricted network, see linked), many of the standard means of interacting with that distribution are not available. In my example, when I go through Settings > Apps and Features, the distro is not shown in the list and the management features are not available. If I get my manually installed linux instance into a bad state, what is the correct way to reset it and bring it back to a fresh install?

Edit: Examples of a 'bad state' encountered thus far include a BSOD during an 'apt-get update', leading to an unrecoverable state. Also, performing multiple configuration changes to troubleshoot a problem, removing or disabling services and installing other packages without keeping close track of what was changed, with a desire to "start fresh" to test if the solution arrived at does in fact work on its own..

0

5 Answers 5

8

If I get my manually installed Linux instance into a bad state, what is the correct way to reset it and bring it back to a fresh install?

If you are running Windows 10 Version 1903:

wsl --unregister <DistributionName>

If you are running Windows 10 Version 1709, 1803, or 1809:

wslconfig /unregister <DistributionName>

Manage and configure Windows Subsystem for Linux

1
  • I am under the assumption you installed your WSL Distribution using this method.
    – Ramhound
    May 22, 2019 at 22:24
1

You may use Chocolatey (with a private NuGet repository for instance) and choose Debian image with:

choco install wsl-debiangnulinux

But then

  • only shortcuts are available like "WSL Terminal" and "Debian Terminal".
  • you will not be prompt for a user creation, only a root shell is started
  • you will not find your Linux distribution for WSL in "Settings / Apps and Features" and so no "Advanced options" or "Reset"

By the way, wsl command line is available but then you have to manually create your user account (useradd or adduser according to distribution), grant sudo (sudo group or sudoers), and create /etc/wsl.conf with [user] section and default=yourlogin - refer to wsl-config documentation. In my case, <distribution> config --default-user yourlogin had no effect.

In case of definitive outage, the only option seems to run following sequence of:

wsl --export <distribution> wsl-backup-<distribution>.tar
wsl --unregister <distribution>
choco install wsl-<distribution>
wsl --import <distribution> wsl-backup-<distribution>.tar

with hope your troubles do not follow you with imported files.

0

Warning: The following information is not entirely officially documented because the question deals with "manual installation" of distribution in WSL. Hence the procedure may be little different in future Windows 10 releases.

To understand it first we need to know what is the difference between installing distribution through Windows Store and manually. Think Windows Store as a package manager in Windows. It monitors all the packages installed, uninstalled, updated etc. So, there is a list of installed apps in Settings menu. When the distribution is installed it comes as an Appx package (ZIP archive). That package contains a rootfs tarball (GZIP tar file) of that distribution (example install.tar.gz), a launcher executable (example ubuntu.exe) and some other stuffs.

When that launcher is first executed it extracts the tarball (like tar -xf command) and makes a registry entry in HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss\{GUID} registry key. This registry key is important which provides where the distribution is installed, default user etc.

When the distribution is installed manually this same registry key is created but with different basepath and others. As this manual procedure does not comes through Windows Store, it is not listed in Settings app. But wsl.exe --list --all command can show all the installed distribution in WSL. In this way, we do not get the launcher executable but we can do all the stuffs with wsl.exe.

How can we reset from 'bad state'? If you are familiar with UNIX world assume distributions in WSL as in chroot-ed environment. Always backup a WSL distribution. As usual in real Debian based distributions we generally run these commands to fix packages:

sudo dpkg –configure -a
sudo apt update –fix-missing
sudo apt install -f

If those can not fix the issue uninstall and reinstall may fix it. You may like to backup the /home folder with tar -czf because most of the user specific configurations are saved there. Next uninstall the distribution with wsl.exe --unregister <Distribution Name> command. The backup may be important to users because the previous command removes the whole root folder aka. /. Now you can install a new distribution and extract the previous /home backup folder with tar -xf as usual.

2
0

Alternatively, you can go to Settings, Apps and features, select your distribution and go to Advanced options. There you can click Reset to delete all application data and restore it to default, so next time you open it it will ask for your username and the rest of initial configuration.

The advantage to the accepted answer is that with this method you don't need to reinstall your linux distro through Microsoft Store. In certain scenarios, like being behind a corporate proxy, installing from Microsoft Store is no easy task, so this way there's no need to do that again.

0

Try this:

wsl --set-default-version 2

You can also set the version of wsl to any installed distributive:

wsl --set-version Ubuntu-20.04 1

You must log in to answer this question.

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