Utilizing WSL: How to Launch Linux Apps on Windows and Windows Apps on Linux, and Access Ext4 and NTFS

The Windows Subsystem for Linux (WSL) strives to unite the open-source operating system with Windows, diminishing the distinction for users between the two. A significant part of this effort is the capacity to interact with either operating system’s file system and launch programs from either system.

Looking from a technical perspective, WSL 2 employs a virtual machine but combines the two systems much more intimately than a straightforward Linux VM on Hyper-V. The fusion transpires at all layers, from the file system to the GUI to the network connection.

This integration enables users to open files from the Linux file system using Windows software, and vice versa. In either environment, applications can be launched from any location, with WSLg making sure that Linux GUI programs open in a separate window on the Windows desktop.

With the upcoming version 2.0, we anticipate further improvements in network-level integration. In the past, Linux services could be accessed from Windows through localhost. This feature is particularly useful if you need to run a web application on Linux and want to browse it in a Windows browser.

Integration of the file systems

The file systems of both Windows and Linux are accessible from the other side. In the File Explorer, you can navigate to \wsl$<Distro-Name> and use the Windows tool to view or copy files.

Files in Linux directories can be displayed in Explorer or the Windows CLI

Similarly, the file system is accessible in PowerShell by, for example, switching to an Ubuntu installation with:

cd \wsl$Ubuntu

Alternatively, Linux mounts the Windows file systems under /mnt. For instance, the C: drive can be traditionally located under /mnt/c.

Accessing the Windows file system in bash.

By using this approach, one can navigate around the Windows file system while inside the Linux shell, leveraging tools such as grep, awk, or GNU Text Utilities to scrutinize file contents.

Microsoft advises against bulk file maneuvers from the counterpart OS due to a decline in performance even though the file systems are perfectly integrated.

This applies when operating in Linux beneath /mnt/<drive letter> or in Windows under \wsl$. It’s crucial to remember that Linux differentiates uppercase and lowercase file names, unlike Windows.

Cross-platform program usage

It’s interesting to note that applications from the other system can be not only executed in their natural environment but also on the flip side. For instance, Windows applications can be effortlessly initiated by denoting the .exe file extension in the bash, like ipconfig.exe /all.

Launching the Windows utility ipconfig.exe in the Ubuntu Bash

Conversely, on a Windows command line, you would use the WSL utility to open Linux programs:

wsl ps -aux

In this example, you would use ps instead of Get-Progress or Task-Manager to display running processes.

Call the Linux utility ps from the Windows command line using wsl.exe

Call the Linux utility ps from the Windows command line using wsl.exe

The integration options extend even further, allowing the use of programs from both worlds in a pipeline. For example:

Get-Process | wsl sed "s/  */;/g"

In this example, the output of the PowerShell cmdlet Get-Process is passed to sed in the Linux environment, replacing all spaces with semicolons.

Summary

The Windows Subsystem for Linux integrates the two operating systems on multiple levels. You can navigate through directories of the Windows file system using the bash shell and switch to the Linux directory tree in PowerShell or cmd.exe.


Posted

in

, , ,

by

Tags: