Skip to content

Pro Windows Subsystem for Linux (WSL) book “review”

Review is in quotation marks because this is not a full review, this is a summary and tips of what I learned from this book. When reading it my main focus was to improve my Kubernetes, terraform script workflow. Which involve windows file/directory navigation, editing files on WSL, managing WSL distributions.

Default parameters

First lets identify which distributions are installed, which are default and make sure we starting them with correct user.

wsl.exe --set-default-version 2 
wsl.exe --list --verbose --all
 NAME                   STATE           VERSION
* Ubuntu                 Running         2
  docker-desktop-data    Running         2
  docker-desktop         Running         2 

Name – <wsl distro name> in following commands

wsl.exe --set-default <wsl distro name>
wsl.exe --set-version <wsl distro name> 2
<wsl distro name> config --default-user <new user name>

File permissions

Even though file permissions doesn’t really fit into what I was looking in this book, wanted to write this down for future reference:

Three groups (<user><group><other>):

  • User – by default user who created
  • Group – users in a group with assigned access to files
  • Other – all other users

Symbolic form:

  • r – Read
  • w – Write
  • x – Execute
  • – (just dash) for no permission

Example: rwx-r-xr-

  • rwx – for user
  • -r- -for group
  • xr- – for other

Numeric form

  • 0 – No permissions, —
  • 1 – Execute only, –x
  • 2 – Write only, -w-
  • 3 – Write and execute, -wx
  • 4 – Read, r–
  • 5 – Read and execute, r-x
  • 6 – Read and write, rw-
  • 7 – Read, write and execute, rwx

Previous example can be written: 745

Convert between Linux and Windows paths

One of the biggest issue for me right now are navigating windows directories in Linux and vice versa.

wslpath -w /mnt/c/Users/sarun
wslpath "C:\Users\sarun"
explorer.exe .

It’s also possible to browse all WSL distribution files using File Explorer, navigate to: \\wsl$

Windows X server

Install x server

configuration:

https://stackoverflow.com/a/61110604

WSL distribution settings

sudo apt update
sudo apt install xfce4 xfce4-goodies

Append following lines to  ~/.bashrc:

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

Reboot WSL distribution.

Windows settings

Install X Server: VcXsrv Windows X Server download | SourceForge.net

Change VcXsrv launcher DPI settings.

Start xLaunch.exe and select display settings, most of them are optional and you can choose what you like. “Disable access control” is required, without it WSL distribution can’t communicate with host.

Display settings, I found that multiple windows works best for me.
When new WSL distribution connects, you can execute or start some default applications.
Disable access control must be enabled.

Running applications

Now that we have everything set up we can run some applications.

You can run individual applications, like xCalc

Run individual applications.

Or you can start full desktop experience by running startxfce4

Full desktop experience in WSL 2.

Please note that not all applications will start, some of them might have issues or crash.

Summary

Considering my initial goal and what this book provided, I’m really happy and would recommend this book. I took only small portion what it provides and will definitely come back to it when my needs increase.

Published inSoftware Development

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *