i3 with WSL2

Sep 23, 2020

WSL configuration

Note This is after WSL2 is configured.

  1. Install i3

     sudo apt install i3 -y
  2. Create an init script

     vim ~/src/scripts/i3launch.sh
source ~/.zshrc
# If not running interactively, don't do anything
[ -z "$PS1" ] && return

export DISPLAY=$(awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null):0

dbus_status=$(service dbus status)
if [[ $dbus_status = *"is not running"* ]]; then
  sudo service dbus --full-restart

Note I’m using zsh instead of bash

Windows configuration

  1. Install vcxsrv from powershell

     winget install vcxsrv

With WSL2 you need to configure your firewall to allow WSL and vcxsrv to communicate.

Search for Windows Defender Firewall with Advanced Security and do the following:

  1. Create an inbound rule:

     name: wsl2
     rule type: port
     port type: tcp
     port number: 6000
  2. Narrow the scope of your inbound rule:

     Right click -> Properties -> scope -> Remote IP addresses -> Add

  3. Search for VcXsrv windows xserver inbound rules and make sure the 4 rules are enabled and in allow mode


  1. Startup i3 script from Windows vcxsrv.vbs

     code vcxsrv.vbs
Set shell = CreateObject("WScript.Shell" ) 

shell.Run """C:\Program Files\VcXsrv\vcxsrv.exe"" :0 -screen 0 @1 -ac +xinerama -engine 1 -nodecoration -wgl"

WScript.Sleep 200

shell.Run "wsl.exe -d YOUR_DISTRO -u YOUR_USER -- /bin/zsh ~/src/scripts/i3launch.sh", 0
  1. And just run your script from powershell


You should see this screen.


i3 configuration

From now on, you are free to modify your i3 as you wish.


To run WSL2 as root

wsl.exe -d Ubuntu-20.04 -u root -- /bin/bash