My config of Windows Subsystem for Linux
wsl windows linux
I have been using Windows Subsystem for Linux (WSL) on my new HP Envy laptop since last September. From my own experience, it is a perfect replacement for Cygwin and MSYS2 on Windows.
I am using Ubuntu 16.04 distro from Windows Store. Personally I prefer Debian but Debian wasn't available at the time when I setup WSL.
This article introduces my configuration of WSL.
Microsoft doesn't invent a new terminal for WSL. The default terminal, cmd, is simple and buggy. There are some third-party terminals which provide similar experience to Linux terminal emulators.
The one I use is wsl-terminal which is based on Mintty. It is much ease of use and customizable.
DrvFs driver privides access to Windows drives (partitions). Persistent drives
(like C:) are mounted on directories in /mnt/
(like /mnt/c
) as DrvFs. If
you have ever used NTFS on Linux, DrvFs is very similar: No UNIX permission
support and every file is in mode 777.
To prevent typing very long paths, I create several symlinks in my home dir:
$ ls -l | grep '\->' lrwxrwxrwx 1 cuihao cuihao 28 Sep 24 2017 Desktop -> /mnt/c/Users/cuihao/Desktop/ lrwxrwxrwx 1 cuihao cuihao 16 Feb 18 22:09 Documents -> /mnt/d/Documents/ lrwxrwxrwx 1 cuihao cuihao 20 Oct 5 22:32 WinUser -> /mnt/c/Users/cuihao/
Removable drives like USB storage are not mounted by default. You can mount by
yourself: mount -t drvfs D: /mnt/d
In fact, my drive D: is a SD card for extending my storage. I use it as my data
storage. To make WSL mount it automatically, I append this line to ~/.bashrc
:
mountpoint -q /mnt/d || sudo /bin/mount -t drvfs D: /mnt/d
To run Linux GUI applications, you need an X server. On Windows there is VcXsrv for this purpose. Once VcXsrv is running on Windows, WSL programs can connect to it and render graphics.
The default setting of VcXsrv doesn't fit WSL well. You may setup VcXsrv parameters according to this. Here is my optimized xlaunch configuration for VcXsrv:
<?xml version="1.0" encoding="UTF-8"?> <XLaunch WindowMode="MultiWindow" ClientMode="NoClient" LocalClient="False" Display="0" LocalProgram="xcalc" RemoteProgram="xterm" RemotePassword="" PrivateKey="" RemoteHost="" RemoteUser="" XDMCPHost="" XDMCPBroadcast="False" XDMCPIndirect="False" Clipboard="True" ClipboardPrimary="True" ExtraParams="" Wgl="False" DisableAC="False" XDMCPTerminate="False"/>
Save above config as whatever.xlaunch
and you should be able to open it with
VcXsrv on Windows. VcXsrv will setup X server with this config. You may copy
the file to %AppData%\Microsoft\Windows\Start Menu\Programs\Startup
to make
VcXsrv start up automatically at boot.
Most GUI softwares (including OpenGL apps) run smoothly on my laptop with this config. So I can plot curves with matplotlib as if using native Linux.
BTW, sound system doesn't work on WSL. I don't need it. But there are some workarounds. Just Google it.
With weasel-pageant ultility, it's possible to use GPG4Win or Putty's SSH agent in WSL. So you don't have to create an indenpendent SSH key for WSL. I store my SSH key in GPG.
To setup SSH agent, first enable SSH support and Putty support in GnuPG. You
can find the options in Kleopatra settings, or you can edit
%APPDATA%\gnupg\gpg-agent.conf
as in Linux.
Then download weasel-pageant and extract it, run gpg-agent on Windows
(calling specific gpg commands will bring it up) and weasel-pageant on WSL. To
setup SSH agent automatically, I append following lines to ~/.bashrc
:
eval $(~/WinUser/Programs/weasel-pageant/weasel-pageant -r -a "/tmp/.weasel-pageant-$USER") ssh-add -l >/dev/null 2>&1 || ( gpg.exe --card-status >/dev/null 2&>1 & )
On current stable version of Windows 10, WSL doesn't support running background jobs. Closing the last WSL window will terminate all WSL processes as well.
As a workaround, an invisible WSL terminal could be used to keep WSL processes running in background. This is the VBScript to achieve this. I have made it run at boot.
Next major update of Windows 10 (Redstone 3) will support background task in WSL, which is likely to release in this month.
There are indeed some performance issues. I heard that WSL is slow to create
new processes and threads like in Windows. Also, Windows defender seem to have
a big impact on performance. I
set the whitelist, but of no use. As a result, you may notice that apt/dpkg
is much slower compared with native Linux, and powerline slow down shell
startup significantly.
Page created on 2018-04-01