Windows/WSL

From Segfault
Jump to navigation Jump to search

Installation

The Windows Subsystem for Linux Installation Guide for Windows 10 are pretty staightforward, but let's summarize them anyway. As an administrator in a PowerShell window:

cd c:\temp
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

Download[1] a Linux distribution, for example Ubuntu 18.04:

Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1804 -OutFile Ubuntu.appx -UseBasicParsing

Install with:

Add-AppPackage .\Ubuntu.appx

The noisy terminal bell can be disabled[2] via /etc/inputrc:

set bell-style none

Usage

Change the default user to someone else:

$ alpine config --default-user bob

But how do we find out the actual executable for our installed distribution?

$ where *leap*
C:\Windows\System32\FileAppxStreamingDataSource.dll
C:\Windows\System32\PeopleAPIs.dll
C:\Users\ck\AppData\Local\Microsoft\WindowsApps\openSUSE-Leap-15-1.exe

Let's try this:

$ openSUSE-Leap-15-1 config --default-user bob
/usr/bin/id: ‘bob’: no such user

We have to make sure the user actually exists in the VM :-)

Restart WSL:

Restart-Service LxssManager
Get-Service LxssManager

Or, w/o PowerShell:

$ sc queryex LxssManager | find "PID"
       PID                : 2540

$ tasklist /FI "PID eq 2540"
Image Name                     PID Session Name        Session#    Mem Usage
========================= ======== ================ =========== ============
svchost.exe                   2540 Services                   0     11,256 K

Sound

For some reason we needed sound support in our WLS environment. Another blog explained how to do this[3] but we only need sound on the command line, so we can omit some parts. The important steps are:

  • Download a precompiled pulseaudio binary from freedesktop.org
  • Extract and edit a two files before we can start it:
etc\pulse\default.pa
load-module module-waveout sink_name=output source_name=input
load-module module-waveout sink_name=output source_name=input record=0

#load-module module-native-protocol-tcp
load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1
etc\pulse\daemon.conf
; exit-idle-time = 20
exit-idle-time = -1
  • With that, pulseaudio.exe should be able to start and will now listen on localhost
  • For our needs, all we needed to do was to point our music program (in WSL) to the Pulseaudio server (running in Windows):
export PULSE_SERVER=tcp:127.0.0.1
mpg123 file.mp3

Other programs may need other hints to connect to the Pulseaudio server though.

References