These are the basic instructions to build Arch on WSL 2.
- For instructions on bootstrapping WSL 1, please go here.
- Installing Arch Linux for WSL2
- Install Yay AUR Helper and Pacman Wrapper
- Configure the Arch Linux WSL install for systemd
- Install and Configure Windows Terminal
- Powerline Fonts
- Launch X11 apps from the shell to Windows display
-
Install/upgrade to the
Windows Subsystem for Linux 2
. Go here. -
Install your favorite available distro from the
Windows Store
, then launch it from theStart
menu.Steps 3-8 should be completed on a linux system
-
Download the Arch Linux bootstrap (latest version at time of writing).
wget https://mirrors.edge.kernel.org/archlinux/iso/latest/archlinux-bootstrap-2020.07.01-x86_64.tar.gz
-
Extract the image.
sudo tar -zxvf archlinux-bootstrap-2020.07.01-x86_64.tar.gz
-
Enter the extraced directory
root.x86_64
cd root.x86_64
-
Uncomment some servers in the pacman mirrorlist.
vim /etc/pacman.d/mirrorlist
-
Recompress files in
root.x86_64
directory.sudo tar -czvf root.tar.gz *
-
Move the
root.tar.gz
file to an accessible Windows directory.sudo mv root.tar.gz /mnt/c/Users/USERNAME/root.tar.gz
After this step, you no longer need the temporarily installed linux system
-
Open a PowerShell prompt as Admin, and issue the following command:
wsl --import Archlinux PATH_WHERE_VHD_SHOULD_BE_CREATED C:\Users\USERNAME\root.tar.gz
-
Launch Archlinux from WSL.
wsl -d Archlinux
-
Initialize Arch keyring.
pacman-key --init pacman-key --populate archlinux
-
Install base.
pacman -Syyu base base-devel git vim wget reflector fish
-
Enable
multilib
(if you want).linenumber=$(grep -nr "\\#\\[multilib\\]" /etc/pacman.conf | gawk '{print $1}' FS=":") sed -i "${linenumber}s:.*:[multilib]:" /etc/pacman.conf linenumber=$((linenumber+1)) sed -i "${linenumber}s:.*:Include = /etc/pacman.d/mirrorlist:" /etc/pacman.conf
-
Sync package databases.
pacman -Syy
-
Update mirror list (replace United States with preferred repo mirror country).
reflector --country "United States" --age 12 --protocol https --sort rate --save /etc/pacman.d/mirrorlist
-
Set
root
user password.passwd
-
Create new user.
useradd -m -G wheel -s /bin/fish -d /home/username username
-
Set password on user.
passwd username
-
Enable
wheel
group.sed -i '/%wheel ALL=(ALL) ALL/c\%wheel ALL=(ALL) ALL' /etc/sudoers
-
Edit Arch locale and regenerate.
sed -i 's:#en_US.UTF-8 UTF-8:en_US.UTF-8 UTF-8:g' /etc/locale.gen locale-gen echo LANG=en_US.UTF-8 >> /etc/locale.conf echo LANGUAGE=en_US.UTF-8 >> /etc/locale.conf echo LC_ALL=en_US.UTF-8 >> /etc/locale.confS
-
Create a directory for the yay PKGBUILD files and enter it.
mkdir ~/yay
cd ~/yay
-
Download yay PKGBUILD from AUR.
wget "https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=yay" --output-document=./PKGBUILD
-
Run
makepkg
to build and install yay.makepkg -si
- Alternatively, you could use the instructions from the official Yay Github repo)
This guid is based off the information found on WSL.dev.
-
Install
daemonize
.yay -S daemonize
-
Create the
wsl.conf
file on the system.vim /etc/wsl.conf
[automount] enabled = true options = "metadata,uid=1000,gid=1000,umask=22,fmask=11,case=off" mountFsTab = true crossDistro = true [network] generateHosts = false generateResolvConf = true [interop] enabled = true appendWindowsPath = true [user] default = your_username
-
Create a startup script daemonize systemd as PID 1.
vim /etc/profile.d/00-wsl2-systemd.sh
SYSTEMD_PID=$(ps -ef | grep '/lib/systemd/systemd --system-unit=basic.target$' | grep -v unshare | awk '{print $2}') if [ -z "$SYSTEMD_PID" ]; then sudo /usr/bin/daemonize /usr/bin/unshare --fork --pid --mount-proc /lib/ systemd/systemd --system-unit=basic.target SYSTEMD_PID=$(ps -ef | grep '/lib/systemd/systemd --system-unit=basic. target$' | grep -v unshare | awk '{print $2}') fi if [ -n "$SYSTEMD_PID" ] && [ "$SYSTEMD_PID" != "1" ]; then exec sudo /usr/bin/nsenter -t $SYSTEMD_PID -a su - $LOGNAME fi
-
Exit out of WSL, and re-enter. It should now be running systemd.
- If you have any issues with the network, manually set a public DNS entry.
-
From the Windows Store, install Windows Terminal.
-
Copy any
.png
or.ico
that you would like to use as distro icons to the following folder:%LOCALAPPDATA%\packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\RoamingState\
-
Edit the
settings.json
file forWindows Terminal
and add the following line to the list item:"icon" : "ms-appdata:///roaming/filename.ico",
Download and install fonts for Powerline. Download here.
-
Download, install and then launch VcXsrv.
Select display settings
- Take defaultSelect how to start clients
- Take defaultExtra settings
- Be sureDisable access control
is checked.Configuration complete
- ClickFinish
-
Create a firewall rule in Windows to allow communication from WSL 2 to host OS.
New-NetFirewallRule -DisplayName "X Server - WSL 2" -Direction Inbound -Program "C:\Program Files\VcXsrv\vcxsrv.exe" -Action Allow
-
Get the IP of your local computer of the
vEthernet (WSL)
interface from CMD or PowerShell:ipconfig
-
Export output to display using IP address collected in step 3.
For
bash
andzsh
:export DISPLAY=192.168.1.100:0
For
fish
:set -x DISPLAY 192.168.1.100:0
Note: Add to
~/.bashrc
,~/.zshrc
, or~/.config/fish/fish.config
and you won't need to type it again on the next WSL launch. -
Install an xorg app for testing (We will use the Xorg Calculator).
sudo pacman -S xorg-xcalc
-
Launch
xcalc
to test.xcalc
-
If
VcXsrv
is working properly, Xorg Calculator should popup as a new window.