WSL2 support update

Hello,

I wanted to ask whether there are ideas to support dietpi as a wsl distro. :slight_smile:

My last information is, that WSL don’t support systemd, which is a basic requirement for DietPi. Not sure if this changed in meantime.

Thanks for the quick answer!
It seems like systemd is available since last september:

I dont want to push any things which are not in the diepi’s creators mind, just asking because I tried pengwin wsl distro and it was way more limited than what I am used to with dietpi :slight_smile:

Theoretically WLS2 is working using Debian and our own install script Supported hardware - DietPi.com Docs

Additional settings might be needed inside WLS Debian to fix some DNS issues and to force systemd

root@gram:~# cat /etc/wsl.conf
[network]
generateResolvConf = false

[boot]
systemd=true
root@gram:~#

I changed WSL Debian as default in Windows cmd

C:\>wsl --list --all
Windows Subsystem für Linux-Distributionen:
Debian (Standard)
Ubuntu

C:\>

and use wsl -u root to start conatiner as user root. At least from same host system, SSH is working as well

However I had some network issues and it was needed to set STATIC IP. Somehow DHCP was not working as it did not set a default gateway. Not sure why becuase it worked on first place. :thinking:

1 Like

I made a quick test with a VM under Proxmox. But I could not activate the Hyper-V hypervisor in the machine, so in this environment, i failed to install WSL 2 to run the DietPi conversion script.

@andey what would be your use case for running DietPi WSL system?

I do not have a specific use case to be honest.
My simple idea was, that it might be a good thing to be able to test changes before applying them to my productive dietpi system.
Perhaps it would even be possible to make a backup of a dietpi system and troubleshoot it using wsl.
Or simply using the quick installer to spin up a webserver/dev-environment/… for development or testing new software and so on :slight_smile:

For testing, it might be easiest to use Hyper-V or VirtualBox. There you could use fully supported VM’s

However, your idea of restoring systems on a VM might not goanna work. You need to keep in mind the chip architecture used. Usually, SBC are based an ARM while VM’s or native PC use x86. Therefore, you can’t restore such a backup. It depends on what your source system is and where you like to restore on. Even between SBC this will not work. Each manufacture use own kernel and software modules. In an ideal world you would have 2 identical systems that you can compare with each other :smiley:

I was just brainstorming :smiley:

Since I do not want to a WSL2 Debian image or Docker container as a starting point for a DietPi WSL2 image, I’m still trying to future out how to create one from scratch, via debootstrap only. It does not need a bootloader and no kernel, so is close to a container image (well, of course, a Docker image can be imported). It internally mounts an /init “file” as primary or secondary (if systemd support is enabled) init command, similar to how it exists in Docker images. But something else is missing for WSL2 to boot an image. If anyone knows what this might be, I’d be highly interested.

I’ll have another careful look into the VHDX image file of minimised official WSL2 Debian image to hopefully find other required files/dirs needed for WSL to boot it.

Hi there,
with windows 11 there is support for bridged mode, but still undocumented. I’ve managed to assign static ip as per Bridged Networking under WSL - by Alistair Young article. Unfortunately pi hole uses lighttpd as service, and I want to use nginx, and couldn’t manage to setup correctly. nginx also changed some config file and folder structure, there is no sites-enabled for example.
For setting ip at boot I’ve used crontab “@reboot /usr/local/bin/configure_ip.sh” it contains just ip addr add dev eth0 … and add route stuff

If there is no web server installed at the beginning, you should be ask which web server to choose. We offer installation for Nginx and Apache as well.

I figured out how make DietPi work in WSL2. You first download the Native PC x86_64 hard drive image, not the installer, and flash it to a usb pendrive. Once that has booted onto a computer, run the command “tar -cvpf /dietpi.tar --exclude=/dietpi.tar --exclude=sys --exclude=dev --exclude=proc /” and it will put a copy of almost the entire system into a .tar archive. Be sure that the archive is accessible from within Windows. Next, boot into Windows, open PowerShell, and type in the command “wsl.exe --import DietPi C:<whatever folder you want to put your WSL2 system folder into>\Dietpi \dietpi.tar” and wait for it to finish. After that finishes, it will be ready to use.
If you want to enable systemd support, create a file in /etc called ‘wsl.conf’ that will contain the settings for this WSL2 distro. On a distro installed from the Microsoft Store or PowerShell, this would already exist. In the file, write “[boot]” into the first line, then “systemd=true” into a second line. After you save that file, end the running session of WSL and wait about eight seconds, or until ‘wsl.exe --list --running’ shows that your DietPi distro isn’t running. Then you can boot up DietPi in WSL2 again and the changes made to ‘wsl.conf’ will be in effect.
There are more settings you can put in that WSL config file. They can be found at Advanced settings configuration in WSL | Microsoft Learn