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

Commit 035a8cb

Browse files
committed
fix: mask recommended systemd services (#4)
1 parent ab26c08 commit 035a8cb

File tree

8 files changed

+69
-17
lines changed

8 files changed

+69
-17
lines changed

.github/workflows/release.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ jobs:
1717
run: |
1818
imagetag=$(cat artifacts/imagetag.txt)
1919
tag="${imagetag#base-}"
20-
gh release create "${tag}" --notes "Arch Linux WSL modern distribution based on the Docker image \`archlinux:${imagetag}\`" ./artifacts/archlinux.wsl.gz ./artifacts/DistributionInfo.json
20+
gh release create "${tag}" \
21+
--notes "Arch Linux WSL modern distribution based on the Docker image \`archlinux:${imagetag}\`" \
22+
./artifacts/archlinux.wsl \
23+
./artifacts/DistributionInfo.json
2124
env:
2225
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/reusable-package.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ jobs:
1818
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
1919
run: |
2020
./build
21-
gzip --best archlinux.wsl
22-
sha256=$(sha256sum archlinux.wsl.gz)
21+
sha256=$(sha256sum archlinux.wsl)
2322
read -r sha256 _ <<<"${sha256}"
2423
tag=$(cat imagetag.txt)
2524
version="${tag#base-}"
@@ -32,7 +31,7 @@ jobs:
3231
"Default": true,
3332
"FriendlyName": "Arch Linux Unofficial version ${version} (latest)",
3433
"Amd64Url": {
35-
"Url": "https://github.com/DevelopersCommunity/archlinux-wsl/releases/download/${version}/archlinux.wsl.gz",
34+
"Url": "https://github.com/DevelopersCommunity/archlinux-wsl/releases/download/${version}/archlinux.wsl",
3635
"Sha256": "${sha256}"
3736
}
3837
}
@@ -45,7 +44,7 @@ jobs:
4544
with:
4645
name: artifacts
4746
path: |
48-
archlinux.wsl.gz
47+
archlinux.wsl
4948
imagetag.txt
5049
DistributionInfo.json
5150
if-no-files-found: error

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
/DistributionInfo.json
44
/imagetag.txt
55
/root/usr/lib/wsl/terminal-profile.json
6+
/rootfs/

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
FROM archlinux:base
22

3+
# Apply configuration files recommendations
4+
# https://learn.microsoft.com/windows/wsl/build-custom-distro#configuration-file-recommendations
35
COPY --chown=root:root --chmod=0644 root/etc/wsl.conf root/etc/wsl-distribution.conf /etc/
46
COPY --chown=root:root --chmod=0755 root/etc/oobe.sh /etc/
57

README.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ distribution](https://learn.microsoft.com/windows/wsl/build-custom-distro).
66

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

1212
## Requirements
1313

1414
You need [WSL release 2.4.4 or higher](https://github.com/microsoft/WSL/releases)
15-
to use this installation method. To install a pre-release version of WSL, run the
16-
following command:
15+
to use this installation method. To install a pre-release version of WSL, run
16+
the following command:
1717

1818
```powershell
1919
wsl --update --pre-release
@@ -31,6 +31,7 @@ token](https://docs.docker.com/security/for-developers/access-tokens/)
3131
- [Node.js](https://nodejs.org/)
3232
- [jq](https://jqlang.github.io/jq/)
3333
- [grep](https://www.gnu.org/software/grep/)
34+
- [fakeroot](https://man.archlinux.org/man/fakeroot.1)
3435

3536
## Build
3637

@@ -68,6 +69,15 @@ $ systemctl
6869
Failed to connect to system scope bus via local transport: No such file or directory
6970
```
7071

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 [email protected]
79+
```
80+
7181
## Arch Linux trademark
7282

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

build

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
#!/bin/bash
22
#
3-
# Build WSL tar image
3+
# Build an Arch Linux WSL tar image
44

55
set -eu
66

7-
[[ -f .env ]] && source .env
8-
7+
# Generate a Windows Terminal profile
8+
# https://learn.microsoft.com/windows/wsl/build-custom-distro#generate-a-windows-terminal-profile
99
pushd terminal-profile || exit 1
1010
npm install
1111
node index.js >../root/usr/lib/wsl/terminal-profile.json
1212
popd || exit 1
1313

14+
# Create an Arch Linux image based on its latest base Docker image
15+
[[ -f .env ]] && source .env
16+
1417
token=$(curl \
1518
-d "{ \"username\": \"${DOCKER_HUB_USERNAME}\", \"password\": \"${DOCKER_HUB_PAT}\" }" \
1619
-H "Content-Type: application/json" \
@@ -34,9 +37,20 @@ echo "${tag}" >imagetag.txt
3437

3538
dockerfile=$(cat Dockerfile)
3639
dockerfile="${dockerfile/FROM archlinux:base/FROM archlinux:${tag}}"
40+
docker buildx build -t "archwsl:${tag}" -f - . <<<"${dockerfile}"
3741

38-
docker buildx build -t archwsl:latest -f - . <<<"${dockerfile}"
39-
40-
docker run -t --name wsl_export archwsl:latest ls /
41-
docker export wsl_export >archlinux.wsl
42+
# Export the tar from the container
43+
# https://learn.microsoft.com/windows/wsl/use-custom-distro#export-the-tar-from-a-container
44+
docker run -t --name wsl_export "archwsl:${tag}" ls /
45+
docker export wsl_export >archlinux.tar
4246
docker rm wsl_export
47+
docker rmi "archwsl:${tag}"
48+
49+
# Apply configuration file recommendations
50+
# https://learn.microsoft.com/windows/wsl/build-custom-distro#configuration-file-recommendations
51+
[[ -d rootfs ]] && rm -rf rootfs
52+
mkdir rootfs
53+
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"
55+
popd || exit 1
56+
rm archlinux.tar

configure.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@
44

55
set -eu
66

7+
# Apply systemd recommendations
8+
# 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
17+
718
# Enable pacman progress bar and remove NoExtract options.
819
# https://gitlab.archlinux.org/archlinux/archlinux-docker/-/blob/master/scripts/make-rootfs.sh?ref_type=heads#L17
920
pacman=$(cat /etc/pacman.conf)

root/etc/oobe.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@
44

55
set -ue
66

7-
/bin/dbus-uuidgen --ensure=/etc/machine-id
7+
# https://man.archlinux.org/man/machine-id.5.en
8+
/bin/systemd-machine-id-setup --commit
9+
# https://wiki.archlinux.org/title/Reflector
810
/bin/systemctl enable reflector.timer
11+
# https://learn.microsoft.com/azure/virtual-machines/linux/time-sync#chrony
912
/bin/systemctl enable chronyd.service
1013

14+
# Initialize and populate the pacman keyring
15+
# https://wiki.archlinux.org/title/Pacman/Package_signing#Initializing_the_keyring
1116
/bin/pacman-key --init
1217
/bin/pacman-key --populate archlinux
1318
/bin/pacman -S --noconfirm --needed archlinux-keyring
@@ -37,3 +42,10 @@ done
3742
while ! /bin/passwd "${username}"; do
3843
:
3944
done
45+
46+
# Apply systemd recommendations
47+
# http://learn.microsoft.com/windows/wsl/build-custom-distro#systemd-recommendations
48+
su -c "mkdir -p \"\${HOME}/.config/systemd/user\"" - "${username}"
49+
su -c "ln -s /dev/null \"\${HOME}/.config/systemd/user/systemd-tmpfiles-clean.service\"" - "${username}"
50+
su -c "ln -s /dev/null \"\${HOME}/.config/systemd/user/systemd-tmpfiles-clean.timer\"" - "${username}"
51+
su -c "ln -s /dev/null \"\${HOME}/.config/systemd/user/systemd-tmpfiles-setup.service\"" - "${username}"

0 commit comments

Comments
 (0)