Question 10 Unsaved Unix/linux Systems Can Read Ms Windows Filesystems.
The Windows Subsystem for Linux or Windows WSL is a not bad solution for developers to natively work within Linux right on their Windows 10 version desktop.
If you've spent manner too much time partitioning hard drives to have several Linux systems installed with Windows, y'all're in luck with this article.
The fairy code-mother at Microsoft has decided to requite you another option: The Windows Subsystem for Linux (WSL). WSL makes running a Linux system alongside Windows and then much easier, and more than flexible.
In this tutorial, you'll learn how to go started with WSL. Y'all'll learn how to get started to learning how to use some bang-up tools making WSL even more versatile than using bash or PowerShell on their own.
What is WSL?
WSL or C:\Windows\System32\wsl.exe is a Windows tool that allows you to install a Linux distribution as an app from the Windows store.
Since WSL is a simple Windows executable, you can call it from a command prompt or PowerShell concluding. We'll get deeper into that topic later. For at present, it's important to empathize a little more about what WSL is doing nether the hood.

How to Enable WSL
To gear up and enable WSL involves installing a Linux distribution alongside Windows 10. But in a style that allows the two different operating systems to collaborate with each other.
Prerequisites
To install WSL on Windows, yous have one requirement to meet; yous must have a Windows 10 64-bit computer Build 18917 or later.
You can observe your Windows 10 build by running the winver utility.

Enabling the WSL Windows Feature
WSL is a cinch to enable; no download required. It's simply a unmarried Windows feature.
To enable WSL, open up up PowerShell as administrator and run the following:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
Related: How to Run PowerShell as Administrator
Once consummate, restart your figurer and you lot're done!
Downloading a Linux Distribution for WSL
WSL does not install any Linux distribution on its ain. You'll need to install one. Once Windows 10 comes support, beginning setting up your called Linux distribution.
First, open up upwardly the Microsoft Store and search for 'WSL'. Y'all should soon run across a listing of Linux distributions show upwards.

Next, choose your distribution of choice and install it. This tutorial will be using Ubuntu 18.04. At the fourth dimension of this writing, you have a few other distributions bachelor likewise such every bit:
- Ubuntu 16.04 LTS
- Ubuntu 18.04 LTS
- OpenSUSE Leap xv
- OpenSUSE Leap 42
- SUSE Linux Enterprise Server 12
- SUSE Linux Enterprise Server xv
- Kali Linux
- Debian GNU/Linux
- Fedora Remix for WSL
- Pengwin
- Alpine WSL
Setting your WSL Version
Yous might accept to enable Linux to piece of work with WSL version ii. If so, yous can do so by following the below instructions.
In a PowerShell console:
- List which versions of Linux you take installed by running
wsl -l
orwsl --list
. - Once y'all have the listing, copy the name of the distro y'all want to run with WSL2 and run
wsl --set-version <Distro> 2
, replacing <Distro> with the name you lot copied earlier. - Ostend the command was successful by running
wsl -l -v
orwsl --list --verbose
. This command will return a full list of WSL distros and the version each distro is using.

