
Windows Subsystem for Linux (WSL) is a compatibility layer designed by Microsoft to run Linux binaries natively within Windows. It provides an Ubuntu-like experience without requiring a virtual machine (VM) or a dual-boot system. However, there are two distinct versions of WSL:
- WSL1 (Windows Kernel-Based Translation Layer)
- WSL2 (Full Linux Kernel with Virtualization)
Both allow running Linux applications, but they function in fundamentally different ways.
How Windows Handles Subsystems
Historically, Windows supports multiple subsystems that allow execution of applications built for different operating systems. These subsystems run on top of the Windows kernel, which manages system resources.
Some of the well-known subsystems include:
- OS/2 Subsystem – Used for running 16-bit OS/2 applications (phased out).
- Win32 Subsystem – Used for running 32-bit and 64-bit Windows applications.
- Windows 64-bit Subsystem – An extension of Win32 for modern applications.
- WSL1 Subsystem – Allows executing Linux ELF binaries by translating system calls into Windows kernel calls.
- WSL2 Subsystem – Runs a full Linux kernel inside a lightweight VM, enabling full system compatibility.
How WSL1 Works
WSL1 was designed to translate Linux system calls into Windows NT kernel calls. It allows Linux binaries (ELF format) to run directly on Windows without a virtual machine. This is similar to how the Win32 subsystem allows 32-bit applications to run on 64-bit Windows.
Key characteristics of WSL1:
- Does not use a real Linux kernel but translates Linux system calls into Windows equivalents.
-
Executes Linux binaries (like
bash
) natively using Windows NT kernel services. -
Stores files in the Windows filesystem (
C:\Users\YourName\AppData\Local\Packages
). -
Can access Windows files quickly, but Linux operations like
fork()
are slower due to translation overhead.
How WSL2 Works
WSL2 introduces a full Linux kernel running inside a lightweight virtual machine (VM) using Microsoft's Hyper-V technology. Unlike WSL1, WSL2 does not translate Linux system calls—it executes them natively.
Key characteristics of WSL2:
- Uses a real Linux kernel, downloaded from Microsoft and updated via Windows Update.
- Runs inside a lightweight Hyper-V virtual machine, making it more compatible with Linux software.
- Uses a virtual ext4 filesystem, making Linux file operations faster.
-
Windows files are accessible via
/mnt/c/
, but accessing them is slower compared to WSL1.
WSL1 vs. WSL2: Key Differences
Feature | WSL1 | WSL2 |
---|---|---|
Kernel | Uses Windows NT Kernel | Uses a real Linux kernel |
File System | Windows-native file system (NTFS) | Linux-native file system (ext4) in a virtual disk |
System Calls | Translates Linux syscalls to Windows | Native execution of Linux syscalls |
Performance | Faster for Windows file access |
Faster for Linux operations like git clone ,
apt install , etc.
|
Network | Shares Windows network stack | Runs in a separate network interface |
Compatibility | Some system calls don’t work | Full Linux compatibility |
Understanding the Linux Userspace
What is the Linux Userspace?
Linux consists of two major components:
- Kernel – The core that manages hardware and system resources.
- Userspace – All the applications, libraries, and programs that interact with the kernel.
A Linux distribution like Ubuntu consists of:
- A kernel – Manages hardware, processes, memory, and networking.
- A userspace – Contains user applications, system tools, package managers, libraries, and more.
WSL and the Userspace
When Microsoft partnered with Canonical (Ubuntu's creator), they created a special userspace image for WSL that contains:
- The same Ubuntu software, utilities, and package manager (APT).
-
The file system hierarchy (
/home
,/usr
,/bin
,/lib
, etc.). -
The shell (
bash
orzsh
). - No systemd/init system – Startup services and daemons are not running by default.
However, in WSL2, many of these limitations are lifted due to the full Linux kernel, making it behave closer to a real Linux system.
WSL1: Windows Filesystem vs. WSL2: Linux Filesystem
A major difference between WSL1 and WSL2 is how files are stored:
WSL1 File System
- Stores Linux files directly on Windows' NTFS.
-
Example: If you create a file in WSL1 at
/home/user/file.txt
, it is actually stored in:C:\Users\YourName\AppData\Local\Packages\CanonicalGroup.XXX\LocalState\rootfs\home\user
- Since files are on Windows NTFS, Windows applications can easily access them.
-
However, Linux operations like
git clone
,tar
, andnpm install
are slow due to NTFS performance limitations.
WSL2 File System
- Uses a virtual disk image (ext4-formatted VHD file) to store the Linux filesystem.
-
Example location of this VHD file:
C:\Users\YourName\AppData\Local\Packages\CanonicalGroup.XXX\LocalState\ext4.vhdx
- Windows cannot directly access this filesystem, making cross-compatibility harder.
- However, Linux applications perform much faster since they run on ext4.
Software Installation in WSL
Linux Package Managers
An essential part of any Linux system is its package manager, which handles software installation and updates. Different Linux distributions use different package managers:
- Ubuntu/Debian:
apt
- Fedora:
dnf
- Arch Linux:
pacman
- openSUSE:
zypper
Since WSL is just a Linux distribution, it naturally includes its package manager.
For example, on Ubuntu WSL:
sudo apt update && sudo apt upgrade -y
This command updates and upgrades all installed software, just as on a real Ubuntu system.
WSL2 Uses a Lightweight Virtual Machine
Although WSL2 runs a full Linux kernel, it does not behave like a traditional VM. Instead, it uses a microVM running on Hyper-V, which:
- Boots in milliseconds (unlike full VMs).
-
Shares the same Windows filesystem (accessible via
/mnt/c
). -
Allows GUI applications (
gedit
,firefox
, etc.). - Uses less RAM and CPU compared to a full Linux VM.
Thus, WSL2 provides native Linux compatibility while staying integrated with Windows.
Final Summary
- Windows uses subsystems to allow running different OS binaries (e.g., Win32, OS/2, WSL).
- WSL1 translates Linux system calls to Windows API calls, allowing ELF binaries to run on NT.
- WSL2 runs a full Linux kernel in a lightweight VM, providing better performance and compatibility.
- File handling is different: WSL1 stores files on NTFS (faster for Windows access), while WSL2 uses ext4 (faster for Linux operations).
- Linux userspace is a key part of any Linux system, and WSL provides a pre-built Ubuntu userspace.
- WSL2 behaves like a real Linux system with package management, networking, and GUI support.