Starting Linux within Windows via WSL
Motivations
Many bioinformatics applications are developed and optimised on Linux architecture, however, the majority of the end-users under corperate or government framework are on Windows system. The aim of this post is to discuss a few practical setups to enable a native Linux development environment on Windows via Windows native hypervisor.
Introduction
Since the later part of 2016, Windows Sybsystem for Linux Version 1 (WSL 1) was released as a Windows 10 feature to allow the running of Linux binary by implementing Linux system calls on the Windows kernel.1 WSL’s popularity largely raised by wide adoption of Windows 10. WSL is a compatibility layer for running Linux binary executables natively on Windows. WSL 1 provides a Linux-compatible kernel interface developed by Microsoft (containing no Linux kernel code), which can then run a GNU user space on top, Ubuntu, openSUSE, SUSE Linux Enterprise Server, Debian and Kali Linux are among popular flavours. Unix shells like Bash and command language, with native GNU/Linux command-line tools (sed, awk, etc.), programming language interpreters (Ruby, Python, etc.), and even graphical applications (using a X11 server at the host side) are also supported.
May 2019, with the release of WSL version 2 (WSL 2), an architecturally redesigned containerized implementation was introducewd to address increasing difficulty in syscall compatibility and performance improvements based on Linux’s API. 2 Conseqeuntly, full Linux kernel has now been made avaialble directly from inside Windows through a subset of Windows-native light-weight hypervisor Hyper-V. WSL 2 also addresses restricted I/O bottleneck of WSL 1 3 4, Microsoft claims a dramatic improvement in speed on certain operations up to 20x faster than WSL 1 5. Additional support of OpenCL and CUDA with WSL 2 also enables GPU-accelerated ML and AI development on Windows. 6
WSL 1 vs. WSL 2
WSL 1 and WSL 2 are two different implementations of Windows Subsystem for Linux. WSL 2 adopts virtualization to support a true Linux kernel, which is significantly lifted the file system performance and full syscall caompatibility.



Setups
Tips:
WSL is an optional Windwos feature, before the first time use, WSL needs to be enabled via Windows PowerShell. WSL 1 and WSL 2 can co-exist on the same machine, however, only one can be enabled at a time. WSL 2 requires Windows 10 version 2004 or higher, and a 64-bit version of Windows 10. WSL 2 also requires an update to its kernel component, which will be automatically downloaded by Windows Update during the installation process.
- Open up PowerShell as Administrator and enable WSL feature with the following command:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
PowerShell can be found via the search bar on the taskbar or by right-clicking the Start button and selecting Windows PowerShell from the menu.
PowerShell can be found under Start, Administrator is required to enable WSL optiions. - A system reboot is required to allow WSL to be fully enabled. After the reboot, open PowerShell as Administrator again and run the following command to set WSL 2 as the default version when installing a new Linux distribution:
wsl --set-default-version 2
WSL 1 and WSL 2 uses different file system, while WSL 1 uses Windows native NT file system, WSL 2 adopts virtual hard disk (VHD) with EXT4 file system. By default, WSL 2 will attempt to mount the device as EXT4. The VHD is stored in the Windows file system, which means the VHD is not portable and cannot be moved to another machine. In addition, the VHD is not accessible from Windows, which means the VHD cannot be accessed from Windows natively, consequently, performance across OS file systems will be impacted.
- Download a Linux distribution, for example, Ubuntu 20.04 LTS. Two methods are common, either directly from the Microsoft Store or with PowerShell.
Download a Linux distribution with default Windows Store or with PowerShell under Adminstriator mode:
wsl --list --online wsl --install -d <DistroName>
- Once a target Linux distribution is downloaded. The WSL can be launched either from the Start menu or with PowerShell. The first time launch will take a few minutes to complete, and you will be asked to create a user account and password for the Linux distribution during the installation process.
wsl --distribution <Distribution Name> --user <User Name>
References
-
Leeks, Stuart (2020). Windows Subsystem for Linux 2 (WSL 2) Tips, Tricks, and Techniques: Maximise Productivity of Your Windows 10 Development Machine with Custom Workflows and Configurations. Birmingham: Packt Publishing. pp. 18–19. ISBN 978-1-80056-352-0. OCLC 1202451000. ↩
-
Craig Loewen (6 May 2019). “Announcing WSL 2”. Windows Command Line Tools For Developers. ↩
-
Larabel, Michael (12 October 2018). “A Look At The Windows 10 October 2018 Update Performance With WSL”. Phoronix. ↩
-
Larabel, Michael (5 November 2018). “The WSL Improvements In The Windows 10 October 2018 Update”. Phoronix. ↩
-
mscraigloewen. “About WSL 2”. docs.microsoft.com. ↩
-
“OpenCL & CUDA GPU support”. Windows Developer feedback (Microsoft/UserVoice). 15 September 2016. Archived from the original on 7 July 2018. Retrieved 1 Jan 2024. ↩
Leave a comment