跳至內容
出自 Arch Linux 中文维基

archlinux-wsl 項目提供了每月更新的WSL(Windows Subsystem for Linux,適用於 Linux 的 Windows 子系統)鏡像,旨在通過最簡且完整的系統在 WSL 上提供完整的 Arch Linux 體驗。

注意:該項目僅為 WSL 2 構建鏡像,不支持 WSL 1。

安裝

已安裝了 WSL 2 的 Windows 系統上遵循以下安裝方式之一:

自動安裝

警告:該方法目前仍在開發,暫時無用。

在 PowerShell 提示符中執行該命令:

> wsl --install archlinux

然後您可以在開始菜單中通過 archlinux 應用程式在 WSL 中運行 Arch Linux,亦可在 PowerShell 提示符中執行 wsl -d archlinux

手動安裝

WSL 2.4.4 及更新版本

下載最新的 Arch Linux .wsl 鏡像,雙擊安裝。

然後您可以在開始菜單中通過 archlinux 應用程式在 WSL 中運行 Arch Linux,亦可在 PowerShell 提示符中執行 wsl -d archlinux

WSL 2.4.4 前的版本

下載最新的 Arch Linux .wsl 鏡像,在 PowerShell 提示符中執行以下命令:

> wsl --import 发行版名称 安装位置 镜像文件位置

例如:

> wsl --import archlinux C:\Users\用户名\Documents\WSL\archlinux C:\Users\用户名\Downloads\archlinux-2025.04.01.121271.wsl

然後您可以在開始菜單中通過 archlinux 應用程式在 WSL 中運行 Arch Linux,亦可在 PowerShell 提示符中執行 wsl -d archlinux。確保在第一次啟動後立刻執行安裝腳本 /usr/lib/wsl/first-setup.sh

提示和技巧

設定默認用戶

要設定 root 以外的默認用戶,請將以下行添加到 /etc/wsl.conf

[user]
default=username

此更改將在下次會話啟動時生效,要終止當前會話,請在 PowerShell 提示符中執行以下命令:

> wsl --terminate archlinux

用 WSLg 運行圖形界面應用程式

WSLg(Windows Subsystem for Linux GUI)項目致力於讓 WSL 運行 Linux 圖形界面(X11 和 Wayland)應用程式

要用 WSLg 運行圖形界面應用程式,必須創建以下符號連結:

$ ln -sf /mnt/wslg/.X11-unix/* /tmp/.X11-unix/
$ ln -sf /mnt/wslg/runtime-dir/wayland-0* /run/user/user_uid/

可以將以上命令添加到 ~/.bashrc 以在會話啟動時自動創建符號連結。

疑難解答

systemd 支持

Arch Linux WSL 鏡像支持 systemd

然而,有一些已知問題可能需要額外操作才能使 systemd 支持工作。

systemd-firstboot.service 掛起

The systemd-firstboot.service job hangs at first boot, preventing any other systemd services to start.

While waiting for the actual root cause of this issue (and a proper fix for it) to be identified, a workaround is automatically applied by the first-setup script when running the image for the first time, so you should not have to do anything on that front.

See archlinux/archlinux-wsl#3

for more details.

systemd 需要純 cgroup v2 支持

Currently, WSL starts systems with cgroup v1 support by default[1] but systemd >= 256 dropped support for it[2] and requires plain cgroup v2 support.

While waiting for WSL to start systems with plain cgroup v2 support by default, you can force it by disabling cgroup v1 support in the %USERPROFILE%/.wslconfig file on your Windows system (create it if it does not exists) with the following content:

[wsl2]
kernelCommandLine = cgroup_no_v1=all systemd.unified_cgroup_hierarchy=1

Docker 容器運行出錯

One might face the following error when running a Docker container from WSL:

Error response from daemon: path / is mounted on / but it is not a shared or slave mount
Error: failed to start containers

This is because Docker expects the root (/) directory to be mounted with rshared propagation.

To do so, run:

# mount --make-rshared /

參見