diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index effb0fd..19fb348 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,7 +19,7 @@ jobs: tag="${imagetag#base-}" gh release create "${tag}" \ --notes "Arch Linux WSL modern distribution based on the Docker image \`archlinux:${imagetag}\`" \ - ./artifacts/archlinux.wsl \ + ./artifacts/archlinux-${imagetag}.wsl \ ./artifacts/DistributionInfo.json env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/reusable-package.yml b/.github/workflows/reusable-package.yml index 74250d6..0b890ea 100644 --- a/.github/workflows/reusable-package.yml +++ b/.github/workflows/reusable-package.yml @@ -18,25 +18,25 @@ jobs: DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }} run: | ./build - sha256=$(sha256sum archlinux.wsl) - read -r sha256 _ <<<"${sha256}" tag=$(cat imagetag.txt) + sha256=$(sha256sum archlinux-${tag}.wsl) + read -r sha256 _ <<<"${sha256}" version="${tag#base-}" cat <DistributionInfo.json { - "ModernDistributions": { - "Arch-Linux-Unofficial": [ - { - "Name": "Arch-Linux-Unofficial-${tag}", - "Default": true, - "FriendlyName": "Arch Linux Unofficial version ${version} (latest)", - "Amd64Url": { - "Url": "https://github.com/DevelopersCommunity/archlinux-wsl/releases/download/${version}/archlinux.wsl", - "Sha256": "${sha256}" - } - } - ] - } + "ModernDistributions": { + "Arch-Linux-Unofficial": [ + { + "Name": "Arch-Linux-Unofficial", + "Default": true, + "FriendlyName": "Arch Linux Unofficial Rolling Release", + "Amd64Url": { + "Url": "https://github.com/DevelopersCommunity/archlinux-wsl/releases/download/${version}/archlinux-${tag}.wsl", + "Sha256": "${sha256}" + } + } + ] + } } EOF - name: Upload artifacts @@ -44,7 +44,7 @@ jobs: with: name: artifacts path: | - archlinux.wsl + archlinux-*.wsl imagetag.txt DistributionInfo.json if-no-files-found: error diff --git a/.gitignore b/.gitignore index 701f306..7b6a010 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ /.env -/archlinux.wsl +/archlinux-*.wsl /DistributionInfo.json /imagetag.txt /root/usr/lib/wsl/terminal-profile.json diff --git a/Dockerfile b/Dockerfile index 803bdfc..f34886e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,9 +3,8 @@ FROM archlinux:base # Apply configuration files recommendations # https://learn.microsoft.com/windows/wsl/build-custom-distro#configuration-file-recommendations COPY --chown=root:root --chmod=0644 root/etc/wsl.conf root/etc/wsl-distribution.conf /etc/ -COPY --chown=root:root --chmod=0755 root/etc/oobe.sh /etc/ - -COPY root/usr/lib/wsl/* /usr/lib/wsl/ +COPY --chown=root:root --chmod=0755 root/usr/lib/wsl/oobe.sh /usr/lib/wsl/ +COPY root/usr/lib/wsl/archlinux.ico root/usr/lib/wsl/terminal-profile.json /usr/lib/wsl/ COPY --chmod=0755 configure.sh ./configure.sh RUN ./configure.sh && rm ./configure.sh diff --git a/README.md b/README.md index d7a8ea6..9c4c8f5 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,9 @@ This is an automated script to create an [Arch Linux](https://archlinux.org) distribution](https://learn.microsoft.com/windows/wsl/build-custom-distro). You can download a pre-built version from the [releases -page](https://github.com/DevelopersCommunity/archlinux-wsl/releases/latest). -Get the `archlinux.wsl` file and double-click it in `File Explorer` to -install the distribution. +page](https://github.com/DevelopersCommunity/archlinux-wsl/releases/latest). Get +the `.wsl` file and double-click it in `File Explorer` to install the +distribution. ## Requirements @@ -54,30 +54,6 @@ the [Arch Linux logo](https://archlinux.org/art/) blue color. The script to generate the profile is available in the [`terminal-profile` directory](./terminal-profile/). -## Known issues - -### systemd services won't start - -If you get the following error when running the `systemctl` command, try to -[install another WSL distribution with `systemd` -support](https://aka.ms/wslsystemd/) and check if it works. In my case, -`systemd` started working on Arch Linux after that, and kept working even after -uninstalling the other distro. - -```terminal -$ systemctl -Failed to connect to system scope bus via local transport: No such file or directory -``` - -If you still have problems after installing another distribution, try to run the -following -[command](https://github.com/microsoft/WSL/issues/10205#issuecomment-1601620093) -in a `PowerShell` terminal: - -```powershell -wsl -d Arch-Linux-Unofficial -u root -e systemctl restart user@1000.service -``` - ## Arch Linux trademark The logo used in this distribution was taken from the [Arch Linux logos and diff --git a/build b/build index 522e072..02d2931 100755 --- a/build +++ b/build @@ -51,6 +51,18 @@ docker rmi "archwsl:${tag}" [[ -d rootfs ]] && rm -rf rootfs mkdir rootfs pushd rootfs || exit 1 -fakeroot bash -c "tar -xf ../archlinux.tar && rm -f etc/resolv.conf && tar --numeric-owner --absolute-names -c -- * | gzip --best >../archlinux.wsl" +trim=$( + cat <../archlinux-${tag}.wsl +EOF +) +fakeroot bash -c "${trim}" popd || exit 1 rm archlinux.tar diff --git a/configure.sh b/configure.sh index 0bb2d7f..c64c24a 100644 --- a/configure.sh +++ b/configure.sh @@ -6,14 +6,18 @@ set -eu # Apply systemd recommendations # https://learn.microsoft.com/en-us/windows/wsl/build-custom-distro#systemd-recommendations -/bin/systemctl mask systemd-resolved.service -/bin/systemctl mask systemd-networkd.service -/bin/systemctl mask systemd-tmpfiles-setup.service -/bin/systemctl mask systemd-tmpfiles-clean.service -/bin/systemctl mask systemd-tmpfiles-clean.timer -/bin/systemctl mask systemd-tmpfiles-setup-dev-early.service -/bin/systemctl mask systemd-tmpfiles-setup-dev.service -/bin/systemctl mask tmp.mount +systemctl mask systemd-resolved.service +systemctl mask systemd-networkd.service +systemctl mask systemd-tmpfiles-setup.service +systemctl mask systemd-tmpfiles-clean.service +systemctl mask systemd-tmpfiles-clean.timer +systemctl mask systemd-tmpfiles-setup-dev-early.service +systemctl mask systemd-tmpfiles-setup-dev.service +systemctl mask tmp.mount + +systemctl mask --global systemd-tmpfiles-setup.service +systemctl mask --global systemd-tmpfiles-clean.service +systemctl mask --global systemd-tmpfiles-clean.timer # Enable pacman progress bar and remove NoExtract options. # https://gitlab.archlinux.org/archlinux/archlinux-docker/-/blob/master/scripts/make-rootfs.sh?ref_type=heads#L17 diff --git a/root/etc/oobe.sh b/root/etc/oobe.sh deleted file mode 100644 index 7de7b03..0000000 --- a/root/etc/oobe.sh +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/bash -# -# Out of box experience script - -set -ue - -# https://man.archlinux.org/man/machine-id.5.en -/bin/systemd-machine-id-setup --commit -# https://wiki.archlinux.org/title/Reflector -/bin/systemctl enable reflector.timer -# https://learn.microsoft.com/azure/virtual-machines/linux/time-sync#chrony -/bin/systemctl enable chronyd.service - -# Initialize and populate the pacman keyring -# https://wiki.archlinux.org/title/Pacman/Package_signing#Initializing_the_keyring -/bin/pacman-key --init -/bin/pacman-key --populate archlinux -/bin/pacman -S --noconfirm --needed archlinux-keyring - -DEFAULT_UID='1000' - -echo 'Please create a default UNIX user account. The username does not need to match your Windows username.' -echo 'For more information visit: https://aka.ms/wslusers' - -if getent passwd "${DEFAULT_UID}" >/dev/null; then - echo 'User account already exists, skipping creation' - exit 0 -fi - -while true; do - # Prompt for the username - read -rp 'Enter new UNIX username: ' username - - # Create the user - if /bin/useradd --uid "${DEFAULT_UID}" --create-home --user-group --groups wheel "${username}"; then - break - else - /bin/userdel "${username}" - fi -done - -while ! /bin/passwd "${username}"; do - : -done - -# Apply systemd recommendations -# http://learn.microsoft.com/windows/wsl/build-custom-distro#systemd-recommendations -su -c "mkdir -p \"\${HOME}/.config/systemd/user\"" - "${username}" -su -c "ln -s /dev/null \"\${HOME}/.config/systemd/user/systemd-tmpfiles-clean.service\"" - "${username}" -su -c "ln -s /dev/null \"\${HOME}/.config/systemd/user/systemd-tmpfiles-clean.timer\"" - "${username}" -su -c "ln -s /dev/null \"\${HOME}/.config/systemd/user/systemd-tmpfiles-setup.service\"" - "${username}" diff --git a/root/etc/wsl-distribution.conf b/root/etc/wsl-distribution.conf index c7ed69b..50719fe 100644 --- a/root/etc/wsl-distribution.conf +++ b/root/etc/wsl-distribution.conf @@ -1,7 +1,7 @@ # /etc/wsl-distribution.conf [oobe] -command = /etc/oobe.sh +command = /usr/lib/wsl/oobe.sh defaultUid = 1000 defaultName = Arch-Linux-Unofficial diff --git a/root/usr/lib/wsl/oobe.sh b/root/usr/lib/wsl/oobe.sh new file mode 100644 index 0000000..689db0c --- /dev/null +++ b/root/usr/lib/wsl/oobe.sh @@ -0,0 +1,56 @@ +#!/bin/bash +# +# Out of box experience script + +set -ue + +DEFAULT_UID='1000' + +echo 'Please create a default UNIX user account. The username does not need to match your Windows username.' +echo 'For more information visit: https://aka.ms/wslusers' + +if getent passwd "${DEFAULT_UID}" >/dev/null; then + echo 'User account already exists, skipping creation' + exit 0 +fi + +# https://man.archlinux.org/man/machine-id.5 +systemd-machine-id-setup --commit +# https://wiki.archlinux.org/title/Reflector +systemctl enable reflector.timer +# https://learn.microsoft.com/azure/virtual-machines/linux/time-sync#chrony +systemctl enable chronyd.service + +# Initialize and populate the pacman keyring +# https://wiki.archlinux.org/title/Pacman/Package_signing#Initializing_the_keyring +pacman-key --init +pacman-key --populate archlinux +pacman -S --noconfirm --needed archlinux-keyring + +while true; do + # Prompt for the username + read -rp 'Enter new UNIX username: ' username + + # Create the user + if useradd --uid "${DEFAULT_UID}" --create-home --user-group --groups wheel "${username}"; then + while ! passwd "${username}"; do + while true; do + read -rp 'Try again? [y/N] ' try_again + case "${try_again}" in + [yY]) + continue 2 + ;; + "" | [nN]) + break 2 + ;; + *) + continue + ;; + esac + done + done + break + else + userdel "${username}" + fi +done