These are instructions for getting Arch Linux running in WSL. Please note that any support for this is unofficial (!), so be prepared to do some research on your own in case things go wrong.
(From here) The following instructions add Arch as a distro to WSL2. This assumes you already have some sort of Linux installation available (for utilities like tar).
- Get a bootstrap image from the download page. These instructions will assume the resulting file is called
archlinux-bootstrap.tar.gz. - The bootstrap archive is in an incorrect format. Extract the files using
sudo tar -xzf archlinux-bootstrap.tar.gz --numeric-owner. Note that usingsudoand--numeric-owneris necessary here to maintain permissions and owners. This creates a folder namedroot.x86_64. Move to that folder withcd root.x86_64and repackage the contents of that folder withsudo tar -cf ../archlinux.tar . --numeric-owner. - Move the tarball to a Windows-accessible directory. Then import it (from Powershell) with
wsl --import <distro name> <installation directory> <path to archlinux.tar>. For me, I useArchas the distro name and put the installation directory somewhere in my home folder. - Open the distro from Powershell using
wsl -d Arch. - Set the machine-id with
systemd-machine-id-setup. - Set the locale with something similar to
echo "en_US.UTF-8 UTF-8" > /etc/locale.genfollowed bylocale-gen. Alternatively, you can install a text editor and manually uncomment the relevant line in/etc/locale.gen. - Initialize pacman's keys using
pacman-key --initfollowed bypacman-key --populate archlinux. - Get the mirror ranking script from Pacman Contrib from
https://gitlab.archlinux.org/pacman/pacman-contrib/-/raw/master/src/rankmirrors.sh.in. To do so, you can usecurl -s "https://gitlab.archlinux.org/pacman/pacman-contrib/-/raw/master/src/rankmirrors.sh.in" -o rankmirrors.sh. Make the script executable withchmod +x rankmirrors.sh. - Generate a mirror list URL from here and feed it into the mirror ranking script with
curl -s "<url>" | sed -e 's/^#Server/Server/' -e '/^#/d' | ./rankmirrors.sh -n 5 - > /etc/pacman.d/mirrorlist. I personally used the commandcurl -s "https://archlinux.org/mirrorlist/?country=US&protocol=https&ip_version=4" | sed -e 's/^#Server/Server/' -e '/^#/d' | ./rankmirrors.sh -n 5 - > /etc/pacman.d/mirrorlist.
Note that, in the following recommendations, changes to the file /etc/wsl.conf require the WSL instance to be terminated with wsl -t Arch and restarted before seeing effects.
-
Set Arch as the default WSL distro with
wsl -s Arch. -
Ensure systemd is active putting the following into
/etc/wsl.conf:[boot] systemd=true
(From here) Upon restarting WSL (using
wsl --shutdownin Powershell and opening a new session), you may need to callsudo systemctl stop systemd-firstboot.serviceif systemd doesn't work for users. -
Set a default non-root user by creating one with
useradd -m -G wheel <username>(thewheelgroup is added here to grantsudoaccess. Note that this assumessudohas already been configured viavisudo). In/etc/wsl.conf, add the lines[user] default=<username>
-
(From here, here, and here) Keep the instance alive once started by creating the file
/etc/systemd/system/infinite-sleep.servicecontaining[Unit] Description=Infinite sleep to keep instance alive [Service] ExecStart=/mnt/c/Windows/System32/wsl.exe sleep infinity [Install] WantedBy=default.target
Enable the unit with
sudo systemctl enable --now infinite-sleep.service. -
(From here) Minimize the amount of disk space being used. In Powershell (or Command Prompt), run the following:
wsl shutdownwsl --manage Arch -s falsediskpart. Note that this starts thediskpartutility, so the next set of commands will be run inside there.select vdisk file="<installation-directory>\ext4.vhdx"attach vdisk readonlycompact vdiskdetach vdiskexitwsl --manage Arch -s true
-
(From here) If you have an Nvidia GPU and the error
ldconfig: /usr/lib/wsl/lib/libcuda.so.1 is not a symbolic linkappears when runningsudo ldconfig, add to/etc/wsl.conf[automount] ldconfig=false
Then modify
/etc/ld.so.conf.d/ld.wsl.confby runningsudo mkdir /usr/lib/wsl/lib2 sudo ln -s /usr/lib/wsl/lib/* /usr/lib/wsl/lib2 echo /usr/lib/wsl/lib2 | sudo tee /etc/ld.so.conf.d/ld.wsl.conf
-
(From here) If graphical applications fail, it may be an issue with
/tmp/.X11-unixbeing overwritten. Try putting the following into/etc/tmpfiles.d/wslg.conf:# This file is part of the debianisation of systemd. # # systemd is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # See tmpfiles.d(5) for details # Type Path Mode UID GID Age Argument L+ /tmp/.X11-unix - - - - /mnt/wslg/.X11-unix