Technology
Understanding the Linux Subsystem in Windows: A Comprehensive Guide
Introduction to the Linux Subsystem in Windows
As a long-time Linux-only user, I always preferred the command-line interface and robust system tools that came with my Unix-based operating systems. However, during the lockdown, the need to play computer games with my family required a shift to the Windows environment. For sysadmins like myself, this posed a challenge since our primary toolsets are designed for Linux. The solution? The Windows Subsystem for Linux (WSL).
What is WSL?
The Windows Subsystem for Linux (WSL) is a feature that allows you to run a GNU/Linux environment directly on Windows, including command-line tools, utilities, and applications, without the need for any VMware or virtualization software. This feature is designed to help developers and system administrators leverage the power of Linux on Windows, making it easier to develop, manage, and deploy applications across different environments.
Why Use WSL?
Consider the following key benefits of using WSL:
System Resources: WSL is designed to be incredibly resource-efficient. It does not require the overhead of a full virtual machine, thus saving memory, CPU, and storage resources. Performance: WSL is built to provide near-native performance, ensuring that you can run Linux commands and applications seamlessly without any significant performance hit. Functionality: You can run native Linux tools and applications directly on your Windows machine, allowing you to retain your Linux-based toolset even when working in a Windows environment.WSL vs. WSL2
The latest iteration of WSL is WSL2, which brings several improvements over the original WSL version. WSL2 offers a more complete Linux experience, including:
Linux Kernel: WSL2 utilizes the same Linux kernel as a full Linux distribution, providing a more accurate and consistent environment. Native Integration: Improved performance and integration with Windows native features, such as file system access and networking. Performance: Enhanced performance and stability, making it ideal for development and production use.Getting Started with WSL
Here’s how to set up and use WSL:
Enable WSL
First, you need to enable the Windows Subsystem for Linux feature in Windows Settings. Follow these steps:
Open the Settings app. Select Update Security. Click on For developers. Toggle Developer mode on. Go back to For developers, and click Features. Find Windows Subsystem for Linux, and toggle it on.Install a Linux Distribution
Once WSL is enabled, you can install a Linux distribution, such as Debian or Ubuntu:
Open Windows Terminal. Run the following command to install a Debian distro:sh wsl -d Debian
After installation, you can open a Linux terminal by typing bash or bash -login.Accessing Local Filesystem
With WSL, you can access your local machine’s filesystem from within the Linux Bash shell. The Windows file system is mounted under the /mnt folder. For example, your C: drive is mounted under /mnt/c.
~ cd /mnt/c ~ /mnt/c ls
Using Linux Commands
Running Linux commands is straightforward. For instance, let's see the details of the currently running Linux distribution:
~ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04 LTS Release: 20.04 Codename: focal
Conclusion
The Windows Subsystem for Linux is a game-changer for developers and sysadmins who need to work with Linux tools within the Windows environment. Whether you are running a full-fledged Linux distribution or just a few essential tools, WSL provides an efficient and seamless way to bridge the gap between Windows and Linux. With WSL2, developers and sysadmins can expect enhanced performance and integration, making it a powerful tool in their arsenal.