Skip to main content

WSL (or why I won't make Linux VMs in Windows)

· 5 min read

Windows Subsystem for Linux (WSL) has been out for a couple of years now and many people have put in a lot of work to make it even better. It all started with the Bash on Ubuntu on Windows, but has since evolved to accept different distributions (there are a couple available in the Microsoft Store and you can install some yourself). It has been improved to the point that I don't see the point in running a Linux VM in Windows (unless you want other utilities of VMs such as copying the whole system or such).

What exactly is WSL

The Windows Subsystem for Linux is actually a recompiled Linux kernel that runs on top of Windows. You can now install multiple different distributions of Linux along side one another and switch between them (since Windows update 1809 in October 2018) using their wsl executable.

How I started using WSL

Not long after I started university I switched to using Linux as my main work operating system (although I still kept a Windows partition/computer for games and such). I find myself much more productive using a linux shell than Windows' cmd or PowerShell. The tools are also much more powerful and can offer a lot more utility. The companies I worked at were using Windows and developing applications for Windows so I didn't have a choice to use that as my main work environment, but I always tried to use some Linux knowledge and tools when working. It started with Cygwin and that lasted for a while until Ubuntu on Windows came out. Although WSL's first versions were sometimes buggy and didn't allow much, it was still an improvement and now I'm very happy with the environment I set up.

What I like about WSL

The integration between Linux and Windows is very well made. The fact that you're actually running a Linux kernel inside of Windows means that you'll be able to run any application with currently runs on Linux natively without needing to recompile them or run them in a virtual machine. You're not limited to a certain amount of threads/processor usage/memory/disk space as you would with a virtual machine either so you can run very demanding programs without running any problems. The fact that you aren't booting a computer also means that starting a new instance is practically instantaneous. You can also run any distribution you want and get the tailored tools they offer.

How I set up my WSL

I won't explain how to set up the default WSL tools, there are many guides for those. I will however explain what I did after that.

When you first activate WSL, it comes with an Ubuntu installation as the default distribution, but you can install other distribution from the Microsoft Store or install you're own distribution with the WSL api that Windows provides. The only problem is that the function isn't easily available so you need to access it with some code which you need to compile and execute passing in the distribution name you want to set for wsl and the filename of a distribution installation media compressed in tar.gz format. I used this to install a stage3 version of Gentoo, which is my favourite distribution so far. For those that want to use Gentoo, simply follow the handbook starting with MAKEOPTS and portage set up (Skip the chrooting and kernel parts).

Although I'm using tmux, I like using ConEmu to launch the distribution once I have it set up because I usually just leave it open and can add tabs for other prompts (cmd, powershell) whenever I need. The ConEmu task is set to run wsl.exe -d gentoo -u lavoiecsh. The only problem with the Windows console (and ConEmu) is that some of the keybindings are broken (Ctrl-Space, Ctrl-Backspace), so I've decided to run my emacs using X (more on that shortly).

Another tool I installed is VcXsrv. This is a Visual C compiled version of the X server for Linux. It runs inside Windows and creates a display that graphical applications in Linux can use to display themselves. Once you've installed it, run the XLaunch.exe tool in the default folder and select Multiple Applications. Save the configuration at the end of the XLaunch wizard and create a link to it in your start up folder (%APPDATA%\Microsoft\Windows\Start Menu\Programs\Start-up) so that it will launch when you start Windows. This will create a display (:0.0 by default) that your linux applications can use. Once XLaunch is running (it only displays an icon in the launch bar), when you launch a graphical application in Linux it will start it in a new window.

With VcXsrv installed and running, I usually start emacs to get a windowed server running (by adding (server-start) in my initialization file). After that, whenever I need to edit a file, I can look it up with emacs, or run emacsclient -nqu <filename> (aliased to em in my case) to send it to the emacs server from the console.

I chose not to run a full graphical interface (window manager or desktop manager) since I barely use graphical tools with linux and I find that having WSL running inside ConEmu with tmux gives me all the bash prompts I need and having emacs running with VcXsrv gives me all the edition tools I need (while also circumventing the keybinding problems that the Windows console has).

Conclusion

WSL is now very powerful, especially when combined with tools such as ConEmu and VcXsrv. I am confident that I will be using it for a while and that more developments will continue on it in the next couple of years.