在 Windows 10 2017秋季更新后 WSL 替换 Ubuntu 为 Archlinux

从Windows商店安装Ubuntu。

从开始菜单打开 Ubuntu。

通过 cmd 切换默认用户为 root:

> ubuntu config --default-user root

重新打开 Ubuntu。

Arch Linux Downloads或镜像站 下载一个 archlinux-bootstrap.tar.gz, 并解压:

# wget https://mirrors.tuna.tsinghua.edu.cn/archlinux/iso/2018.05.01/archlinux-bootstrap-2018.05.01-x86_64.tar.gz
# tar -zxvf archlinux-bootstrap-2018.05.01-x86_64.tar.gz

修改 ~/root.x86_64/etc/pacman.d/mirrorlist, 选择需要的服务器,取消注释。

让WSL自动生成 /etc/resolv.conf:

# echo "# This file was automatically generated by WSL. To stop automatic generation of this file, remove this line." > ~/root.x86_64/etc/resolv.conf

退出所有 Ubuntu Shell, 在资源管理器中打开 %localappdata%\Packages, 并找到 CanonicalGroupLimited.UbuntuonWindows_ 开头的文件夹,删除 %localappdata%\Packages\CanonicalGroupLimited.UbuntuonWindows_*\LocalState\rootfs 中的 bin, etc, lib, lib64, sbin, srv, usr 和 var 等 8 个文件夹。

然后,移动 rootfs\root\root.x86_64 中的 bin, etc, lib, lib64, sbin, srv, usr 和 var 到 rootfs 中。

在另一个 Arch Linux 系统中构建 fakeroot-tcpAURglibc-wslAUR , 然后复制到你的 Windows 电脑。 (通过 --nocheck 选项可以在 makepkg 编译 glibc-wsl 时跳过一个非常耗时的测试套件) glibc-wsl 用于解决 这个bug。 而直到 System V IPC 被完全实现之前 fakeroot-tcp 都是必需的。 (详情)

在另一个 Arch Linux 系统中构建 fakeroot-tcpAUR , 然后复制到你的 Windows 电脑。直到 System V IPC 被完全实现之前 fakeroot-tcp 都是必需的。 (详情)

重新打开 Bash 以安装 Archlinux:

# pacman-key --init
# pacman-key --populate archlinux
# pacman -Syy
# pacman -U fakeroot-tcp-1.22-2-x86_64.pkg.tar.xz
# pacman -Syu base base-devel

注意:在安装 base 和 base-devel 时,需要取消 glibc 和 fakeroot 。

最后,增加一个普通账号。

# useradd -m -G wheel -s /bin/bash username
# passwd root
# passwd username

并通过 cmd 设置该账号为默认账号:

> ubuntu config --default-user username