56

I've installed Linux Subsystem for Windows on my machine. It works beautifully!

Since then, I've done unspeakable things to my install. Nothing works anymore. How do I start again from scratch?

1
  • This is no longer the recommended approach. PS C:\IaC> lxrun /uninstall Warning: lxrun.exe is only used to configure the legacy Windows Subsystem for Linux distribution. Distributions can be installed by visiting the Windows Store: aka.ms/wslstore Mar 1, 2018 at 5:24

5 Answers 5

57

You can reset Ubuntu from settings, just find it in the start menu, right-click to go to App settings, then press the reset button.

find ubuntu in start

reset from settings

5
  • 13
    Damn.. didn't expect it would be that straightforward! Oct 10, 2019 at 13:07
  • 2
    that ends in: Error code: Wsl/Service/CreateInstance/MountVhd/ERROR_FILE_NOT_FOUND
    – Andre
    Oct 30, 2023 at 16:03
  • Failed to attach disk 'C:\Users\User\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu22.04LTS_79rhkp1fndgsc\LocalState\ext4.vhdx' to WSL2: The system cannot find the file specified. Error code: Wsl/Service/CreateInstance/MountVhd/HCS/ERROR_FILE_NOT_FOUND Feb 28 at 15:22
  • @MuhammadIkhwanPerwira In this case I would try to Repair the whole installation or even uninstall and reinstall. Sorry.
    – Qwerty
    Feb 29 at 13:40
  • this corupt my ubuntu. Apr 2 at 14:36
23

Open Command Prompt (AKA cmd.exe), and type lxrun /uninstall. That should wipe your Ubuntu image.

Once this is done, you can reinstall with lxrun /install.

References:

2
  • This would have to be run in the Windows cmd.exe shell, right?
    – Byte Commander
    Apr 23, 2016 at 17:37
  • Yup. I've edited to clarify. Apr 23, 2016 at 18:30
10

With the new distro-specific store apps, for example:

C:\> ubuntu /?
Launches or configures a linux distribution.

Usage:
    <no args>
      - Launches the distro's default behavior. By default, this launches your default shell.

...

    clean
      - Uninstalls the distro. The appx remains on your machine. This can be
        useful for "factory resetting" your instance. This removes the linux
        filesystem from the disk, but not the app from your PC, so you don't
        need to redownload the entire tar.gz again.

So, ubuntu clean should be enough.

If ubuntu clean fails, then you'll have to uninstall the app from the store and reinstall it. See WSL #2387.

1
  • The ubuntu clean flag has been removed from the app.
    – James
    Jan 6 at 5:47
9

After WSL 2 it's simple:

wsl --unregister Your_Ubuntu_distro

How to get distro name?

wsl --list

Per https://docs.microsoft.com/en-us/windows/wsl/basic-commands:

Caution: Once unregistered, all data, settings, and software associated with that distribution will be permanently lost. Reinstalling from the store will install a clean copy of the distribution. For example, wsl --unregister Ubuntu would remove Ubuntu from the distributions available in WSL. Running wsl --list will reveal that it is no longer listed.

You may want to backup your home directory and other data prior to unregistering the distro.

1
  • Only this solution worked for me.
    – steph643
    Oct 12, 2023 at 7:39
0

launch -> cmd /d

ubuntu config --default-user root

launch -> C:\Windows\System32\bash

passwd your_username set new_password and confirm new_password close the bash

back into cmd /d

ubuntu config --default-user your_username

Launch the bash and fell free to use the new_password for your_username when needed (like for a "sudo apt-get install gcc")

1
  • This helped me resetting my lost password. Instead of doing the complete reinstallation or cleaning, I just did a password reset. Thanks! Feb 12, 2022 at 17:35

You must log in to answer this question.

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