About

Windows 10 version 1909 is finally available for my surface device, I’ve waited for it for several months since there is a very important new feature: WSL2

IMO, WSL1 is not suitable for daily development because the performance is TOO BAD. Can you imagine I spent 15 minutes but still cannon launch neovim while it only took about 100 milliseconds in physical arch linux?

Compared to WSL1, the performance of WSL2 has been greatly improved. I think it’s time to try WSL again.

This time I decided to try void linux. Void linux is an independent rolling release linux distribution, it uses runit as its init system instead of systemd which is generally used in most of distros. Systemd has caused a lot of controversy in the linux community. I personally don’t like it either, I prefer openrc which is developed by gentoo. But looks like runit is also a great alternative to systemd, it might be worth trying, although I’m not sure if it works in WSL2.

Another great feature of void linux is that it officially supports both glibc and musl libc. Musl libc is an implementation of the C standard library. Compared to glibc which is used in most of the distros, musl libc is more lightweight and is written with more security in mind. Here is a detailed comparison: https://www.etalabs.net/compare_libcs.html

Preparation

To begin with, follow this official guide to enable WSL2: https://docs.microsoft.com/en-us/windows/wsl/install-win10

Then download the x86_64-musl rootfs tarballs: https://alpha.de.repo.voidlinux.org/live/current/

And verify it:

Open powershell and execute

1
2
3
4
> CertUtil -hashfile void-x86_64-musl-ROOTFS-20191109.tar.xz SHA256
SHA256 的 void-x86_64-musl-ROOTFS-20191109.tar.xz 哈希:
c3540f9e829e144041271fa7d2e5fd64c64ce8efee3e1955ce90a7e890eedd33
CertUtil: -hashfile 命令成功完成。

Compare the output of this command with sha256.txt.

Installation

First of all, install Ubuntu on WSL1:

  1. Install Ubuntu from Microsoft Store: Ubuntu
  2. Make sure Ubuntu is installed on WSL1 instead of WSL2: wsl --set-version Ubuntu 1
  3. Make sure the default user is root: ubuntu config --default-user root

Now, launch ubuntu from the Start Menu.

Extract the tarball:

1
# tar -xvf /mnt/c/Users/username/Downloads/void-x86_64-musl-ROOTFS-20191109.tar.xz

You may want to change the mirror of void linux:

1
2
3
# mkdir -p ./etc/xbps.d
# cp ./usr/share/xbps.d/*-repository-*.conf ./etc/xbps.d/
# sed -i 's|https://alpha.de.repo.voidlinux.org|https://mirrors.tuna.tsinghua.edu.cn/voidlinux|g' ./etc/xbps.d/*-repository-*.conf

Let WSL generate /etc/resolv.conf automatically:

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

Exit Ubuntu.

Open windows file explorer, navigate to %localappdata%\Packages and find CanonicalGroupLimited.UbuntuonWindows_*.

In %localappdata%\Packages\CanonicalGroupLimited.UbuntuonWindows_*\LocalState\rootfs, delete bin, etc, lib, lib64, lib32, libx32, sbin, usr and var.

Move (Don’t copy) bin, etc, lib, sbin, usr and var from rootfs\root\ to rootfs.

Launch ubuntu again.

Delete useless files in /root

1
# rm -rf ~/*

Install base-system:

1
2
3
4
5
6
# ARCH=x86_64-musl
# XBPS_ARCH=$ARCH
# xbps-install -Su xbps
# xbps-install -u
# xbps-install base-system
# xbps-remove base-voidstrap

Go through the options in /etc/rc.conf:

1
# vi /etc/rc.conf

Set a root password:

1
# passwd

Create a new user:

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

Use xbps-reconfigure to ensure all installed packages are configured properly:

1
# xbps-reconfigure -fa

Exit ubuntu.

Open powershell and set default user:

1
> ubuntu config --default-user username

Set WSL version to WSL2:

1
> wsl --set-version Ubuntu 2

Now we get a void linux on WSL2

void

Post Install

Next you can follow the official guide to configure void linux: https://docs.voidlinux.org/config/index.html