windows11 使用 wsl2 安装 archLinux
-
下载 archLinux,下载 tar.gz 文件
下载地址:https://mirrors.tuna.tsinghua.edu.cn/archlinux/iso/latest/
-
启用 WSL
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
-
启用虚拟平台
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
-
设置 WSL2 为默认版本
wsl --set-default-version 2
-
安装 LxRunOffline,解压后把 LxRunOffline 放到 C:/Windows/System32 目录下
下载地址:https://link.zhihu.com/?target=https%3A//github.com/DDoSolitary/LxRunOffline/releases
-
安装 archLinux 到 WSL
命令:
LxRunOffline i -n <自定义名称> -f <Arch镜像位置> -d <安装系统的位置> -r root.x86_64
使用:
LxRunOffline i -n ArchLinux -f C:\Users\xielei\Downloads\archlinux-bootstrap-2022.04.05-x86_64.tar.gz -d D:\WSL\Linux -r root.x86_64
如果输入错误出现
[ERROR] The distro "ArchLinux" already exists.
,使用以下操作:LxRunOffline l
查看已安装的 WSL 名称LxRunOffline di -n <WSL名称>
查看安装的 WSL 目录,可以手动删除lxrunoffline ur -n <WSL名称>
取消 WSL 注册,并不会删除目录(上一步查询的目录)- 重新执行安装命令
-
安装 Linux 内核包,下载完后双击运行
下载地址:https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi
-
进入 ArchLinux 系统
wsl -d ArchLinux # -d 启动, -t 关闭
,如果报错FATAL: kernel too old
,使用wsl --set-version ArchLinux 2
,转换完成后,重新执行。-
新建用户,修改密码
useradd -m -G wheel -s /bin/bash maple passwd maple # 解释各个参数 # -m 在home目录下自动创建一个名为misaki的用户目录 # -G 将maple加入到wheel用户组 (等一下授权的时候用) # -s 指定用户使用的bash # maple 要创建的用户名 # passwd 不加用户名可以给root设置密码
-
更新源
-
使用 Windows 的资源浏览器打开目录
cd /etc/ explorer .
-
修改源配置,找到并打开 pacman.conf 在文件末尾添加如下配置
[multilib] Include = /etc/pacman.d/mirrorlist [archlinuxcn] Server = https://mirrors.tuna.tsinghua.edu.cn/archlinuxcn/$arch
-
修改镜像源,在打开的目录中找到 pacman.d 文件夹,修改里面的 mirrorlist,找到 China 下的镜像,放开注释
Server = https://mirrors.ustc.edu.cn/archlinux/$repo/os/$arch
-
-
更新包,生成 archlinuxcn-keyring,下载终端工具 vim
pacman-key --init pacman-key --populate pacman -S archlinuxcn-keyring pacman -Syy pacman -S base base-devel vim
-
切换用户,查看用户id
su maple # 用自己起的名字 # 查看用户id,后面使用默认登陆用户 id -u maple
-
-
至此,archLinux 在 WSL 中安装完成,进入 /mnt 目录下即为 Windows 系统目录
cd /mnt/
-
退出 wsl 后,在 windows power shell 里切换登录 archlinux 的默认用户,账户id为上面查看的
lxrunoffline su -n <你的arch名字> -v <账户id>