You can also set up your default WSL version for any distros yous install in the future to WSL2 past running
wsl --ready-default-version 2
Starting upwardly WSL
To showtime using WSL, open up a PowerShell terminal and type wsl
. If y'all've set up WSL correctly, you'll enter a bash final running on the WSL distro of choice. From hither, you tin run any Linux commands you wish.
Below you will observe a reference to all of the options the wsl.exe provides when starting up.
Command | Caption | Example |
---|---|---|
exec, -e | Will run command using without using default shell | wsl -east ringlet google.com |
— | Passes anything after this parameter to default shell. Leaving the operator out volition also piece of work. | wsl — curl google.com, wsl curl google.com |
distribution, -d | Opens a final in the specified distribution'due south shell | wsl -d Ubuntu-18.04 |
user, -u | Runs WSL command as the specified user every bit long every bit user exists on that distro | wsl -d Ubuntu-18.04 -u tux_user |
export | Exports the specified distribution to a tar file on your local system. | wsl –consign Ubuntu ./Examination-Ubuntu.tar |
import | Imports a tar file every bit a new WSL distribution. Can specify WSL version with the –version option | wsl –import Test-Ubuntu C:\data\Test-Ubuntu .\Test-Ubuntu.tar |
list, -fifty [Options] | wsl –list | |
all | List all installed WSL distributions | wsl -l –all |
running | List only WSL distributions that are currently running | wsl -l –running |
quiet, -q | Only show WSL distribution names | wsl -l -q |
verbose, -5 | Show detailed information most all WSL distributions | wsl -fifty -five |
gear up-default, -s | Sets the specified WSL distribution as the default distribution for WSL commands. | wsl -due south Test-Ubuntu |
ready-default-version | Changes the default WSL version for all new distributions installed to that system | wsl –set-default-version 2 |
set-version | Changes the WSL version of the specified distribution | wsl –prepare-version Test-Ubuntu 2 |
shutdown | Immediately terminates all running WSL distributions | wsl –shutdown |
terminate, -t | Terminates the specified WSL distribution | wsl -t Exam-Ubuntu |
unregister | Unregisters the specified WSL distribution | wsl –unregister Test-Ubuntu |
help | Display information most using WSL | wsl –assistance |
Once yous become comfortable using these switches, y'all'll find that running and managing applications through WSL is much easier than managing Linux virtual machines on your own.
Quick tip: Observe all flags and arguments for to WSL past running
wsl --assist
.
When you lot're finished, type exit
to go back back to the PowerShell terminal.
Sharing Windows/Linux Resources via WSL
One of the best parts of WSL is that it tin seamlessly share Windows and Linux resources with each other. At this fourth dimension, you can share file systems, environs variables, network resources, and control-line tools like cmd and PowerShell.
All examples you will come across in this section are via the WSL Ubuntu Linux distro. Your mileage may vary if y'all've chosen to download a different distro.
Sharing File Systems
The file system is ane of the almost useful things to share with WSL. WSL allows you to work with both file systems equally if they were i.
The Windows 10 file system is mounted as a directory in Linux while your Linux file system will be mounted equally a binder in Windows.
Finding the Linux File Organization from Windows with Surround Variables
When yous install a Linux distro with WSL, it volition sometimes add together a Windows environs variable. In the case of the WSL Ubuntu Linux distro, it will create an surround variable called UBUNTU_HOME. This surroundings variable points to the Linux /dwelling house/ubuntu directory from both Windows and WSL Ubuntu.
The path divers in UBUNTU_HOME can be used to run scripts that utilise resources across them, or fix a default location for the Windows concluding (covered later).

Other distros may define a similar environment variable. Inspect the Windows surroundings variables with the PowerShell control Get-ChildItem -Path $Env:\
later installing a new Linux distro to run into if whatever may have been added.
This environment variable shortcut is handy if you want to put everything in the /home/ubuntu directory. But let's dig a trivial deeper into how it got there and how else you can accomplish information technology.
Finding the Linux File Arrangement from Windows via the Microsoft Shop Packages Folder
Not every WSL distro is guaranteed to come up with an like shooting fish in a barrel way to reference information technology. It'southward important that you acquire how to find the Linux file system an alternative manner.
Since virtually WSL Linux distributions will exist installed from the Microsoft store, you can look for the Linux file system in the same place as other Windows store apps. Navigate to %USERPROFILE%\AppData\Local\Packages\ to find the directory where your Windows store apps become. So assume control of the folder as this is usually protected by default.
Yous will encounter many subfolders in the packages folder where your Linux distrubution file system may be presented. The WSL Ubuntu distro, for example, was under the CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc binder for me.
If y'all navigate into the package folder, y'all volition discover the Linux file system. For WSL Ubuntu, information technology'due south located in the LocalState\rootfs folder. This is the root directory of your Linux distro.

Finding the Windows File System from Linux
To detect the Windows 10 file system from Linux, open upward WSL in Windows. WSL volition and then bring up a bash terminal. This bash terminal will start in your UBUNTU_HOME directory by default.
You can also find the root of your Windows storage volumes as well. Each of your Windows letter drives (C, D, E, etc) is treated as a mounted drive from the WSL Linux file system. You lot'll find each volume mounted equally /mnt/c, /mnt/d, etc as long as you have root privileges.

