Skip to content

Instantly share code, notes, and snippets.

@avoidik
Forked from BusterNeece/00-setup.md
Last active August 27, 2022 00:28
Show Gist options
  • Save avoidik/c5351dc4c363c86187fdc46c521087ed to your computer and use it in GitHub Desktop.
Save avoidik/c5351dc4c363c86187fdc46c521087ed to your computer and use it in GitHub Desktop.
My WSL2 Ubuntu 20.04 Environment

My local Ubuntu 20.04 WSL2 setup.

Enable and Install WSL2

From Windows, as admin:

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

Install the latest WSL2 kernel.

Restart, then:

wsl --set-default-version 2

Set up X410 Settings

  • Install X410 from Windows Store
  • Launch X410
  • Right click tray menu, click "Allow Public Access", then allow through Windows Firewall

Set up Ubuntu 20.04

Initial setup inside Ubuntu Bash:

sudo apt-get update
sudo apt-get full-upgrade

# Installing common deps
sudo apt-get install git gpg vim tasksel

# Set up desktop environment
sudo tasksel

# Select "Ubuntu minimal desktop" in tasksel.

# Alternative: Install xfce4 minimal
sudo apt install xfce4 xfce4-terminal

# Alternative: Install gnome minimal
sudo apt install gnome-session gnome-terminal 

# Install the Dotnet Core framework repository
wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb

# Install Genie (for creating a pseudo-systemd-compatible environment to run in)
curl -s https://packagecloud.io/install/repositories/arkane-systems/wsl-translinux/script.deb.sh | sudo bash

sudo apt install -y systemd-genie

# Disable services blocking genie startup
sudo systemctl mask multipathd.socket
sudo systemctl mask systemd-remount-fs.service
  • Create file desktop.sh in user root (select relevant option below).
  • chmod a+x desktop.sh

Launching

  • Create a file launch-desktop.bat (select relevant option below)
  • Run the batch script to start up.

Shutting Down

Shut down the WSL2 instance by running:

wsl -t Ubuntu-20.04
#!/bin/bash
if [ -z "$(pidof gnome-session)" ]; then
export DISPLAY="$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0.0"
export XDG_SESSION_TYPE="x11"
export XDG_RUNTIME_DIR="~/xdg"
export XDG_SESSION_CLASS="user"
export XDG_SESSION_DESKTOP="ubuntu"
export XDG_CURRENT_DESKTOP="ubuntu:GNOME"
export DESKTOP_SESSION="ubuntu"
export GDMSESSION="ubuntu"
gnome-session
fi
#!/bin/bash
if [ -z "$(pidof dbus-launch)" ]; then
export DISPLAY="$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0.0"
dbus-launch --exit-with-x11
fi
if [ -z "$(pidof tilix)" ]; then
export DISPLAY="$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0.0"
export GTK_THEME="Arc:dark"
exec tilix
fi
#!/bin/bash
if [ -z "$(pidof xfce4-session)" ]; then
export DISPLAY="$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0.0"
export XDG_SESSION_TYPE="x11"
export XDG_SESSION_CLASS="user"
export XDG_SESSION_DESKTOP="xubuntu"
export XDG_CURRENT_DESKTOP="XFCE"
export DESKTOP_SESSION="xubuntu"
export GDMSESSION="xubuntu"
xfce4-session
fi
@echo off
cd /d %~dp0
start /B x410.exe /desktop
ubuntu2004.exe run "genie -c desktop-gnome.sh"
@echo off
cd /d %~dp0
start /B x410.exe /desktop
ubuntu2004.exe run "genie -c desktop-xfce4.sh"
@avoidik
Copy link
Author

avoidik commented Mar 30, 2021

Misc xfce4 settings

# we won't need login manager for single session scenario
sudo apt-get remove lightdm
sudo apt-get autoremove
# we won't need ssh and gpg agents
xfconf-query -c xfce4-session -p /startup/ssh-agent/enabled -n -t bool -s false
xfconf-query -c xfce4-session -p /startup/gpg-agent/enabled -n -t bool -s false

Enable sound (pulseaudio)

https://x410.dev/cookbook/wsl/enabling-sound-in-wsl-ubuntu-let-it-sing/

in etc/pulse/default.pa set additional CIDR

load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1;172.16.0.0/12

add the following line into the desktop-xfce4.sh or desktop-gnome.sh script

export PULSE_SERVER="tcp:$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}')"

batch files will be different

@echo off
cd /d %~dp0
start /B x410.exe /desktop
start /B C:\tools\pulseaudio\bin\pulseaudio.exe
ubuntu2004.exe run "genie -c ~/.local/bin/desktop-xfce4.sh"
taskkill /F /IM x410.exe
taskkill /F /IM pulseaudio.exe
del /q %HOMEDRIVE%%HOMEPATH%\.pulse\%COMPUTERNAME%-runtime\pid

Resolve cryptic error with WSLInterop

Like this

ls: cannot open directory '/proc/sys/fs/binfmt_misc': Too many levels of symbolic links
cat <<'EOF' | sudo tee /etc/rc.local
#!/bin/sh -e

ls /proc/sys/fs/binfmt_misc > /dev/null 2>&1 || \
  mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc

exit 0
EOF
sudo chmod +x /etc/rc.local

Genie profile script

# Are we connecting over ssh?
if [[ -v SSH_CLIENT ]]; then
  TMPFILE="$(mktemp --tmpdir XXXXX.tmp)"
  systemctl show-environment | awk '{print "export "$0}' >> "$TMPFILE"
  source "$TMPFILE"
  rm "$TMPFILE"
fi

# Are we in the bottle?
if [[ ! -v INSIDE_GENIE ]]; then
  read -t 3 -p "About to enter the genie bottle in 3 seconds, abort (y/n)? " yn
  echo

  if [[ $yn != "y" ]]; then
    exec /usr/bin/genie -s
    echo "Done!"
  else
    echo "Aborted!"
  fi
else
  echo -n "Waiting for systemd units to finish..."
  until systemctl --user is-system-running &>/dev/null ; do
    sleep 1
    echo -n "."
  done
  echo "Done!"
fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment