Skip to content

Instantly share code, notes, and snippets.

@ulexxander
Last active July 17, 2023 08:14
Show Gist options
  • Save ulexxander/df9d65f799db82bba66fb1174e5d4bac to your computer and use it in GitHub Desktop.
Save ulexxander/df9d65f799db82bba66fb1174e5d4bac to your computer and use it in GitHub Desktop.
Setting up and troubleshooting WSL2 development environment.

WSL

Installation

Command on boot

Advanced settings configuration in WSL | Microsoft Learn

/etc/wsl.conf contents:

[boot]
command = /etc/wsl-boot.sh

/etc/wsl-boot.sh contents:

#!/bin/bash
service docker start

Make script executable:

chmod +x /etc/wsl-boot.sh

Troubleshooting

Vmmem process consumes too much RAM

What Is the Vmmem Process in Windows Task Manager? Here's How to Fix Its High Resource Consumption

Create global WSL config in C:\Users\<UserName>\.wslconfig and specify memory limit, for example 6 gigabytes:

[wsl2]
memory=6GB

Time out of sync

$ date
Fri Jan 20 20:44:19 CET 2023
$ sudo hwclock -s
$ date
Mon Jan 23 13:30:07 CET 2023

TODO: proper solution, either NTP server sync or cron job.

Copying to clipboard on command line

xclip is already installed on Ubuntu 22.04, but will not work. To copy into Windows clipboard use clip.exe instead, example:

echo 123 | clip.exe

Some CLI tools like pass depend on xclip or wl-copy. To make it work, make system-wide shim to clip.exe:

Create /usr/local/bin/xclip and /usr/local/bin/wl-copy with contents:

#!/bin/sh
clip.exe

Make both executable: chmod +x /usr/local/bin/xclip /usr/local/bin/wl-copy

Now pass running in WSL is able to copy your secret into Windows clipboard:

$ pass -c some-website/my-password
Copied some-website/my-password to clipboard. Will clear in 45 seconds.

Firefox paths on the command line

Shim to open file under WSL in firefox which is running on host Windows.

Create /usr/local/bin/firefox:

#!/bin/bash

WSL_HOST_PATH="file://///wsl.localhost/Ubuntu"

ARG=$(echo "$1" | sed -r "s|^(file://)?/|$WSL_HOST_PATH/|")

"/mnt/c/Program Files/Mozilla Firefox/firefox.exe" "$ARG"

Test:

firefox $HOME
# Should serve your home directory in browser.
# file://///wsl.localhost/Ubuntu/home/alex

Docker Engine fails to start because of iptables

WSL2 Kernel do not support nftables and causing docker failed to start up in Ubuntu 20.10+ · Issue #6655 · microsoft/WSL

/var/log/docker.log

failed to start daemon: Error initializing network controller: error obtaining controller instance: unable to add return rule in DOCKER-ISOLATION-STAGE-1 chain:  (iptables failed: iptables --wait -A DOCKER-ISOLATION-STAGE-1 -j RETURN: iptables v1.8.7 (nf_tables):  RULE_APPEND failed (No such file or directory): rule in chain DOCKER-ISOLATION-STAGE-1
 (exit status 4))
sudo update-alternatives --set iptables /usr/sbin/iptables-legacy
sudo update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy

No internet in WSL when Docker starts

WSL2 DNS stops working · Issue #4285 · microsoft/WSL

May be caused by conflicting IP ranges that WSL and Docker use.

Solution: add to or create /etc/docker/daemon.json with:

{
   "bip" : "10.99.0.1/16"
}

MTU set on interface is too large for github.com

MTU is the largest packet or frame size, specified in octets (eight-bit bytes) that can be sent in a packet- or frame-based network.

Hangs out on TLS handshake, Client hello (1).

$ curl -v https://github.com
*   Trying 140.82.121.3:443...
* Connected to github.com (140.82.121.3) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
*  CAfile: /etc/ssl/certs/ca-certificates.crt
*  CApath: /etc/ssl/certs
* TLSv1.0 (OUT), TLS header, Certificate Status (22):
* TLSv1.3 (OUT), TLS handshake, Client hello (1):

Interface eth0 before:

$ ip link list
6: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
    link/ether 00:15:5d:89:cc:39 brd ff:ff:ff:ff:ff:ff

Changing MTU for eth0:

sudo ip link set dev eth0 mtu 1300

Interface eth0 after:

$ ip link list
6: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1300 qdisc mq state UP mode DEFAULT group default qlen 1000
    link/ether 00:15:5d:89:cc:39 brd ff:ff:ff:ff:ff:ff

Find out suitable MTU size. You need greatest number that succeeds. Here MTU of size 1300 is being tested:

$ ping -c 1 -M do -s 1300 github.com
--- github.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 22.622/22.622/22.622/0.000 ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment