Please read this [post](https://stackoverflow.com/questions/38779801/move-wsl-bash-on-windows-root-filesystem-to-another-hard-drive) if you are familiar with the English. 這篇筆記是記錄我在`C:`容量不夠時,尋找移動WSL到`D:`的方法,詳情請參考上面那篇貼文。 ## Step 1 輸出原本的WSL,這裡的`DistributionName`可以透過`wsl -l -v`獲得,`Tar-FileName`就任意以tar為副檔名的名稱都可以。在FileName前面可以加上路徑,如果要指定`D:`就在前面加上`D:\` ```powershell= wsl.exe --export <DistirbutionName> <Tar-FileName> ``` ## Step 2 把輸出的tar輸入到新的一個WSL中,一樣透過powershell(Admin)操作。 `NewDistributionName`: 可以是任意名稱,可以當作你幫你的WSL取的名字 `NewPath`: 可以是任意路徑,就是未來要存放WSL的地方 `Tar-FileName`: 上一步生成的tar檔案 ```powershell= wsl.exe --import <NewDistributionName> <NewPath> <Tar-FileName> ``` ## Step 3 開啟新的WSL ``` wsl.exe -d <NewDistributionName> ``` ## Step 4 更改預設使用者,這裡開始就是在bash內操作了。 ```bash= echo "[user]\ndefault = <your user name>" >> /etc/wsl.conf ``` 到這裡就完成了。 ## Step 5 (Optional) 我們可以把原本的WSL刪掉,釋放儲存空間 ```powershell= wsl.exe --unregister <DistributionName> ```