Skip to content
Open
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
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# Changelog

## 1.4.0 - 2024-12-26
**Major update with multiple bug fixes and improvements:**

### Bug Fixes
- **#37**: Fixed script failing when only one distro is installed (improved parsing)
- **#30/#35**: Added automatic `wsl --shutdown` before export to prevent "file in use" errors
- **#29**: Default distro setting is now preserved after move

### Enhancements
- **#23**: Pre-check for NTFS compression on target folder (prevents corruption)
- Added CLI parameters for non-interactive mode: `-Distro`, `-Target`, `-Force`, `-NoShutdown`
- Improved visual feedback with colors and progress messages
- Shows distro info (WSL version, state, default status) during selection
- Displays export file size after completion

### Technical
- Replaced `ConvertFrom-String` with robust manual parsing
- Better error messages with recovery suggestions

## 1.3.2 - 2020-09-09
Fix: Bug in PS script: Import failed when target folder was entered with trailing slash.

Expand Down
108 changes: 88 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,123 @@
> [!Warning]
> As I switched the OS, I am not updating this script or fixing bugs anymore.
> Have a look at the issue tab for some known issues.
> Happy to merge PRs with fixes.

# Move WSL

PowerShell script to move WSL 1 and WSL 2 distros VHDX file to a different location.

![Interactive Example](screencast.gif)

## Features (v1.4.0)

- ✅ Supports both WSL 1 and WSL 2
- ✅ Interactive and CLI modes
- ✅ Automatic WSL shutdown to prevent file locks
- ✅ Preserves default distro setting
- ✅ Pre-checks for NTFS compression (prevents corruption)
- ✅ Colored output with progress feedback

## Usage

### Interactive Mode

```powershell
./move-wsl.ps1
```

1. Select your distro from the list
2. Enter your target path (e.g., `D:\wsl\ubuntu`)
3. Confirm the operation

### CLI Mode (Non-Interactive)

```powershell
# Basic usage
./move-wsl.ps1 -Distro "Ubuntu" -Target "D:\wsl\ubuntu"

# Force mode (skip confirmations)
./move-wsl.ps1 -Distro "Ubuntu" -Target "D:\wsl\ubuntu" -Force

# Skip WSL shutdown (not recommended)
./move-wsl.ps1 -Distro "Ubuntu" -Target "D:\wsl\ubuntu" -NoShutdown
```

### Parameters

| Parameter | Description |
|-----------|-------------|
| `-Distro` | Name of the WSL distro to move |
| `-Target` | Destination folder path |
| `-Force` | Skip confirmation prompts and NTFS compression warning |
| `-NoShutdown` | Skip automatic WSL shutdown (not recommended) |

## ⚠️ Important Notes

> **Warning**
>
> This script uses official `wsl` commands and was used by a lot of people. Nevertheless some people had weird issues that resulted in broken WSL disks.
> Make sure you have a backup of your data, so you can restore in case of an error.
> This script uses official `wsl` commands and was used by many people. Make sure you have a backup of your data before proceeding.

Interactive way of moving wsl for Windows PowerShell.
### Before Running

1) `./move-wsl.ps1`
2) Select your distro
3) Enter your target (i.e. `D:\wsl target\ubuntu`)
1. **Backup important data** in your WSL distro
2. **Close all applications** using WSL
3. **Stop Docker Desktop** if moving Docker WSL distros

## Moving Docker WSL
### NTFS Compression Warning

The script will check if the target folder has NTFS compression enabled. **Compressed folders can corrupt WSL images.** If detected, disable compression:

Before moving Docker WSL make sure to stop the Docker service. Otherwise Docker will crash and you may need to reset it to factory defaults.
1. Right-click the target folder
2. Properties → Advanced
3. Uncheck "Compress contents to save disk space"

## FAQ

### Default user was switched to root when moving a distro

Set your default user inside your distro by adding the following configuration to your `/etc/wsl.conf`.
Set your default user inside your distro by adding the following configuration to your `/etc/wsl.conf`:

```ini
[user]
default=YOUR_USERNAME
```

If the file doesn't exist create it manually. Then exit your distro, terminate it (`wsl -t YOUR_DISTRO`) and start it again. For further options see [Microsoft Docs](https://docs.microsoft.com/en-us/windows/wsl/wsl-config#user).
If the file doesn't exist, create it manually. Then exit your distro, terminate it (`wsl -t YOUR_DISTRO`) and start it again.

Some distributions also allow settings the default user via command line with `YOUR_DISTRO config --default-user YOUR_USER` (e.g. `ubuntu config --default-user johndoe`). Make sure to shutdown your distro before (`wsl -t YOUR_DISTRO`).
Some distributions also allow setting the default user via command line:
```powershell
ubuntu config --default-user johndoe
```

### Standard distro switched when moving it

Since we need to unregister to import it with the same name, the standard distro can be switched. Just set your standard distro again:
The script now automatically preserves the default distro setting (v1.4.0+). If using an older version:

```sh
```powershell
wsl -s YOUR_DISTRO
```

### Script cannot be loaded (not digitally signed)

Run this command to allow the script:

```powershell
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
./move-wsl.ps1
```

### WSL version was switched when moving distro

On import the distro will be registered with the current default WSL version. You can set your default WSL version with `wsl --set-default-version <Version>`.
When the WSL version was accidentally changed while moving, you can set the version with `wsl --set-version <Distro> <Version>`.
On import, the distro will be registered with its original WSL version. If it changed:

```powershell
wsl --set-version <Distro> <Version>
```

## Moving Docker WSL

Before moving Docker WSL, make sure to:

1. Stop Docker Desktop completely
2. Wait a few seconds for processes to terminate
3. Run the script

## License

This project is licensed under the GPL-3.0 License - see the [LICENSE](LICENSE) file for details.
Loading