Get-ChildItem C:\Windows\System32 | Select-Object -First five
running on WSLThe WSL2 Filesystem
Navigating the WSL filesystem is adequately straightforward. Anyone non familiar with a Linux file system structure will appreciate existence able to navigate information technology with the Windows Explorer. Bu if you want to switch to WSL2, it's going to exist a trivial more complicated.
WSL2 changes how everything works under the hood for sharing file systems. For starters, the filesystem is now a virtual hard disk in vhdx format instead of a directory.
Y'all can find the vhdx file nether %USERPROFILE%\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState for an WSL Ubuntu distro.
You'll find that VHDX files tin exist mounted in Windows with the Disk Manager tool. But, the virtual disks cannot exist mounted while the WSL distro is registered.
Sharing Environment Variables
Environment variables are a crucial part of whatever operating system, making information technology like shooting fish in a barrel to reference binaries and executables anywhere in your applications.
Earlier Windows 10 build 17063, the simply environment variable shared between Windows 10 and WSL Linux was the PATH variable. Since so it is possible to share environment variables by using WSLENV the environment variable.
Using the WSLENV environment variable to share other environment variables tin experience a footling meta. To share environment variables across platforms, you actually have to prepare environment variables inside of another environment variable.
Overview
Sharing environment variables is a iii-footstep process beneath. The simply major deviation when sharing across Windows/Linux is the switch argument used (full reference below).
- Define environment variable in Windows or Linux.
- Fix the WSLENV environs variable equal to the previously divers surroundings variable followed past a switch argument (for path translation).
- Read the environs variable in Windows or Linux.
Sharing Options
You can make variables available iv different means depending on which platform y'all'd like the surroundings variable to show up on using switches (tabular array shown below).
- Windows filesystem to only exist available from itself
- WSL filesystem to only be available from WSL
- WSL filesystem to be available on both WSL Linux and Windows
- Windows filesystem to be be available on both WSL Linux and Windows
Flag | Explanation |
---|---|
/p | Unmarried path. A variable set with this will be translated between the Windows and WSL Linux and made available to both. |
/l | List of paths. Similar to /p , except it can accept more than ane path. On Windows, this list will exist delimited by semicolons while on WSL Linux it volition be delimited by colons. |
/u | Unix path. A path ready with this flag can but exist accessed when invoking WSL Linux from Windows. Can exist used with either the /p or /l flags |
/westward | Windows path. A path set with this flag can only exist accessed when invoking Windows from WSL Linux. Can exist used with either the /p or /fifty flags |
Path Translation
The main reason to share surroundings variables is for path translation. As you may already know, Windows has user profile folders as Linux has user contour directories, for instance. Each user has a predetermined "domicile folder" like C:\Users\<username> on Windows and /dwelling/<username> on Linux.
Using the /p
and /l
switches, the WSL will translate these folder paths betwixt platforms.
Sharing and Translating Windows Paths with Linux
Y'all tin can share a single path or multiple paths at in one case using the /p
and /l
switches.
At a Windows command prompt and with a Windows environment variable defined chosen DESKTOP, assign a value of DESKTOP/p
to the WSLENV variable. This allows you to admission it from WSL Linux. Y'all tin come across an example below.

The exact same process can be performed for multiple paths at once using the /l
switch.
Sharing and Translating Linux Paths with Windows
To share and translate Linux path with Windows is the same procedure as it Windows although using Linux-specific commands to set environment variables.
For a deeper await at sharing environment variables, check out, this Microsoft article.
Sharing Network Resource
The networking component is another handy resources to share between Windows and WSL Linux.
Physical vs. Virtualized Network Interfaces
In WSL2, the network interfaces are virtualized. Virtualized network interfaces hateful that WSL2 network instances tin can hold unlike IP configurations than their Windows 10 counterparts.
At the time of this writing, IP addresses for WSL2 Linux use Network Accost Translation (NAT) to access network resource on Windows, though Microsoft has mentioned removing NAT is high on their backlog of problems to prepare.

Client DNS Resolution
WSL volition still both generate /etc/resolv.conf and /etc/hosts files to allow for DNS resolution. As long as yous don't explicitly override that behavior in /etc/wsl.conf, client DNS resolution will keep to work as expected.
You'll learn more about the wsl.conf file later in the postal service.
Using PowerShell and Bash Together
I of the coolest features of WSL is the ability to seamlessly pass information to and from PowerShell and Bash on WSL.
PowerShell –> Bash
Since the WSL executable accepts input from the pipeline, y'all can telephone call the wsl.exe command inside of PowerShell and accept stdin. This allows y'all to use WSL to pass entire objects from PowerShell into the WSL which then get processed with the bash terminal. You can see an example beneath.

grep
Fustigate –> PowerShell/Cmd
You can also pass information from bash in the WSL to PowerShell and cmd just as easily. Below you can come across an instance of executing the Linux ls control and passing the output to the PowerShell Select-Object
cmdlet via the pipeline.

You tin also call some Windows cmd utilities from the WSL and pass the output dorsum to Linux as long as both commands are in the system path.
Remember that the WSL knows what the system path is on both sides because it has access to the Windows PATH variable by default
Below you lot can see that you lot tin run ipconfig, which is a Windows control, from inside the WSL and pass that output to the Linux grep command. You lot can also see the opposite of calling the Linux command which and passing output to the Windows ipconfig command.

Translation Problems
There are some caveats to passing command output back and forth between bash and PowerShell.
I big problem is how PowerShell and bash return data. PowerShell is an object-oriented programming language while fustigate is a string manipulation tool. Any PowerShell objects piped to bash will flattened as a cord. Conversely, whatever bash output piped to PowerShell will exist converted to a string object.
You can get effectually the beliefs somewhat past converting or explicitly casting object types in PowerShell like in the example below. But if you are expecting to pass objects between PowerShell and WSL without any extra work, you're going to exist disappointed.

Past casting the bash date as the [datetime]
course in PowerShell, now we have a valid PowerShell object that we tin use in our script. If you are writing scripts that demand to go from Windows to WSL and dorsum over again, information technology'southward possible to practice with a little massaging to the code.
Install a Windows Subsystem for Linux GUI with Xfce4
When command-line tools aren't enough, it's time to intermission out the GUIs. If yous demand to run a graphical utility on WSL, explore a custom distro, or you're not familiar with bash withal, you can install a Linux GUI.
Xfce
Linux has many available desktop environments. One of the most common ones to set upwards for WSL is called Xfce. At the time of this writing, Xfce is at version four. Other desktop environments are available but in this article, y'all'll acquire how to become Xfce4 set upwards.
xRDP
When you have a Linux desktop environment fix up, y'all'll need a service that understands the RDP protocol. In this article, we'll focus on the xRDP server. xRDP is an open source RDP server for Linux that allows you to employ RDP clients to connect to Linux just as if you can Windows hosts.
Setting Upward
To access a Linux GUI from Windows with Xfce4 and xRDP, follow the instructions below. In a WSL concluding:
- Download and install Xfce4 – Download and install Xfce4 using the command
sudo apt-get -y install xfce4 && sudo apt-get -y install xubuntu-desktop
. This will take a while. Stand by. - Install the xRDP server – Download and install xRDP by running
sudo apt-get -y install xrdp
. - Configure xRDP for xfce4 –
echo xfce4-session > ~/.xsession
- Restart xRDP –
sudo service xrdp restart
- Find the WSL distro IP address –
ifconfig | grep inet
At this point, you should be able to open an RDP session from Windows 10. Open up remote desktop connection window using mstsc
and provide the Linux IP address found in step #5.
If all goes well, yous can open an RDP connection to the Linux distro that's running on your Windows operating organisation equally shown beneath.

Tips and Tricks
Now that you lot know the basics of WSL and how to use it, what's next? Fortunately there are a lot of tools that are either congenital for or work well with WSL.
Setting WSL Configuration Items at Bootup with wsl.conf
A configuration file exists in the WSL at /etc/wsl.conf. This file contains configuration settings that run every time the WSL distro is started. When the wsl.conf file exists, WSL will ingest whatsoever setting in this file every fourth dimension the Linux distro is started.
There are a few different sections inside of the wsl.conf file you can configure.
- Automount – Mounting drives from Windows at start
- Network – Generate resolv.conf or the hosts file
- Interop – Enabling or disabling interop with Windows
For more details on the wsl.conf file, check out the Microsoft Set WSL Launch Settings page.
Developing on WSL with Visual Studio Code (VS Lawmaking)
VS Code seemingly integrates with everything and WSL is no exception. From inside VS Code, yous can set upward a workspace on your WSL Distro but manipulate information technology completely with VS Code on Windows. You don't fifty-fifty need to have a terminal running!
To set up VS Code on Windows to work with WSL, you'll first obviously need VS Code for Windows installed. Also be sure you have the Remote – WSL VS Code extension installed.
Once you lot've got the extension installed, you lot can now connect to it by opening a WSL terminal and running code <workspace>
.<Workspace>
is the directory where yous'd like to run VS Code from. VS Code will and then detect that you are in a WSL distro, open a window, and establish a connection to to the workspace.
Ostend it worked by noticing the WSL connection icon in the lower left corner of VS Code. You should see that it has the name of your WSL distro.

You can fifty-fifty apply the built-in terminal to collaborate directly with the WSL workspace. There's no demand to run a separate window for git bash commands.
Adding Windows Subsystem for Linux to the Windows Terminal
Another useful utilize-case of WSL is to add together the WSL console it to the Windows Terminal.
From inside Windows Terminal, you add together each WSL distro in it's own tab. You lot can besides customize the look of each tab so you don't get lost.
If you're using a WSL distro that sets an environment variable for the user directory like UBUNTU_HOME, you can likewise set that as the starting directory for your terminal.

If yous'd like a complete video walkthrough on setting upwardly WSL to piece of work with the Windows Final, cheque out the TechSnips how-to video below.
Closing Thoughts
Microsoft released the WSL to let Linux developers the ability to develop on Windows. And so far, the WSL has been a stride in the right management.
It appears that the WSL is going to be a crucial component of Microsoft's new open up-source friendly strategy. If Microsoft is going to take on Apple to be the devices that developers write their code on, it's going to be an uphill battle. But WSL is a strong card to play.
WSL brings about many many welcome benefits to developers like:
- Significantly lighter weight than running local Linux VMs
- Removing the overhead of installing and managing a hypervisor
- No more than requirement for multi-partitioned hard drives
- No more complicated grub bootloaders
WSL just turns on and runs so we can all lawmaking happily ever after.
johnsonbetteramer.blogspot.com
Source: https://adamtheautomator.com/windows-subsystem-for-linux/
ارسال یک نظر for "Question 10 Unsaved Unix/linux Systems Can Read Ms Windows Filesystems."