WSL2 安装 archlinux

安装步骤

  1. 下载LxRunOffline
https://github.com/DDoSolitary/LxRunOffline/releases
  1. 加压后将所有的文件放入一个文件,并将LxRunOffline.exe所在路径加入环境变量,这样可以在命令行使用该程序。
  2. 下载Archlinux bootstrap镜像,本文使用镜像源文件名格式如下archlinux-bootstrap-2021.05.01-x86_64.tar.gz
  3. 安装archlinux,命令格式如下
LxRunOffline i -n <自定义名称> -f <Arch镜像位置> -d <安装系统的位置> -r root.x86_64

例如

LxRunOffline  i -n archlinux -f C:Users32861Downloadsarchlinux-bootstrap-2021.05.01-x86_64.tar.gz -d D:linuxarchlinux -r root.x86_64
  1. 进入系统
wsl -d archlinux

若出现FATAL: kernel too old的报错,可使用 wsl --set-version <distribution name> 2or1为当前linux系统设置正确的wsl版本。

配置

  1. 重新启动 archlinux
    进入windows,执行如下命令
wsl -t archlinux # 关闭 archlinux
wsl -d archlinux # 启动 archlinux
  1. 添加 archlinuxcn
  2. cd /etc/
  3. explorer.exe .
  4. 打开 /etc/pacman.conf
  5. 文件最后添加如下内容
[archlinuxcn]
Server = https://mirrors.tuna.tsinghua.edu.cn/archlinuxcn/$arch
  1. 进入 /etc/pacman.d/mirrorlist,取消China源注释(注销一部分也行)。
  2. 更新系统
pacman -Syy
pacman-key --init
pacman-key --populate
pacman -S archlinuxcn-keyring
  1. 添加个人用户(可选)
  2. 设置默认登录用户
# linux 中执行
id -u username # 查看用户ID
# windows 执行
lxrunoffline su -n archlinux -v 用户ID

参考

https://www.jianshu.com/p/f1359913ad42
https://www.cnblogs.com/kainhuck/p/13835833.html

如有不当,欢迎指正 :)
原文地址:https://www.cnblogs.com/lif323/p/14802468.html