forked from pxlrbt/move-wsl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
move-wsl.bat
50 lines (39 loc) · 1.1 KB
/
move-wsl.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
@echo off
SETLOCAL
SET WSL_NAME=%~1
SET WSL_TARGET=%~2
IF %WSL_TARGET:~-1%==\ SET WSL_TARGET=%WSL_TARGET:~0,-1%
SET TEMP_FILE=%WSL_TARGET%\%WSL_NAME%.tar
SET /P PROMPT="Move WSL '%WSL_NAME%' to '%WSL_TARGET%'? (Y|n) "
IF /I "%PROMPT%" NEQ "Y" GOTO :EOF
IF NOT EXIST "%WSL_TARGET%" (
ECHO Creating target dir "%WSL_TARGET%" ...
SETLOCAL enableextensions
MD "%WSL_TARGET%"
ENDLOCAL
)
ECHO Exporting VHDX to "%TEMP_FILE%" ...
wsl --export %WSL_NAME% "%TEMP_FILE%"
IF %ERRORLEVEL% EQU 0 IF EXIST "%TEMP_FILE%" (
ECHO Export successful.
GOTO :UNREGISTER
)
ECHO ERROR: Export failed!
CALL :CLEANUP
GOTO :EOF
:UNREGISTER
ECHO Unregistering WSL ...
wsl --unregister %WSL_NAME% >nul 2>&1
ECHO Importing "%WSL_NAME%" at "%WSL_TARGET%" ...
wsl --import "%WSL_NAME%" "%WSL_TARGET%" "%TEMP_FILE%"
ECHO Validating import ...
IF NOT EXIST "%WSL_TARGET%\ext4.vhdx" (
IF NOT EXIST "%WSL_TARGET%\rootfs" (
ECHO ERROR: Import failed! Target file not found. Export file at '%TEMP_FILE%'
GOTO :EOF
)
)
:CLEANUP
ECHO Cleaning up ...
IF EXIST "%TEMP_FILE%" DEL "%TEMP_FILE%"
ECHO Done!