archlinux-wsl 项目提供了每月更新的WSL(Windows Subsystem for Linux,适用于 Linux 的 Windows 子系统)镜像,旨在通过最简且完整的系统在 WSL 上提供完整的 Arch Linux 体验。
安装
在已安装了 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.
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 /