Skip to content

Instantly share code, notes, and snippets.

@LunarLambda
Last active August 22, 2023 11:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LunarLambda/cb0805bca974247803a7e94db2c6ecc9 to your computer and use it in GitHub Desktop.
Save LunarLambda/cb0805bca974247803a7e94db2c6ecc9 to your computer and use it in GitHub Desktop.
Arch on WSL2, DIY-Style

Arch on WSL2, DIY-Style

NOTE: This requires Windows 11 to work fully. If you're on Windows 10, you won't have working systemd. If you're on an older version of WSL, you should try https://github.com/yuk7/ArchWSL or https://github.com/sileshn/ArchWSL2 instead.

Step 0: Install WSL through the Microsoft Store

https://aka.ms/wslstore

Step 1: Repackage the rootfs

curl -L https://geo.mirror.pkgbuild.com/iso/latest/archlinux-bootstrap-x86_64.tar.gz -o base.tar.gz
sudo bsdtar xzpf base.tar.gz
bsdtar czf arch.tar.gz -C root.x86_64 .

or

curl -sL https://geo.mirror.pkgbuild.com/iso/latest/archlinux-bootstrap-x86_64.tar.gz | bsdtar czf arch.tar.gz --strip-components=1 @-

Copy arch.tar.gz to somewhere on your Windows machine.

Step 2: Register with WSL

wsl --import Arch %USERPROFILE%\Arch arch.tar.gz --version 2
wsl -d Arch

Step 3: System Setup

Fill in the commands according to your own needs, particularly the mirror countries for reflector, the installed pacman packages, the locale, as well as the name for the new default user.

pacman-key --init
pacman-key --populate

sed -i 's/^#Server/Server/' /etc/pacman.d/mirrorlist
pacman -Syy archlinux-keyring rsync reflector
reflector -c de,fr, -l 20 -f 10 -p https,rsync --save /etc/pacman.d/mirrorlist

pacman -Suu pacman-contrib sudo neovim zsh grml-zsh-config

sed -i 's/^#en_US.UTF-8/en_US.UTF-8/' /etc/locale.gen
locale-gen
echo 'LANG=en_US.UTF-8' > /etc/locale.conf

# Enable wheel group
EDITOR=nvim visudo

useradd -mG wheel -s /usr/bin/zsh lambda
passwd lambda

cat >/etc/wsl.conf <<EOF
[boot]
systemd = true

[user]
default = lambda
EOF

exit

Step 4: "Reboot"

wsl --shutdown
timeout /t 8 /nobreak
wsl -d Arch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment