Photo - Torsten Dederichs
Photo

WSL

Reset WSL2 Quickly

If you're getting Network Unreachable in WSL2 for some reason, try this:

sudo Disable-WindowsOptionalFeature -Online -FeatureName -NoRestart `
    $("VirtualMachinePlatform", "Microsoft-Windows-Subsystem-Linux")
sudo Enable-WindowsOptionalFeature -Online -FeatureName `
    $("VirtualMachinePlatform", "Microsoft-Windows-Subsystem-Linux")

Systemd in WSL2

It should 'just work' now, but sometimes you may need to set something in your wsl.conf:

# /etc/wsl.conf
[boot]
systemd=true

Import WSL2 disks in place

You can just import random vhdx disks you have with:

wsl --import-in-place ubuntu ext4.vhdx

You don't need to export them or anything, just getting the vhdx is enough.

You can put them generally anywhere, even some random dev drive.

Sparse WSL2 disks

You can make your WSL2 disks sparse now, saving disk space.

To make a distro sparse:

wsl --manage $DISTRO $ --set-sparse true

Also:

# ~/.wslconfig

[experimental]
sparseVhd=true

            bdd2fe91a05bbcd4b0985af5639435252b217403