Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit a0f0011

Browse files
authored
fix: properly mask systemd user services (#5)
1 parent 035a8cb commit a0f0011

File tree

10 files changed

+103
-107
lines changed

10 files changed

+103
-107
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
tag="${imagetag#base-}"
2020
gh release create "${tag}" \
2121
--notes "Arch Linux WSL modern distribution based on the Docker image \`archlinux:${imagetag}\`" \
22-
./artifacts/archlinux.wsl \
22+
./artifacts/archlinux-${imagetag}.wsl \
2323
./artifacts/DistributionInfo.json
2424
env:
2525
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/reusable-package.yml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,27 @@ jobs:
2424
version="${tag#base-}"
2525
cat <<EOF >DistributionInfo.json
2626
{
27-
"ModernDistributions": {
28-
"Arch-Linux-Unofficial": [
29-
{
30-
"Name": "Arch-Linux-Unofficial-${tag}",
31-
"Default": true,
32-
"FriendlyName": "Arch Linux Unofficial version ${version} (latest)",
33-
"Amd64Url": {
34-
"Url": "https://github.com/DevelopersCommunity/archlinux-wsl/releases/download/${version}/archlinux.wsl",
35-
"Sha256": "${sha256}"
36-
}
37-
}
38-
]
39-
}
27+
"ModernDistributions": {
28+
"Arch-Linux-Unofficial": [
29+
{
30+
"Name": "Arch-Linux-Unofficial",
31+
"Default": true,
32+
"FriendlyName": "Arch Linux Unofficial Rolling Release",
33+
"Amd64Url": {
34+
"Url": "https://github.com/DevelopersCommunity/archlinux-wsl/releases/download/${version}/archlinux-${tag}.wsl",
35+
"Sha256": "${sha256}"
36+
}
37+
}
38+
]
39+
}
4040
}
4141
EOF
4242
- name: Upload artifacts
4343
uses: actions/upload-artifact@v4
4444
with:
4545
name: artifacts
4646
path: |
47-
archlinux.wsl
47+
archlinux-*.wsl
4848
imagetag.txt
4949
DistributionInfo.json
5050
if-no-files-found: error

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/.env
2-
/archlinux.wsl
2+
/archlinux-*.wsl
33
/DistributionInfo.json
44
/imagetag.txt
55
/root/usr/lib/wsl/terminal-profile.json

Dockerfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ FROM archlinux:base
33
# Apply configuration files recommendations
44
# https://learn.microsoft.com/windows/wsl/build-custom-distro#configuration-file-recommendations
55
COPY --chown=root:root --chmod=0644 root/etc/wsl.conf root/etc/wsl-distribution.conf /etc/
6-
COPY --chown=root:root --chmod=0755 root/etc/oobe.sh /etc/
7-
8-
COPY root/usr/lib/wsl/* /usr/lib/wsl/
6+
COPY --chown=root:root --chmod=0755 root/usr/lib/wsl/oobe.sh /usr/lib/wsl/
7+
COPY root/usr/lib/wsl/archlinux.ico root/usr/lib/wsl/terminal-profile.json /usr/lib/wsl/
98

109
COPY --chmod=0755 configure.sh ./configure.sh
1110
RUN ./configure.sh && rm ./configure.sh

README.md

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ This is an automated script to create an [Arch Linux](https://archlinux.org)
55
distribution](https://learn.microsoft.com/windows/wsl/build-custom-distro).
66

77
You can download a pre-built version from the [releases
8-
page](https://github.com/DevelopersCommunity/archlinux-wsl/releases/latest).
9-
Get the `archlinux.wsl` file and double-click it in `File Explorer` to
10-
install the distribution.
8+
page](https://github.com/DevelopersCommunity/archlinux-wsl/releases/latest). Get
9+
the `.wsl` file and double-click it in `File Explorer` to install the
10+
distribution.
1111

1212
## Requirements
1313

@@ -54,30 +54,6 @@ the [Arch Linux logo](https://archlinux.org/art/) blue color. The script to
5454
generate the profile is available in the [`terminal-profile`
5555
directory](./terminal-profile/).
5656

57-
## Known issues
58-
59-
### systemd services won't start
60-
61-
If you get the following error when running the `systemctl` command, try to
62-
[install another WSL distribution with `systemd`
63-
support](https://aka.ms/wslsystemd/) and check if it works. In my case,
64-
`systemd` started working on Arch Linux after that, and kept working even after
65-
uninstalling the other distro.
66-
67-
```terminal
68-
$ systemctl
69-
Failed to connect to system scope bus via local transport: No such file or directory
70-
```
71-
72-
If you still have problems after installing another distribution, try to run the
73-
following
74-
[command](https://github.com/microsoft/WSL/issues/10205#issuecomment-1601620093)
75-
in a `PowerShell` terminal:
76-
77-
```powershell
78-
wsl -d Arch-Linux-Unofficial -u root -e systemctl restart user@1000.service
79-
```
80-
8157
## Arch Linux trademark
8258

8359
The logo used in this distribution was taken from the [Arch Linux logos and

build

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ docker rmi "archwsl:${tag}"
5151
[[ -d rootfs ]] && rm -rf rootfs
5252
mkdir rootfs
5353
pushd rootfs || exit 1
54-
fakeroot bash -c "tar -xf ../archlinux.tar && rm -f etc/resolv.conf && tar --numeric-owner --absolute-names -c -- * | gzip --best >../archlinux.wsl"
54+
trim=$(
55+
cat <<EOF
56+
tar -xf ../archlinux.tar &&
57+
rm -f etc/resolv.conf &&
58+
rm -f .dockerenv &&
59+
rm -rf boot &&
60+
rm -rf dev &&
61+
rm -rf run &&
62+
tar --numeric-owner --absolute-names -c -- * |
63+
gzip --best >../archlinux-${tag}.wsl
64+
EOF
65+
)
66+
fakeroot bash -c "${trim}"
5567
popd || exit 1
5668
rm archlinux.tar

configure.sh

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@ set -eu
66

77
# Apply systemd recommendations
88
# https://learn.microsoft.com/en-us/windows/wsl/build-custom-distro#systemd-recommendations
9-
/bin/systemctl mask systemd-resolved.service
10-
/bin/systemctl mask systemd-networkd.service
11-
/bin/systemctl mask systemd-tmpfiles-setup.service
12-
/bin/systemctl mask systemd-tmpfiles-clean.service
13-
/bin/systemctl mask systemd-tmpfiles-clean.timer
14-
/bin/systemctl mask systemd-tmpfiles-setup-dev-early.service
15-
/bin/systemctl mask systemd-tmpfiles-setup-dev.service
16-
/bin/systemctl mask tmp.mount
9+
systemctl mask systemd-resolved.service
10+
systemctl mask systemd-networkd.service
11+
systemctl mask systemd-tmpfiles-setup.service
12+
systemctl mask systemd-tmpfiles-clean.service
13+
systemctl mask systemd-tmpfiles-clean.timer
14+
systemctl mask systemd-tmpfiles-setup-dev-early.service
15+
systemctl mask systemd-tmpfiles-setup-dev.service
16+
systemctl mask tmp.mount
17+
18+
systemctl mask --global systemd-tmpfiles-setup.service
19+
systemctl mask --global systemd-tmpfiles-clean.service
20+
systemctl mask --global systemd-tmpfiles-clean.timer
1721

1822
# Enable pacman progress bar and remove NoExtract options.
1923
# https://gitlab.archlinux.org/archlinux/archlinux-docker/-/blob/master/scripts/make-rootfs.sh?ref_type=heads#L17

root/etc/oobe.sh

Lines changed: 0 additions & 51 deletions
This file was deleted.

root/etc/wsl-distribution.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# /etc/wsl-distribution.conf
22

33
[oobe]
4-
command = /etc/oobe.sh
4+
command = /usr/lib/wsl/oobe.sh
55
defaultUid = 1000
66
defaultName = Arch-Linux-Unofficial
77

root/usr/lib/wsl/oobe.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
#
3+
# Out of box experience script
4+
5+
set -ue
6+
7+
DEFAULT_UID='1000'
8+
9+
echo 'Please create a default UNIX user account. The username does not need to match your Windows username.'
10+
echo 'For more information visit: https://aka.ms/wslusers'
11+
12+
if getent passwd "${DEFAULT_UID}" >/dev/null; then
13+
echo 'User account already exists, skipping creation'
14+
exit 0
15+
fi
16+
17+
# https://man.archlinux.org/man/machine-id.5
18+
systemd-machine-id-setup --commit
19+
# https://wiki.archlinux.org/title/Reflector
20+
systemctl enable reflector.timer
21+
# https://learn.microsoft.com/azure/virtual-machines/linux/time-sync#chrony
22+
systemctl enable chronyd.service
23+
24+
# Initialize and populate the pacman keyring
25+
# https://wiki.archlinux.org/title/Pacman/Package_signing#Initializing_the_keyring
26+
pacman-key --init
27+
pacman-key --populate archlinux
28+
pacman -S --noconfirm --needed archlinux-keyring
29+
30+
while true; do
31+
# Prompt for the username
32+
read -rp 'Enter new UNIX username: ' username
33+
34+
# Create the user
35+
if useradd --uid "${DEFAULT_UID}" --create-home --user-group --groups wheel "${username}"; then
36+
while ! passwd "${username}"; do
37+
while true; do
38+
read -rp 'Try again? [y/N] ' try_again
39+
case "${try_again}" in
40+
[yY])
41+
continue 2
42+
;;
43+
"" | [nN])
44+
break 2
45+
;;
46+
*)
47+
continue
48+
;;
49+
esac
50+
done
51+
done
52+
break
53+
else
54+
userdel "${username}"
55+
fi
56+
done

0 commit comments

Comments
 (0)