microsoft / microsoft/WSL

`wsl --install --location` downloads distribution before validating target directory existence

Open
#41,625 3 comments 1 reaction 2 assignees Claimed by @benhillis View on GitHub
Dominant language
C++
Stars
33.7k
Forks
1.8k
Avg merge
3d 17h
Merged PRs (30d)
116

Description

**Is your feature request related to a problem? Please describe.**
When installing a Linux distribution with a custom location using `wsl --install --location `, WSL downloads the entire distribution image first. If the target directory specified in `--location` does not exist (which is my case) or parent path validation fails, the command terminates with an error only after the download completes.

This leads to poor UX, unnecessary wait times, and wasted bandwidth—especially on metered/slower network connections.

**Describe the solution you'd like**
Implement a pre-flight validation check on the `--location` path prior to initiating the distribution payload download.

Specifically:

1. Validate that the specified drive and target path exist (or can be created) during initial command-line argument parsing.
2. If the path does not exist, either create the target directory automatically or exit early with a clear error message (e.g., `Error: Target directory 'D:\WSL\Ubuntu' does not exist.`) *before* triggering the download step.

**Describe alternatives you've considered**
Allowing the download to proceed and creating the directory retroactively at the end of the pipeline, which remains vulnerable to path/permission failures after network time has already been consumed.

**Additional context**
Example reproduction (in my case, I don't have D:):

```cmd
wsl --install Ubuntu --location D:\WSL\Ubuntu

```

*Current flow:* Download starts -> 100% complete -> Error: Directory does not exist.

*Expected flow:* Path validation check -> Error / Auto-create directory -> Download starts.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.