Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 

Repository files navigation

Introduction

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.

Installation

(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).

  1. Get a bootstrap image from the download page. These instructions will assume the resulting file is called archlinux-bootstrap.tar.gz.
  2. The bootstrap archive is in an incorrect format. Extract the files using sudo tar -xzf archlinux-bootstrap.tar.gz --numeric-owner. Note that using sudo and --numeric-owner is necessary here to maintain permissions and owners. This creates a folder named root.x86_64. Move to that folder with cd root.x86_64 and repackage the contents of that folder with sudo tar -cf ../archlinux.tar . --numeric-owner.
  3. 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 use Arch as the distro name and put the installation directory somewhere in my home folder.
  4. Open the distro from Powershell using wsl -d Arch.
  5. Set the machine-id with systemd-machine-id-setup.
  6. Set the locale with something similar to echo "en_US.UTF-8 UTF-8" > /etc/locale.gen followed by locale-gen. Alternatively, you can install a text editor and manually uncomment the relevant line in /etc/locale.gen.
  7. Initialize pacman's keys using pacman-key --init followed by pacman-key --populate archlinux.
  8. 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 use curl -s "https://gitlab.archlinux.org/pacman/pacman-contrib/-/raw/master/src/rankmirrors.sh.in" -o rankmirrors.sh. Make the script executable with chmod +x rankmirrors.sh.
  9. 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 command curl -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.

Configuration recommendations

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 --shutdown in Powershell and opening a new session), you may need to call sudo systemctl stop systemd-firstboot.service if systemd doesn't work for users.

  • Set a default non-root user by creating one with useradd -m -G wheel <username> (the wheel group is added here to grant sudo access. Note that this assumes sudo has already been configured via visudo). 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.service containing

    [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:

    1. wsl shutdown
    2. wsl --manage Arch -s false
    3. diskpart. Note that this starts the diskpart utility, so the next set of commands will be run inside there.
    4. select vdisk file="<installation-directory>\ext4.vhdx"
    5. attach vdisk readonly
    6. compact vdisk
    7. detach vdisk
    8. exit
    9. wsl --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 link appears when running sudo ldconfig, add to /etc/wsl.conf

    [automount]
    ldconfig=false

    Then modify /etc/ld.so.conf.d/ld.wsl.conf by running

    sudo 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-unix being 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
    

About

Instructions for getting Arch Linux running in WSL2

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors