WSL 攻略

參考微軟官方文件

啟用 windows 功能

  1. 按下 +R 後在執行視窗輸入 Optionalfeatures 再按 確認Enter ↲
  2. 勾選 Windows 子系統 Linux 版 後按下 確認
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  3. 等待彈出視窗完成相關步驟

安裝 wsl

wsl --install

移動已安裝系統

下面整理各位爆盤俠會需要的步驟

確認安裝位置

參考這篇文章,以下指令可以確認你系統安裝的位置

Get-ChildItem "HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss" -Recurse

像我會呈現

這樣
Name                           Property
----                           --------
{48ebbf72-eff3-40db-969d-52772 State            : 1
b88d20c}                       DistributionName : Ubuntu
                               Version          : 2
                               BasePath         : \\?\D:\Ubuntu
                               Flags            : 15
                               DefaultUid       : 0
{72c61ce1-2653-4ac0-aaf5-a464b State            : 1
6a2993b}                       DistributionName : docker-desktop
                               Version          : 2
                               BasePath         : \\?\D:\docker-desktop
                               Flags            : 15
                               DefaultUid       : 0
{743d2c1c-979b-4e25-aff2-b1d00 State            : 1
a82f923}                       DistributionName : kali-linux
                               Version          : 2
                               BasePath         : \\?\D:\kali-linux
                               Flags            : 15
                               DefaultUid       : 0
{7dec4552-0e72-4279-8519-3d004 State            : 1
75f58ee}                       DistributionName : Ubuntu-20.04
                               Version          : 2
                               BasePath         : \\?\D:\Ubuntu-20.04
                               Flags            : 15
                               DefaultUid       : 0
{a2254c30-b1fc-4828-b689-c186e State            : 1
600817e}                       DistributionName : docker-desktop-data
                               Version          : 2
                               BasePath         : \\?\D:\docker-desktop-data
                               Flags            : 15
                               DefaultUid       : 0

匯出

參考這篇文章

  1. 匯出前至少先將要匯出的系統關掉,以下指令擇一使用

    wsl --terminate, -t <Distro>
    終止指定的發佈(系統)。
    範例
    ​​​​​​wsl -t Ubuntu
    
    wsl --shutdown
    立即終止所有執行中的發佈和 WSL 2 輕量公用程式虛擬機器。
  2. 使用以下指令進行匯出

    wsl --export <Distro> <FileName>
    將發佈匯出為 tar 檔案。
    檔案名稱可以是 - 以用於標準輸出。
    範例
    ​​​​​​wsl --export Ubuntu "C:\Ubuntu.tar"
    

取消登錄並刪除

用以下指令將 要搬移的系統 取消登錄並刪除

wsl --unregister <Distro>
取消登錄發佈並刪除根檔案系統。
範例
​​wsl --unregister Ubuntu

匯入

用以下指令將剛匯出的 tar 檔案匯入到要移動的位置

wsl --import <Distro> <InstallLocation> <FileName> [Options]

匯入指定的 tar 檔案作為新發佈。
檔案名稱可以是 - 以用於標準輸入。
選項:

--version <Version>
指定要用於新發佈的版本。

範例

​​wsl --import Ubuntu "D:\Ubuntu" "C:\Ubuntu.tar" --version 2

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
小提示:你會需要建立資料夾