NOTE: If you have Windows 11 there is now an official way to do this in WSL 2, use it if possible - see MS post here (WINDOWS 11 ONLY)
This guide will enable systemd
to run as normal under WSL 2. This will enable services like microk8s
, docker
and many more to just work
during a WSL session. Note: this was tested on Windows 10 Build 2004, running Ubuntu 20.04 LTS in WSL 2.
-
To enable
systemd
under WSL we require a tool calledsystemd-genie
-
Copy the contents of
install-sg.sh
to a new file/tmp/install-sg.sh
:cd /tmp wget --content-disposition \ "https://gist.githubusercontent.com/djfdyuruiry/6720faa3f9fc59bfdf6284ee1f41f950/raw/952347f805045ba0e6ef7868b18f4a9a8dd2e47a/install-sg.sh"
-
Make it executable:
chmod +x /tmp/install-sg.sh
-
Run the new script:
/tmp/install-sg.sh && rm /tmp/install-sg.sh
-
Exit the WSL terminal and shutdown the WSL env:
wsl --shutdown
-
To open a new WSL terminal with
systemd
enabled, run:wsl genie -s
-
Prove that it works:
sudo systemctl status time-sync.target
Technically speaking, WSL is a VM. The main difference is the kernel. The kernel in WSL distributions is different because Microsoft develops it. Per Microsoft, it is intended to be used for interoperability during development. Everyone can read the docs here: https://learn.microsoft.com/en-us/windows/wsl/about.
During development on Windows, you absolutely should be using WSL for Docker. There is nothing to disagree with. What you describe are development purposes.
If someone intends to keep a heterogeneous Linux system for production, they should use the Linus-developed kernel distributions in a VM.
There are valid reasons why this is best practice from Microsoft and the Linux community and not a matter of opinion. Using the documentation from Microsoft, I'll go ahead and elaborate so others can know the differences.
From the documentation: https://learn.microsoft.com/en-us/windows/wsl/faq#who-is-wsl-for-
Who is WSL for?
"This is primarily a tool for developers, especially web developers, those working on open source projects, or deploying to Linux server environments. WSL is for anyone who likes using Bash, common Linux tools (sed, awk, etc.) and Linux-first frameworks (Ruby, Python, etc.) but also enjoys using Windows productivity tools."
From the documentation: https://learn.microsoft.com/en-us/windows/wsl/faq#can-i-use-wsl-for-production-scenarios--
Can I use WSL for production scenarios?
"WSL has been designed and built to use with inner loop development workflows. There are design features in WSL that make it great for this purpose but may make it challenging for production-related scenarios compared to other products. Our goal is to make clear how WSL differs from a regular VM environment, so you can make the decision on whether it fits your business needs."
The main differences between WSL and a traditional production environment are:
In summary, Microsoft is saying that WSL is not intended to replace running Linux as a VM, regardless of how WSL performs. WSL can do certain things that make it ideal for development workflows. However, it's been designed to operate differently than users expect from a typical Linux system. This makes it not ideal for production or long-running utilization. The confusion can stem from when a development tool is released to the public, and non-developers start to use it and think it's something it is not.