1. 程式人生 > 其它 >WSL2 安裝ArchLinux

WSL2 安裝ArchLinux

安裝ubuntu測試

從win10商店下載完直接執行一般會出錯

The WSL optional component is not enabled. Please enable it and try again.
See https://aka.ms/wslinstall for details.
Error: 0x8007007e
Press any key to continue...

需要執行命令開啟WSL的功能,以管理員身份開啟powershell執行以下命令

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

安裝完成後會提示重啟,重啟會更新一些元件延後正常開啟就會安裝了,安裝提示輸入使用者名稱和密碼就可以正常進入系統了。

PS:修改root使用者的密碼

sudo -s #切換到root使用者
passwd  #設定密碼

安裝Windows Terminal和美化

使用WSL配合windows termianl使用更佳

從win10商店安裝直接使用,通過win+r開啟執行wt.exe就可以快捷開啟

簡單美化一下

開啟設定,選擇開啟Json檔案,其中是Terminal的配置檔案

{
    "$schema": "https://aka.ms/terminal-profiles-schema",

    "defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",

    // You can add more global application settings here.
    // To learn more about global settings, visit https://aka.ms/terminal-global-settings

    // If enabled, selections are automatically copied to your clipboard.
    "copyOnSelect": false,

    // If enabled, formatted data is also copied to your clipboard
    "copyFormatting": false,


    "profiles":
    {
        "defaults":
        {
            // Put settings here that you want to apply to all profiles.
        },
        "list":
        [
            {
                // Make changes here to the powershell.exe profile.
                "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
                "name": "Windows PowerShell",
                "commandline": "powershell.exe",
			   "useAcrylic" : true,
                "hidden": false
            },
            {
                // Make changes here to the cmd.exe profile.
                "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
                "name": "命令提示符",
                "commandline": "cmd.exe",
			   "useAcrylic" : true,
                "hidden": false
            },
            {
                "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
                "hidden": false,
                "name": "Azure Cloud Shell",
                "source": "Windows.Terminal.Azure"
            },
            {
                "guid": "{07b52e3e-de2c-5db4-bd2d-ba144ed6c273}",
                "hidden": false,
                "name": "Ubuntu-20.04",
                "source": "Windows.Terminal.Wsl"
            }
        ]
    },

    // Add custom color schemes to this array.
    // To learn more about color schemes, visit https://aka.ms/terminal-color-schemes
    "schemes": [],

    // Add custom actions and keybindings to this array.
    // To unbind a key combination from your defaults.json, set the command to "unbound".
    // To learn more about actions and keybindings, visit https://aka.ms/terminal-keybindings
    "actions":
    [

        { "command": {"action": "copy", "singleLine": false }, "keys": "ctrl+c" },
        { "command": "paste", "keys": "ctrl+v" },

        { "command": "find", "keys": "ctrl+shift+f" },

        { "command": { "action": "splitPane", "split": "auto", "splitMode": "duplicate" }, "keys": "alt+shift+d" }
    ]
}

其中profiles對應著每一個終端的配置,新增

"useAcrylic" : true

開啟亞克力特效,還可以設定字型等(fontFace),方法類似

開啟WSL2

以管理員身份開啟Powershell,執行一下命令開啟虛擬機器平臺可選功能

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

安裝Linux核心更新包

設定WSL2為預設版本

wsl --set=default-version 2

嘗試切換原來的為wsl的ubuntu為wsl2

wsl --set-version Ubuntu-20.04 2  #--set-version後跟開發版的名字再跟wsl版本

出現以下提示

正在進行轉換,這可能需要幾分鐘時間...
有關與 WSL 2 的主要區別的資訊,請訪問 https://aka.ms/wsl2
轉換完成。

檢視,發現版本已經改變了

wsl -l -v

下載 yuk7/ArchWSL,下載最新的zip包,解壓執行Arch.exe,會在目錄下生成系統執行檔案,Arch就可以使用了