Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Main > Live #1988

Merged
merged 16 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion WSL/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ms.topic: article

Windows Subsystem for Linux (WSL) is a feature of Windows that allows you to run a Linux environment on your Windows machine, without the need for a separate virtual machine or dual booting. WSL is designed to provide a seamless and productive experience for developers who want to use both Windows and Linux at the same time.

- Use WSL to install and run various Linux distributions, such as Ubuntu, Debian, Kali, and more. [Install Linux distributions](./install.md) and receive automatic updates from the [Microsoft Store](./compare-versions.md#wsl-in-the-microsoft-store), [import Linux distributions not available in the Microsoft Store](./use-custom-distro.md), or [build your own customer Linux distribution](./build-custom-distro.md).
- Use WSL to install and run various Linux distributions, such as Ubuntu, Debian, Kali, and more. [Install Linux distributions](./install.md) and receive automatic updates from the [Microsoft Store](./compare-versions.md#wsl-in-the-microsoft-store), [import Linux distributions not available in the Microsoft Store](./use-custom-distro.md), or [build your own custom Linux distribution](./build-custom-distro.md).
- Store files in an isolated Linux file system, specific to the installed distribution.
- Run command-line tools, such as BASH.
- Run common BASH command-line tools such as `grep`, `sed`, `awk`, or other ELF-64 binaries.
Expand Down
8 changes: 5 additions & 3 deletions WSL/basic-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ For example:
wsl --shutdown
```

Immediately terminates all running distributions and the WSL 2 lightweight utility virtual machine. This command may be necessary in instances that require you to restart the WSL 2 virtual machine environment, such as [changing memory usage limits](/windows/wsl/disk-space) or making a change to your [.wslconfig file](./manage.md#).
Immediately terminates all running distributions and the WSL 2 lightweight utility virtual machine. This command may be necessary in instances that require you to restart the WSL 2 virtual machine environment, such as [changing memory usage limits](/windows/wsl/disk-space) or making a change to your [.wslconfig file](./manage.md).

## Terminate

Expand All @@ -168,8 +168,10 @@ To terminate the specified distribution, or stop it from running, replace `<Dist

## Identify IP address

- `wsl hostname -i` for the IP address of your Linux distribution installed via WSL 2 (the WSL 2 VM address)
- `cat /etc/resolv.conf` for the IP address of the Windows machine as seen from WSL 2 (the WSL 2 VM)
- `wsl hostname -I`: Returns the IP address of your Linux distribution installed via WSL 2 (the WSL 2 VM address)
- `ip route show | grep -i default | awk '{ print $3}'`: Returns teh IP address of the Windows machine as seen from WSL 2 (the WSL 2 VM)

For a more detailed explanation, see [Accessing network applications with WSL: Identify IP Address](./networking.md#identify-ip-address).

## Export a distribution

Expand Down
10 changes: 7 additions & 3 deletions WSL/faq.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
metadata:
title: FAQ's about Windows Subsystem for Linux
description: "Find answers to frequently asked questions (FAQs) about the Windows Subsystem for Linux, such as 'What can I do with WSL?'."
keywords: BashOnWindows, bash, wsl, windows, windowssubsystem, faq
ms.date: 11/20/2023
ms.date: 07/16/2024
ms.topic: faq
ms.localizationpriority: high
title: Frequently Asked Questions about Windows Subsystem for Linux
Expand Down Expand Up @@ -167,7 +166,7 @@ sections:
- question: |
Can I use WSL for production scenarios?
answer: |
WSL has been designed and built to use with inner loop development workflows. There are design features in WSL that make it great for this purpose but may make it challenging for production-related scenarios compared to other products. Our goal is to make clear how WSL differs from a regular VM environment, so you can make the decision on whether it fits your business needs.
Yes, however WSL has been designed and built to use with inner loop development workflows. There are design features in WSL that make it great for this purpose but may make it challenging for production-related scenarios compared to other products. Our goal is to make clear how WSL differs from a regular VM environment, so you can make the decision on whether it fits your business needs.

The main differences between WSL and a traditional production environment are:

Expand Down Expand Up @@ -209,8 +208,13 @@ sections:
wsl --unregister <Distroname>

# Import your VHD backup

wsl --import-in-place <Distroname> <Install Location with filename>

# Set your default user account

You can set up your default user account by [setting a wsl.conf value of user.default=<name>](/windows/wsl/wsl-config#user-settings)


- name: WSL 2
questions:
Expand Down
2 changes: 1 addition & 1 deletion WSL/filesystems.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ We recommend against working across operating systems with your files, unless yo

For example, when storing your WSL project files:

- Use the Linux file system root directory: `\\wsl$\Ubuntu\home\<user name>\Project`
- Use the Linux file system root directory: `/home/<user name>/Project`
- Not the Windows file system root directory: `/mnt/c/Users/<user name>/Project$` or `C:\Users\<user name>\Project`

When you see `/mnt/` in the file path of a WSL command line, it means that you are working from a mounted drive. So the Windows file system C:/ drive (`C:\Users\<user name>\Project`) will look like this when mounted in a WSL command line: `/mnt/c/Users/<user name>/Project$`. It is possible to store your project files on a mounted drive, but your performance speed will improve if you store them directly on the `\\wsl$` drive.
Expand Down
1 change: 1 addition & 0 deletions WSL/install-manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ There are some scenarios in which you may not be able (or want) to, install WSL
If the Microsoft Store app is not available, you can download and manually install Linux distributions using these links:

- [Ubuntu](https://aka.ms/wslubuntu)
- [Ubuntu 24.04](https://wslstorestorage.blob.core.windows.net/wslblob/Ubuntu2404-240425.AppxBundle)
- [Ubuntu 22.04 LTS](https://aka.ms/wslubuntu2204)
- [Ubuntu 20.04](https://aka.ms/wslubuntu2004)
- [Ubuntu 20.04 ARM](https://aka.ms/wslubuntu2004arm)
Expand Down
44 changes: 43 additions & 1 deletion WSL/networking.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,56 @@
title: Accessing network applications with WSL
description: Learn about the considerations for accessing network applications when using Windows Subsystem for Linux (WSL).
keywords: wsl, Linux, Windows, networking, ip address, ip addr, host IP, server, network, localhost, local area network, lan, ipv6, remote
ms.date: 11/15/2023
ms.date: 07/16/2024
ms.topic: article
---

# Accessing network applications with WSL

There are a few considerations to be aware of when working with networking apps and WSL. By default WSL uses a [NAT based architecture](#default-networking-mode-nat), and we recommend trying the new [Mirrored networking mode](#mirrored-mode-networking) to get the latest features and improvements.

### Identify IP address

There are two scenarios to consider when identifying the IP address used for a Linux distribution running via WSL:

**Scenario One:** From the perspective of the Windows host, you want to query a Linux distribution's IP address running via WSL2, so that a program on Windows host can connect to a server program running inside the distribution (instance).

The Windows host can use command:

```
wsl -d <DistributionName> hostname -I
```

If querying the default distribution, this part of the command designating the distribution can be omitted: `-d <DistributionName>`. Be sure to use a capital `-I` flag and not a lower-case `-i`.

Under the hood, host command `wsl.exe` launches the target instance and executes Linux command `hostname -I`. This command then prints the IP address of the WSL instance to `STDOUT`. The `STDOUT` text content is then relayed back to wsl.exe. Finally, wsl.exe displays that output to the command line.

A typical output might be:

```powershell
172.30.98.229
```

**Scenario Two:** A program running inside a Linux distribution via WSL2 (instance) wants to know the Windows host's IP address, so that a Linux program can connect to a Windows host server program.

The WSL2 Linux user can use command:

```bash
ip route show | grep -i default | awk '{ print $3}'
```

A typical output might be:

```
172.30.96.1
```

So the `172.30.96.1` is the host IP address for Windows, in this example.

> [!NOTE]
> These above IP address querying action is typically required when WSL2 is running with the default [NAT network mode](#default-networking-mode-nat).
> When the WSL2 is running with the new [mirrored mode](#mirrored-mode-networking), the Windows host and WSL2 VM can connect to each other using `localhost` (127.0.0.1) as the destination address, so the trick of using a query peer's IP address is not required.

## Default networking mode: NAT

By default, WSL uses a NAT (Network Address Translation) based architecture for networking. Keep the following considerations in mind when working with a NAT-based networking architecture:
Expand Down
4 changes: 2 additions & 2 deletions WSL/systemd.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Use systemd to manage Linux services with WSL
description: Learn how to use systemd to manage Linux services with Windows Subsystem for Linux.
ms.date: 06/16/2023
ms.date: 07/17/2024
ms.topic: article
---

Expand Down Expand Up @@ -60,7 +60,7 @@ Microsoft partnered with Canonical to bring systemd support to WSL. See Craig Lo

A few examples of Linux applications that depend on systemd are:

- [snap](https://snapcraft.io/): a software packaging and deployment system developed by Canonical for operating systems that use the Linux kernel and the systemd init system. The packages are called "snaps", the command line tool for building snaps is called "Snapcraft", the central repository where snaps can be downloaded/installed is called the "Snap Store", and the daemon required to run snaps (download from the store, mount into place, confine, and run apps out of them) is called "snapd". The entire system is sometimes referred to as "snappy." Try running the command: `snap install spotify` or `snap install postman`.
- [snap](https://snapcraft.io/): a software packaging and deployment system developed by Canonical for operating systems that use the Linux kernel and the systemd init system. The packages are called "snaps", the command line tool for building snaps is called "Snapcraft", the central repository where snaps can be downloaded/installed is called the "Snap Store", and the daemon required to run snaps (download from the store, mount into place, confine, and run apps out of them) is called "snapd". The entire system is sometimes referred to as "snappy." Try running the command: `snap install spotify`.

- [microk8s](https://microk8s.io/): an open-source, low-ops, minimal production Kubernetes that automates deployment, scaling, and management of containerized apps. Follow the instructions to [Install MicroK8s on WSL2](https://microk8s.io/docs/install-wsl2), check out the [Get Started Tutorial](https://microk8s.io/docs/getting-started), or watch the video on [Kubernetes on Windows with MicroK8s and WSL 2](https://ubuntu.com/blog/kubernetes-on-windows-with-microk8s-and-wsl-2).

Expand Down
20 changes: 8 additions & 12 deletions WSL/use-custom-distro.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,25 @@ In this example, we'll use Docker inside of a WSL distribution to obtain the tar

1. Open the command line (Bash) for a Linux distribution that you've already installed from the Microsoft Store (Ubuntu in this example).

2. Start the Docker service:

```bash
sudo service docker start
```
2. Ensure you have Docker Desktop running (Or if you have Docker installed in the WSL distro start the service with `sudo service docker start` )

3. Run the CentOS container inside Docker:

```bash
docker run -t centos bash ls /
docker run -t --name wsl_export centos ls /
```

4. Grab the CentOS container ID using grep and awk:
4. Export the container ID to a tar file on your mounted c-drive:

```bash
dockerContainerID=$(docker container ls -a | grep -i centos | awk '{print $1}')
docker export wsl_export > /mnt/c/temp/centos.tar
```

5. Export the container ID to a tar file on your mounted c-drive:
5. Clean up the container

```bash
docker export $dockerContainerID > /mnt/c/temp/centos.tar
```
```bash
docker rm wsl_export
```

![Example of running the commands above](./media/run-any-distro-tarfile.png)

Expand Down
17 changes: 9 additions & 8 deletions WSL/wsl-config.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Advanced settings configuration in WSL
description: A guide to the wsl.conf and .wslconfig files used for configuring settings when running multiple Linux distributions on Windows Subsystem for Linux.
ms.date: 01/17/2024
ms.date: 07/16/2024
ms.topic: article
ms.custom: seo-windows-dev
adobe-target: true
Expand Down Expand Up @@ -218,14 +218,15 @@ This file can contain the following options that affect the VM that powers any W
| swapFile | path | `%USERPROFILE%\AppData\Local\Temp\swap.vhdx` | An absolute Windows path to the swap virtual hard disk. |
| pageReporting | boolean | `true` | Default `true` setting enables Windows to reclaim unused memory allocated to WSL 2 virtual machine. |
| guiApplications | boolean | `true` | Boolean to turn on or off support for GUI applications ([WSLg](https://github.com/microsoft/wslg)) in WSL.|
| debugConsole | boolean* | `false` | Boolean to turn on an output console Window that shows the contents of `dmesg` upon start of a WSL 2 distro instance. Only available for Windows 11.|
| nestedVirtualization | boolean* | `true` | Boolean to turn on or off nested virtualization, enabling other nested VMs to run inside WSL 2. Only available for Windows 11.|
| vmIdleTimeout | number* | `60000` | The number of milliseconds that a VM is idle, before it is shut down. Only available for Windows 11.|
| dnsProxy | bool | true | Only applicable to networkingMode = NAT. Boolean to inform WSL to configure the DNS Server in Linux to the NAT on the host. Setting to false will mirror DNS servers from Windows to Linux. |
| debugConsole* | boolean | `false` | Boolean to turn on an output console Window that shows the contents of `dmesg` upon start of a WSL 2 distro instance. Only available for Windows 11.|
| nestedVirtualization* | boolean | `true` | Boolean to turn on or off nested virtualization, enabling other nested VMs to run inside WSL 2. Only available for Windows 11.|
| vmIdleTimeout* | number | `60000` | The number of milliseconds that a VM is idle, before it is shut down. Only available for Windows 11.|
| dnsProxy | boolean | true | Only applicable to networkingMode = NAT. Boolean to inform WSL to configure the DNS Server in Linux to the NAT on the host. Setting to false will mirror DNS servers from Windows to Linux. |
| networkingMode** | string | NAT | If the value is `mirrored` then this turns on mirrored networking mode. Default or unrecognized strings result in NAT networking. |
| firewall** | bool | true | Setting this to true allows the Windows Firewall rules, as well as rules specific to Hyper-V traffic, to filter WSL network traffic. |
| dnsTunneling** | bool | true | Changes how DNS requests are proxied from WSL to Windows |
| autoProxy* | bool | true | Enforces WSL to use Windows’ HTTP proxy information |
| firewall** | boolean | true | Setting this to true allows the Windows Firewall rules, as well as rules specific to Hyper-V traffic, to filter WSL network traffic. |
| dnsTunneling** | boolean | true | Changes how DNS requests are proxied from WSL to Windows |
| autoProxy* | boolean | true | Enforces WSL to use Windows’ HTTP proxy information |
| defaultVhdSize | size | `1TB` | Set the Virtual Hard Disk (VHD) size that stores the Linux distribution (for example, Ubuntu) file system. Can be used to limit the maximum size that a distribution file system is allowed to take up. |

Entries with the `path` value must be Windows paths with escaped backslashes, e.g: `C:\\Temp\\myCustomKernel`

Expand Down