Skip to content

Instantly share code, notes, and snippets.

@4wk-
Last active November 10, 2024 17:26
Show Gist options
  • Save 4wk-/889b26043f519259ab60386ca13ba91b to your computer and use it in GitHub Desktop.
Save 4wk-/889b26043f519259ab60386ca13ba91b to your computer and use it in GitHub Desktop.
Clean uninstall then reinstall of WSL on Windows 10, with systemD support

Uninstall then reinstall WSL on Windows 10 (clean way)

Background

I've been using wsl (version 2) with genie mod for years without issue, but one day, Windows 10 finally catch up on wsl Windows 11 features and gives us a way to use systemD natively.

I wanted to use the new "right way" to enable systemD on Windows Subsystem for Linux (without genie), and I also had a (probably related) infinite Windows RemoteApp error poping in.

Fixing it

A - Uninstall wsl and related stuff

  1. In powershell (as admin)
# list all installed distros
wsl -l -v

# destroy distros
wsl --unregister Ubuntu
wsl --unregister Debian # and so on

 

  1. In Settings > Apps > Apps & Features
  • search for Ubuntu (then Debian, etc), and if something is found, click on uninstall
  • search for Linux, and if something is found, click on uninstall on all results

 

  1. In Start Menu > Turn Windows Features on or off
  • Untick Virtual Machine Platform checkbox
  • Untick Windows Subsystem for Linux checkbox

 

  1. Reboot
  • I might have reboot between step 2) and 3) as well.

B - Re-install and configure wsl to use systemD

The process of installing wsl have become super straightforward.

  1. Installing wsl - In powershell (as admin)
# install wsl
wsl --install

Then reboot and wait for the Ubundu installation to complete and ask for username (it might takes some time).

 

  1. Optional: Changing distribution - In powershell (as admin)
# list available distributions
wsl --list --online

# install favorite distro
wsl --install -d Debian

# set Debian as default
wsl --set-default Debian

NB: wsl --set-default-version 2 is not needed anymore.

 

  1. Enabling systemD support - Inside wsl
  • Launch your distribution
  • Edit /etc/wsl.conf (or create the file if it doesn't exist)
[boot]
systemd=true

# Optional: remove windows from PATH (autocompletion)
[interop]
appendWindowsPath = false

 

  1. Clean rebooting - In powershell (as admin)
# clean shutdown
wsl --shutdown

Great success! 🎉 You have now enabled systemD in wsl natively. You can test it with sudo systemctl status time-sync.target (inside your Linux distribution).


NB: System wide configuration file .wslconfig will not be deleted/reseted, you would have to do it manually.

Let me know if I missed anything, I'll be glad to update this gist.

@kolos181
Copy link

@ricardoalcantara Are you sure you were on an elevated Powershell? AFAIK, the wsl --install command enable both of them on its own. I will test it again soon-ish.

It was enabled for me automatically as well

@T-helper
Copy link

Thanks Dude ! It's awesome and resolve a lot of troubles

@MaxBu
Copy link

MaxBu commented Oct 6, 2023

very helpful thank you!

@henryjams
Copy link

Okay so just had big problems following this guide, but at no fault of the author. In case anyone has the same problems I did:

Error code: 0x80370102

You have to enable Virtualization in your BIOS. This will depend on your motherboard, but once you have enabled Virtualization (called SVM on my MSI motherboard) then you will need to re-install WSL according to this guide. Once I did that, it worked well.

@locdhthtb
Copy link

Do these steps clean up WSL network ?

@devin-AK
Copy link

devin-AK commented Jan 8, 2024

For the sake of completeness, note that the .wslconfig settings will not be deleted/reset using this method.

@4wk-
Copy link
Author

4wk- commented Jan 8, 2024

@locdhthtb I'm not sure what you mean with "WSL network", sorry.
@devin-AK I've updated the gist; thank you!

@DanKaplanSES
Copy link

DanKaplanSES commented Jan 25, 2024

Note: I'm a Win 10 user

Very helpful. What would you think about linking to the import/export documentation? And steps from https://learn.microsoft.com/en-us/windows/wsl/install-manual ?

Also, probably worth mentioning wsl --update.*

If you are importing from an exported distribution, the default user will be root even if it was a different user when exported. Read the warning at the bottom of this section to learn how to set it back to the previous user: https://learn.microsoft.com/en-us/windows/wsl/basic-commands#change-the-default-user-for-a-distribution

UPDATE

I was following these steps because I experienced the all too common "WSL2's wsl.exe hangs forever" symptom.

* These additional steps resolved my issues:

  1. Include "Hyper-V" in your A.3. step. I turned it back on manually, but I'm not sure if I needed to.
  2. Don't run wsl --update.

I'm not sure if both of these are required; I've yet to take the time to narrow it down.

@agrotecnia
Copy link

after the last update of win 11 i can´t lauch docker (i´m really rookie in terms of console and these things). your steps helped me solve the problem. Thank you very much!!!!

@MateBalint
Copy link

MateBalint commented Mar 25, 2024

Worked perfectly. It was very helpful. Thank you!

@recoil24
Copy link

Thank you. Its perfect +rep

@DanielOX
Copy link

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment