โดยปกติ wsl จะถูกติดตั้งใน %USERPROFILE%\AppData\Local\Packages\ ถ้าจะย้ายไปไดรฟ์อื่นหรือย้ายไปที่อื่น เพราะ drive c เต็มหรืออยากจะ restore windows ทำได้โดย
- สร้างไฟล์ WSL2_move.ps1 โดยมีเนื้อหา
<# PowerShell move Windows Subsystem for Linux 2 (WSL2) #by pitt phunsanit https://pitt.plusmagi.com [email protected] #> $distribution = "Ubuntu" $folderPath = "C:\UsersDatas\WSL\2\" $exportPath = [string]::Concat($folderPath, $distribution, ".tar") $importPath = [string]::Concat($folderPath, $distribution) #make folder #Check if Folder exists If(!(Test-Path -Path $folderPath)) { #PowerShell create directory New-Item -ItemType Directory -Path $importPath Write-Host 'New folder "'$importPath'" created successfully!' -f Green } Else { Write-Host 'Folder "'$importPath'" already exists!' -f Yellow } #stop distribution wsl -t $distribution #export distribution wsl --export $distribution $exportPath #Unregister distribution wsl --unregister $distribution #import distribution wsl --import $distribution $importPath $exportPath #wsl --update Write-Host 'move WSL"'$distribution'" to "'$importPath'" successfully!' -f Blue #show distribution wsl --install -d $distribution
- เรียกใช้โดยเปิด PowerShell โดยสิทธิ์ administrator
- cd ไป folder ที่ save ไฟล์ WSL2_move.ps1 เช่น cd C:\UsersGit\phunsanit\snippets\WSL
- run โดยใช้ .\WSL2_move.ps1 แล้ว enter แค่นี้ก็ย้าย WSL ได้แล้ว