In this Ask the Admin, I’ll look at what you can do with Bash and the Windows Subsystem for Linux in Windows 10 and Windows Server 1709.
If you’re a developer that needs to compile Linux binaries, then the Windows Subsystem for Linux (WSL) is for you. And while it’s possible to run Linux GUI programs using an X Server, WSL isn’t intended for the average user who wants to spin up their favorite Linux apps. WSL is a tool for developers and sysadmins that need Linux interoperability in Windows.
The most important thing to understand about WSL is that it isn’t based on virtual machines or containers. When you download a supported Linux distro from the Microsoft Store, it doesn’t mean that a virtual machine is created. WSL provides a layer for mapping Windows kernel system calls to Linux kernel system calls. This allows Linux binaries to run in Windows unmodified. WSL also maps Windows services, like the filesystem and networking, as devices that Linux can access.
Install a Linux Distro From the Microsoft Store (Image Credit: Russell Smith)
Instead of using a VM or container, WSL virtualizes a Linux kernel interface on top of the Windows kernel. This means that running WSL only requires a minimal amount of RAM. And when not in use, the WSL driver isn’t loaded into memory, making it much more efficient than a solution based on a VM or container.
Apart from giving access to the Bash shell or another shell of your choice and the tools included with whichever Linux distro you have chosen to install, WSL can also run system level daemons (services) in the background. In the Fall Creators Update and Windows Server 1709, it’s even possible to install multiple Linux distributions and switch between them.
For developers, this means you can install Linux IDEs (Integrated Development Environments) and use them to test Linux software and compile Linux binaries directly in Windows. Python, Perl, Ruby, PHP, and the GNU Compiler Collection (GCC) are all supported. Servers, like Apache and MySQL, can be run in WSL but Microsoft recommends using Azure, Hyper-V, and Docker. While Linux technologies can be installed in WSL, like Python and Ruby, some features only work properly in Linux because not all libraries are ported and some features have dependencies on Linux-only features. Microsoft doesn’t officially support running GUI apps in WSL but you can install an X Server and change the DISPLAY variable to allow GUI apps to run.
WSL allows you to access the Windows filesystem. For example, to access the C drive, you would use the following command:
WSL doesn’t allow changing Linux files with a Windows app or tool, but you can change Windows files with Linux tools. Either with an absolute path, like /mnt/c/Users/<Windows User>/Documents/Projects/<filename>, or for Linux tools that can’t use /mnt, you can create a symbolic link with ln:
ln -s "/mnt/c/Users/<Windows User>/Documents/Projects" /home/<Linux User>/Projects
For developers that want or need to use Windows but also develop for Linux, WSL alleviates the need to maintain separate physical devices or virtual machines for Linux development. But it’s worth remembering that WSL isn’t Linux, and while what Microsoft has achieved is quite impressive, it’s not without its drawbacks. The most significant being slow disk I/O operations, which can be up to four times slower than on native Linux. Microsoft is aware of the problem and will hopefully improve performance in a future update.
Other issues that users are experiencing include slow networking and when a VPN is established from Windows, it breaks WSL networking. So, depending on how you work and the payloads you need to execute, WSL may or may not be for you.
In the Fall Creators Update, it got much easier to install WSL. All you need to do is enable WSL in the Programs and Features Control Panel, or using PowerShell, and then reboot in a 64-bit edition of Windows 10 FCU or Windows Server 1709.
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
Once the computer has rebooted, you can install a Linux distribution from the Microsoft Store. On Windows Server, you’ll need to use PowerShell to install a Linux distribution. You can find detailed instructions on Microsoft’s website here. There’s also a guide for Windows 10 here.
In this Ask the Admin, I explained what WSL is, how it works, and why it might be of interest to developers.
The post How Does the Windows 10 Subsystem for Linux Work and What Is It For? appeared first on Petri.