WSL | Cookbook

Inhaltsverzeichnis

Configuration

wsl.conf

Sample wsl.conf

[boot]
systemd=true

[network]
hostname = playground
generateHosts = false

Basics

Run specify distribution

 wsl --distribution Ubuntu-22.04
 wsl -d Ubuntu-22.04

Run Distribution and login as root

wsl -d Debian -u root

Change root password

 wsl.exe --user root --distribution Alpine passwd

Running X Apps

https://nickjanetakis.com/blog/using-wsl-and-mobaxterm-to-create-a-linux-dev-environment-on-windows

export DISPLAY="$(/sbin/ip route | awk '/default/ { print $3 }'):0"

Boot Configuration

systemd

Set the systemd flag set in your WSL distro settings

You will need to edit the wsl.conf file to ensure systemd starts up on boot.

Add these lines to the /etc/wsl.conf (note you will need to run your editor with sudo privileges, e.g: sudo nano /etc/wsl.conf):

[boot]
systemd=true

And close out of the nano editor using CTRL+O to save and CTRL+X to exit.

Final Check

Close your WSL distro Windows and run wsl.exe --shutdown from PowerShell to restart your WSL instances. Upon launch you should have systemd running. You can check this with

systemctl list-unit-files --type=service

Change Hostname

Edit /etc/wsl.conf

[network]
hostname = wsl2
generateHosts = false

Change the hostname in /etc/hosts and /etc/hostname

# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateHosts = false
127.0.0.1      localhost
127.0.1.1      wsl2.localdomain        wsl2

Shutdown wsl

wsl --shutdown

Distributions

Create a new Distribution

Export a distribution

wsl --export Ubuntu-22.02 ubuntu.tar

Import with new name

wsl --import MyUbuntu D:\WSL\Distributions\MyUbuntu ubuntu.tar