2 # SPDX-License-Identifier: LGPL-2.1-or-later
3 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
4 # ex: ts=8 sw=4 sts=4 et filetype=sh
5 # shellcheck disable=SC2233,SC2235,SC2016
9 # shellcheck source=test/units/util.sh
10 .
"$(dirname "$0")"/util.sh
12 systemd-dissect
--json=short
"$MINIMAL_IMAGE.raw" | \
13 grep -q -F '{"rw":"ro","designator":"root","partition_uuid":null,"partition_label":null,"fstype":"squashfs","architecture":null,"verity":"external"'
14 systemd-dissect
"$MINIMAL_IMAGE.raw" |
grep -q -F "MARKER=1"
15 # shellcheck disable=SC2153
16 systemd-dissect
"$MINIMAL_IMAGE.raw" |
grep -q -F -f <(sed 's/"//g' "$OS_RELEASE")
18 systemd-dissect
--list "$MINIMAL_IMAGE.raw" |
grep -q '^etc/os-release$'
19 systemd-dissect
--mtree "$MINIMAL_IMAGE.raw" --mtree-hash yes | \
20 grep -qe "^./usr/bin/cat type=file mode=0755 uid=0 gid=0 size=[0-9]* sha256sum=[a-z0-9]*$"
21 systemd-dissect
--mtree "$MINIMAL_IMAGE.raw" --mtree-hash no | \
22 grep -qe "^./usr/bin/cat type=file mode=0755 uid=0 gid=0 size=[0-9]*$"
24 read -r SHA256SUM1 _
< <(systemd-dissect
--copy-from "$MINIMAL_IMAGE.raw" etc
/os-release | sha256sum
)
25 test "$SHA256SUM1" != ""
26 read -r SHA256SUM2 _
< <(systemd-dissect
--read-only --with "$MINIMAL_IMAGE.raw" sha256sum etc
/os-release
)
27 test "$SHA256SUM2" != ""
28 test "$SHA256SUM1" = "$SHA256SUM2"
30 if systemctl
--version |
grep -qF -- "+LIBARCHIVE" ; then
31 # Make sure tarballs are reproducible
32 read -r SHA256SUM1 _
< <(systemd-dissect
--make-archive "$MINIMAL_IMAGE.raw" | sha256sum
)
33 test "$SHA256SUM1" != ""
34 read -r SHA256SUM2 _
< <(systemd-dissect
--make-archive "$MINIMAL_IMAGE.raw" | sha256sum
)
35 test "$SHA256SUM2" != ""
36 test "$SHA256SUM1" = "$SHA256SUM2"
37 # Also check that a file we expect to be there is there
38 systemd-dissect
--make-archive "$MINIMAL_IMAGE.raw" |
tar t |
grep etc
/os-release
41 mv "$MINIMAL_IMAGE.verity" "$MINIMAL_IMAGE.fooverity"
42 mv "$MINIMAL_IMAGE.roothash" "$MINIMAL_IMAGE.foohash"
43 systemd-dissect
"$MINIMAL_IMAGE.raw" \
45 --root-hash="$MINIMAL_IMAGE_ROOTHASH" \
46 --verity-data="$MINIMAL_IMAGE.fooverity" | \
47 grep -q -F '{"rw":"ro","designator":"root","partition_uuid":null,"partition_label":null,"fstype":"squashfs","architecture":null,"verity":"external"'
48 systemd-dissect
"$MINIMAL_IMAGE.raw" \
49 --root-hash="$MINIMAL_IMAGE_ROOTHASH" \
50 --verity-data="$MINIMAL_IMAGE.fooverity" | \
52 systemd-dissect
"$MINIMAL_IMAGE.raw" \
53 --root-hash="$MINIMAL_IMAGE_ROOTHASH" \
54 --verity-data="$MINIMAL_IMAGE.fooverity" | \
55 grep -q -F -f <(sed 's/"//g' "$OS_RELEASE")
56 mv "$MINIMAL_IMAGE.fooverity" "$MINIMAL_IMAGE.verity"
57 mv "$MINIMAL_IMAGE.foohash" "$MINIMAL_IMAGE.roothash"
59 mkdir
-p "$IMAGE_DIR/mount" "$IMAGE_DIR/mount2"
60 systemd-dissect
--mount "$MINIMAL_IMAGE.raw" "$IMAGE_DIR/mount"
61 grep -q -F -f "$OS_RELEASE" "$IMAGE_DIR/mount/usr/lib/os-release"
62 grep -q -F -f "$OS_RELEASE" "$IMAGE_DIR/mount/etc/os-release"
63 grep -q -F "MARKER=1" "$IMAGE_DIR/mount/usr/lib/os-release"
64 # Verity volume should be shared (opened only once)
65 systemd-dissect
--mount "$MINIMAL_IMAGE.raw" "$IMAGE_DIR/mount2"
66 verity_count
=$
(find /dev
/mapper
/ -name "*verity*" |
wc -l)
67 # In theory we should check that count is exactly one. In practice, libdevmapper
68 # randomly and unpredictably fails with an unhelpful EINVAL when a device is open
69 # (and even mounted and in use), so best-effort is the most we can do for now
70 if [[ "$verity_count" -lt 1 ]]; then
71 echo "Verity device $MINIMAL_IMAGE.raw not found in /dev/mapper/"
74 systemd-dissect
--umount "$IMAGE_DIR/mount"
75 systemd-dissect
--umount "$IMAGE_DIR/mount2"
77 # Test BindLogSockets=
78 systemd-run
--wait -p RootImage
="$MINIMAL_IMAGE.raw" mountpoint
/run
/systemd
/journal
/socket
79 (! systemd-run
--wait -p RootImage
="$MINIMAL_IMAGE.raw" -p BindLogSockets
=no
ls /run
/systemd
/journal
/socket
)
80 (! systemd-run
--wait -p RootImage
="$MINIMAL_IMAGE.raw" -p MountAPIVFS
=no
ls /run
/systemd
/journal
/socket
)
82 # Test that the notify socket is bind mounted to /run/host/notify in sandboxed environments and
83 # $NOTIFY_SOCKET is set correctly.
86 -p RootImage
="$MINIMAL_IMAGE.raw" \
90 [[ "$$NOTIFY_SOCKET" == "/run/host/notify" ]]
91 test -S /run/host/notify
93 if [[ "$(findmnt -n -o FSTYPE /)" == btrfs
]]; then
94 [[ -d /test-dissect-btrfs-snapshot
]] && btrfs subvolume delete
/test-dissect-btrfs-snapshot
95 btrfs subvolume snapshot
/ /test-dissect-btrfs-snapshot
97 # Same test with RootDirectory=, also try to send READY=1, as we can use systemd-notify.
100 -p RootDirectory
=/test-dissect-btrfs-snapshot \
101 -p NotifyAccess
=all \
102 --service-type=notify \
105 systemd-notify --pid=auto --ready
106 [[ "$$NOTIFY_SOCKET" == "/run/host/notify" ]]
107 test -S /run/host/notify
110 btrfs subvolume delete
/test-dissect-btrfs-snapshot
113 systemd-run
-P -p RootImage
="$MINIMAL_IMAGE.raw" cat /usr
/lib
/os-release |
grep -q -F "MARKER=1"
114 mv "$MINIMAL_IMAGE.verity" "$MINIMAL_IMAGE.fooverity"
115 mv "$MINIMAL_IMAGE.roothash" "$MINIMAL_IMAGE.foohash"
117 -p RootImage
="$MINIMAL_IMAGE.raw" \
118 -p RootHash
="$MINIMAL_IMAGE.foohash" \
119 -p RootVerity
="$MINIMAL_IMAGE.fooverity" \
120 -p BindLogSockets
=yes \
121 cat /usr
/lib
/os-release |
grep -q -F "MARKER=1"
122 # Let's use the long option name just here as a test
124 --property RootImage
="$MINIMAL_IMAGE.raw" \
125 --property RootHash
="$MINIMAL_IMAGE_ROOTHASH" \
126 --property RootVerity
="$MINIMAL_IMAGE.fooverity" \
127 cat /usr
/lib
/os-release |
grep -q -F "MARKER=1"
128 mv "$MINIMAL_IMAGE.fooverity" "$MINIMAL_IMAGE.verity"
129 mv "$MINIMAL_IMAGE.foohash" "$MINIMAL_IMAGE.roothash"
131 # Derive partition UUIDs from root hash, in UUID syntax
132 ROOT_UUID
="$(systemd-id128 -u show "$
(head -c 32 "$MINIMAL_IMAGE.roothash")" -u | tail -n 1 | cut -b 6-)"
133 VERITY_UUID
="$(systemd-id128 -u show "$
(tail -c 32 "$MINIMAL_IMAGE.roothash")" -u | tail -n 1 | cut -b 6-)"
135 systemd-dissect
--json=short \
136 --root-hash "$MINIMAL_IMAGE_ROOTHASH" \
137 "$MINIMAL_IMAGE.gpt" | \
138 grep -q '{"rw":"ro","designator":"root","partition_uuid":"'"$ROOT_UUID"'","partition_label":"Root Partition","fstype":"squashfs","architecture":"'"$ARCHITECTURE"'","verity":"signed",'
139 systemd-dissect
--json=short \
140 --root-hash "$MINIMAL_IMAGE_ROOTHASH" \
141 "$MINIMAL_IMAGE.gpt" | \
142 grep -q '{"rw":"ro","designator":"root-verity","partition_uuid":"'"$VERITY_UUID"'","partition_label":"Verity Partition","fstype":"DM_verity_hash","architecture":"'"$ARCHITECTURE"'","verity":null,'
143 if [[ -n "${OPENSSL_CONFIG:-}" ]]; then
144 systemd-dissect
--json=short \
145 --root-hash "$MINIMAL_IMAGE_ROOTHASH" \
146 "$MINIMAL_IMAGE.gpt" | \
147 grep -qE '{"rw":"ro","designator":"root-verity-sig","partition_uuid":"'".*"'","partition_label":"Signature Partition","fstype":"verity_hash_signature","architecture":"'"$ARCHITECTURE"'","verity":null,'
149 systemd-dissect
--root-hash "$MINIMAL_IMAGE_ROOTHASH" "$MINIMAL_IMAGE.gpt" |
grep -q -F "MARKER=1"
150 systemd-dissect
--root-hash "$MINIMAL_IMAGE_ROOTHASH" "$MINIMAL_IMAGE.gpt" |
grep -q -F -f <(sed 's/"//g' "$OS_RELEASE")
152 # Test image policies
153 systemd-dissect
--validate "$MINIMAL_IMAGE.gpt"
154 systemd-dissect
--validate "$MINIMAL_IMAGE.gpt" --image-policy='*'
155 (! systemd-dissect
--validate "$MINIMAL_IMAGE.gpt" --image-policy='~')
156 (! systemd-dissect
--validate "$MINIMAL_IMAGE.gpt" --image-policy='-')
157 (! systemd-dissect
--validate "$MINIMAL_IMAGE.gpt" --image-policy=root
=absent
)
158 (! systemd-dissect
--validate "$MINIMAL_IMAGE.gpt" --image-policy=swap
=unprotected
+encrypted
+verity
)
159 systemd-dissect
--validate "$MINIMAL_IMAGE.gpt" --image-policy=root
=unprotected
160 systemd-dissect
--validate "$MINIMAL_IMAGE.gpt" --image-policy=root
=verity
161 systemd-dissect
--validate "$MINIMAL_IMAGE.gpt" --image-policy=root
=verity
:root-verity-sig
=unused
+absent
162 systemd-dissect
--validate "$MINIMAL_IMAGE.gpt" --image-policy=root
=verity
:swap
=absent
163 systemd-dissect
--validate "$MINIMAL_IMAGE.gpt" --image-policy=root
=verity
:swap
=absent
+unprotected
164 (! systemd-dissect
--validate "$MINIMAL_IMAGE.gpt" --image-policy=root
=verity
:root-verity
=unused
+absent
)
165 systemd-dissect
--validate "$MINIMAL_IMAGE.gpt" --image-policy=root
=signed
166 (! systemd-dissect
--validate "$MINIMAL_IMAGE.gpt" --image-policy=root
=signed
:root-verity-sig
=unused
+absent
)
167 (! systemd-dissect
--validate "$MINIMAL_IMAGE.gpt" --image-policy=root
=signed
:root-verity
=unused
+absent
)
169 # Test RootImagePolicy= unit file setting
170 systemd-run
--wait -P \
171 -p RootImage
="$MINIMAL_IMAGE.gpt" \
172 -p RootHash
="$MINIMAL_IMAGE_ROOTHASH" \
174 cat /usr
/lib
/os-release |
grep -q -F "MARKER=1"
175 systemd-run
--wait -P \
176 -p RootImage
="$MINIMAL_IMAGE.gpt" \
177 -p RootHash
="$MINIMAL_IMAGE_ROOTHASH" \
178 -p RootImagePolicy
='*' \
180 cat /usr
/lib
/os-release |
grep -q -F "MARKER=1"
181 (! systemd-run
--wait -P \
182 -p RootImage
="$MINIMAL_IMAGE.gpt" \
183 -p RootHash
="$MINIMAL_IMAGE_ROOTHASH" \
184 -p RootImagePolicy
='~' \
186 cat /usr
/lib
/os-release |
grep -q -F "MARKER=1")
187 (! systemd-run
--wait -P \
188 -p RootImage
="$MINIMAL_IMAGE.gpt" \
189 -p RootHash
="$MINIMAL_IMAGE_ROOTHASH" \
190 -p RootImagePolicy
='-' \
192 cat /usr
/lib
/os-release |
grep -q -F "MARKER=1")
193 (! systemd-run
--wait -P \
194 -p RootImage
="$MINIMAL_IMAGE.gpt" \
195 -p RootHash
="$MINIMAL_IMAGE_ROOTHASH" \
196 -p RootImagePolicy
='root=absent' \
198 cat /usr
/lib
/os-release |
grep -q -F "MARKER=1")
199 systemd-run
--wait -P \
200 -p RootImage
="$MINIMAL_IMAGE.gpt" \
201 -p RootHash
="$MINIMAL_IMAGE_ROOTHASH" \
202 -p RootImagePolicy
='root=verity' \
204 cat /usr
/lib
/os-release |
grep -q -F "MARKER=1"
205 systemd-run
--wait -P \
206 -p RootImage
="$MINIMAL_IMAGE.gpt" \
207 -p RootHash
="$MINIMAL_IMAGE_ROOTHASH" \
208 -p RootImagePolicy
='root=signed' \
210 cat /usr
/lib
/os-release |
grep -q -F "MARKER=1"
211 (! systemd-run
--wait -P \
212 -p RootImage
="$MINIMAL_IMAGE.gpt" \
213 -p RootHash
="$MINIMAL_IMAGE_ROOTHASH" \
214 -p RootImagePolicy
='root=encrypted' \
216 cat /usr
/lib
/os-release |
grep -q -F "MARKER=1")
218 systemd-dissect
--root-hash "$MINIMAL_IMAGE_ROOTHASH" --mount "$MINIMAL_IMAGE.gpt" "$IMAGE_DIR/mount"
219 grep -q -F -f "$OS_RELEASE" "$IMAGE_DIR/mount/usr/lib/os-release"
220 grep -q -F -f "$OS_RELEASE" "$IMAGE_DIR/mount/etc/os-release"
221 grep -q -F "MARKER=1" "$IMAGE_DIR/mount/usr/lib/os-release"
222 systemd-dissect
--umount "$IMAGE_DIR/mount"
224 systemd-dissect
--root-hash "$MINIMAL_IMAGE_ROOTHASH" --mount "$MINIMAL_IMAGE.gpt" --in-memory "$IMAGE_DIR/mount"
225 grep -q -F -f "$OS_RELEASE" "$IMAGE_DIR/mount/usr/lib/os-release"
226 grep -q -F -f "$OS_RELEASE" "$IMAGE_DIR/mount/etc/os-release"
227 grep -q -F "MARKER=1" "$IMAGE_DIR/mount/usr/lib/os-release"
228 systemd-dissect
--umount "$IMAGE_DIR/mount"
230 # add explicit -p MountAPIVFS=yes once to test the parser
232 -p RootImage
="$MINIMAL_IMAGE.gpt" \
233 -p RootHash
="$MINIMAL_IMAGE_ROOTHASH" \
235 cat /usr
/lib
/os-release |
grep -q -F "MARKER=1"
237 -p RootImage
="$MINIMAL_IMAGE.raw" \
238 -p RootImageOptions
="root:nosuid,dev home:ro,dev ro,noatime" \
239 mount |
grep -F "squashfs" |
grep -q -F "nosuid"
241 -p RootImage
="$MINIMAL_IMAGE.gpt" \
242 -p RootImageOptions
="root:ro,noatime root:ro,dev" \
243 mount |
grep -F "squashfs" |
grep -q -F "noatime"
245 mkdir
-p "$IMAGE_DIR/result"
246 cat >/run
/systemd
/system
/testservice-50a.service
<<EOF
249 ExecStart=bash -c "mount >/run/result/a"
250 BindPaths=$IMAGE_DIR/result:/run/result
251 TemporaryFileSystem=/run
252 RootImage=$MINIMAL_IMAGE.raw
253 RootImageOptions=root:ro,noatime home:ro,dev relatime,dev
254 RootImageOptions=nosuid,dev
256 systemctl start testservice-50a.service
257 grep -F "squashfs" "$IMAGE_DIR/result/a" |
grep -q -F "noatime"
258 grep -F "squashfs" "$IMAGE_DIR/result/a" |
grep -q -F -v "nosuid"
260 cat >/run
/systemd
/system
/testservice-50b.service
<<EOF
263 ExecStart=bash -c "mount >/run/result/b"
264 BindPaths=$IMAGE_DIR/result:/run/result
265 TemporaryFileSystem=/run
266 RootImage=$MINIMAL_IMAGE.gpt
267 RootImageOptions=root:ro,noatime,nosuid home:ro,dev nosuid,dev
268 RootImageOptions=home:ro,dev nosuid,dev,%%foo
269 # this is the default, but let's specify once to test the parser
272 systemctl start testservice-50b.service
273 grep -F "squashfs" "$IMAGE_DIR/result/b" |
grep -q -F "noatime"
275 # Check that specifier escape is applied %%foo → %foo
276 busctl get-property org.freedesktop.systemd1 \
277 /org
/freedesktop
/systemd
1/unit
/testservice_2d50b_2eservice \
278 org.freedesktop.systemd1.Service RootImageOptions |
grep -F "nosuid,dev,%foo"
280 # Now do some checks with MountImages, both by itself, with options and in combination with RootImage, and as single FS or GPT image
282 -p MountImages
="$MINIMAL_IMAGE.gpt:/run/img1 $MINIMAL_IMAGE.raw:/run/img2" \
283 cat /run
/img
1/usr
/lib
/os-release |
grep -q -F "MARKER=1"
285 -p MountImages
="$MINIMAL_IMAGE.gpt:/run/img1 $MINIMAL_IMAGE.raw:/run/img2" \
286 cat /run
/img
2/usr
/lib
/os-release |
grep -q -F "MARKER=1"
288 -p MountImages
="$MINIMAL_IMAGE.gpt:/run/img1 $MINIMAL_IMAGE.raw:/run/img2:nosuid,dev" \
289 mount |
grep -F "squashfs" |
grep -q -F "nosuid"
291 -p MountImages
="$MINIMAL_IMAGE.gpt:/run/img1:root:nosuid $MINIMAL_IMAGE.raw:/run/img2:home:suid" \
292 mount |
grep -F "squashfs" |
grep -q -F "nosuid"
294 -p MountImages
="$MINIMAL_IMAGE.raw:/run/img2\:3" \
295 cat /run
/img2
:3/usr
/lib
/os-release |
grep -q -F "MARKER=1"
297 -p MountImages
="$MINIMAL_IMAGE.raw:/run/img2\:3:nosuid" \
298 mount |
grep -F "squashfs" |
grep -q -F "nosuid"
300 -p TemporaryFileSystem
=/run \
301 -p RootImage
="$MINIMAL_IMAGE.raw" \
302 -p MountImages
="$MINIMAL_IMAGE.gpt:/run/img1 $MINIMAL_IMAGE.raw:/run/img2" \
303 cat /usr
/lib
/os-release |
grep -q -F "MARKER=1"
305 -p TemporaryFileSystem
=/run \
306 -p RootImage
="$MINIMAL_IMAGE.raw" \
307 -p MountImages
="$MINIMAL_IMAGE.gpt:/run/img1 $MINIMAL_IMAGE.raw:/run/img2" \
308 cat /run
/img
1/usr
/lib
/os-release |
grep -q -F "MARKER=1"
310 -p TemporaryFileSystem
=/run \
311 -p RootImage
="$MINIMAL_IMAGE.gpt" \
312 -p RootHash
="$MINIMAL_IMAGE_ROOTHASH" \
313 -p MountImages
="$MINIMAL_IMAGE.gpt:/run/img1 $MINIMAL_IMAGE.raw:/run/img2" \
314 cat /run
/img
2/usr
/lib
/os-release |
grep -q -F "MARKER=1"
316 -p MountImages
="$MINIMAL_IMAGE.raw:/run/img2" \
317 veritysetup status
"${MINIMAL_IMAGE_ROOTHASH}-verity" |
grep -q "${MINIMAL_IMAGE_ROOTHASH}"
318 cat >/run
/systemd
/system
/testservice-50c.service
<<EOF
321 TemporaryFileSystem=/run
322 RootImage=$MINIMAL_IMAGE.raw
323 MountImages=$MINIMAL_IMAGE.gpt:/run/img1:root:noatime:home:relatime
324 MountImages=$MINIMAL_IMAGE.raw:/run/img2\:3:nosuid
325 ExecStart=bash -c "cat /run/img1/usr/lib/os-release >/run/result/c"
326 ExecStart=bash -c "cat /run/img2:3/usr/lib/os-release >>/run/result/c"
327 ExecStart=bash -c "mount >>/run/result/c"
328 BindPaths=$IMAGE_DIR/result:/run/result
331 systemctl start testservice-50c.service
332 grep -q -F "MARKER=1" "$IMAGE_DIR/result/c"
333 grep -F "squashfs" "$IMAGE_DIR/result/c" |
grep -q -F "noatime"
334 grep -F "squashfs" "$IMAGE_DIR/result/c" |
grep -q -F -v "nosuid"
336 # Adding a new mounts at runtime works if the unit is in the active state,
337 # so use Type=notify to make sure there's no race condition in the test
338 cat >/run
/systemd
/system
/testservice-50d.service
<<EOF
346 systemd-notify --ready; \\
347 while [ ! -f /tmp/img/usr/lib/os-release ] || ! grep -q -F MARKER /tmp/img/usr/lib/os-release; do \\
351 mount | grep -F "on /tmp/img type squashfs" | grep -q -F "nosuid"; \\
354 systemctl start testservice-50d.service
356 # Mount twice to exercise mount-beneath (on kernel 6.5+, on older kernels it will just overmount)
357 mkdir
-p /tmp
/wrong
/foo
358 mksquashfs
/tmp
/wrong
/foo
/tmp
/wrong.raw
359 systemctl mount-image
--mkdir testservice-50d.service
/tmp
/wrong.raw
/tmp
/img
360 test "$(systemctl show -P SubState testservice-50d.service)" = "running"
361 systemctl mount-image
--mkdir testservice-50d.service
"$MINIMAL_IMAGE.raw" /tmp
/img root
:nosuid
362 # shellcheck disable=SC2016
363 timeout
30s bash
-xec 'while [[ $(systemctl show -P SubState testservice-50d.service) == running ]]; do sleep .2; done'
364 systemctl is-active testservice-50d.service
366 # ExtensionImages will set up an overlay
368 --property ExtensionImages
=/tmp
/app0.raw \
369 --property RootImage
="$MINIMAL_IMAGE.raw" \
370 cat /opt
/script0.sh |
grep -q -F "extension-release.app0"
372 --property ExtensionImages
=/tmp
/app0.raw \
373 --property RootImage
="$MINIMAL_IMAGE.raw" \
374 cat /usr
/lib
/systemd
/system
/some_file |
grep -q -F "MARKER=1"
376 --property ExtensionImages
="/tmp/app0.raw /tmp/app1.raw" \
377 --property RootImage
="$MINIMAL_IMAGE.raw" \
378 cat /opt
/script0.sh |
grep -q -F "extension-release.app0"
380 --property ExtensionImages
="/tmp/app0.raw /tmp/app1.raw" \
381 --property RootImage
="$MINIMAL_IMAGE.raw" \
382 cat /usr
/lib
/systemd
/system
/some_file |
grep -q -F "MARKER=1"
384 --property ExtensionImages
="/tmp/app0.raw /tmp/app1.raw" \
385 --property RootImage
="$MINIMAL_IMAGE.raw" \
386 cat /opt
/script1.sh |
grep -q -F "extension-release.app2"
388 --property ExtensionImages
="/tmp/app0.raw /tmp/app1.raw" \
389 --property RootImage
="$MINIMAL_IMAGE.raw" \
390 cat /usr
/lib
/systemd
/system
/other_file |
grep -q -F "MARKER=1"
392 --property ExtensionImages
=/tmp
/app-nodistro.raw \
393 --property RootImage
="$MINIMAL_IMAGE.raw" \
394 cat /usr
/lib
/systemd
/system
/some_file |
grep -q -F "MARKER=1"
396 --property ExtensionImages
=/etc
/service-scoped-test.raw \
397 --property RootImage
="$MINIMAL_IMAGE.raw" \
398 cat /etc
/systemd
/system
/some_file |
grep -q -F "MARKER_CONFEXT_123"
400 --property ExtensionImages
="/tmp/app0.raw /tmp/conf0.raw" \
401 veritysetup status
"$(cat /tmp/app0.roothash)-verity" |
grep -q "$(cat /tmp/app0.roothash)"
403 --property ExtensionImages
="/tmp/app0.raw /tmp/conf0.raw" \
404 veritysetup status
"$(cat /tmp/conf0.roothash)-verity" |
grep -q "$(cat /tmp/conf0.roothash)"
406 # Check that two identical verity images at different paths do not fail with -ELOOP from OverlayFS
408 cp /tmp
/app0.raw
/tmp
/loop
/app0.raw
409 veritysetup format
/tmp
/loop
/app0.raw
/tmp
/loop
/app0.verity
--root-hash-file /tmp
/loop
/app0.roothash
410 cp /tmp
/loop
/app0.raw
/tmp
/loop
/app0_copy.raw
411 cp /tmp
/loop
/app0.verity
/tmp
/loop
/app0_copy.verity
412 cp /tmp
/loop
/app0.roothash
/tmp
/loop
/app0_copy.roothash
414 --property ExtensionImages
=/tmp
/loop
/app0.raw \
415 --property ExtensionImages
=/tmp
/loop
/app0_copy.raw \
416 --property RootImage
="$MINIMAL_IMAGE.raw" \
417 "${BIND_LOG_SOCKETS[@]}" \
418 cat /opt
/script0.sh |
grep -q -F "extension-release.app0"
421 # Check that using a symlink to NAME-VERSION.raw works as long as the symlink has the correct name NAME.raw
422 mkdir
-p /tmp
/symlink-test
/
423 cp /tmp
/app-nodistro.raw
/tmp
/symlink-test
/app-nodistro-v1.raw
424 ln -fs /tmp
/symlink-test
/app-nodistro-v1.raw
/tmp
/symlink-test
/app-nodistro.raw
426 --property ExtensionImages
=/tmp
/symlink-test
/app-nodistro.raw \
427 --property RootImage
="$MINIMAL_IMAGE.raw" \
428 cat /usr
/lib
/systemd
/system
/some_file |
grep -q -F "MARKER=1"
430 # Symlink check again but for confext
431 mkdir
-p /etc
/symlink-test
/
432 cp /etc
/service-scoped-test.raw
/etc
/symlink-test
/service-scoped-test-v1.raw
433 ln -fs /etc
/symlink-test
/service-scoped-test-v1.raw
/etc
/symlink-test
/service-scoped-test.raw
435 --property ExtensionImages
=/etc
/symlink-test
/service-scoped-test.raw \
436 --property RootImage
="$MINIMAL_IMAGE.raw" \
437 cat /etc
/systemd
/system
/some_file |
grep -q -F "MARKER_CONFEXT_123"
438 # And again mixing sysext and confext
440 --property ExtensionImages
=/tmp
/symlink-test
/app-nodistro.raw \
441 --property ExtensionImages
=/etc
/symlink-test
/service-scoped-test.raw \
442 --property RootImage
="$MINIMAL_IMAGE.raw" \
443 cat /etc
/systemd
/system
/some_file |
grep -q -F "MARKER_CONFEXT_123"
445 --property ExtensionImages
=/tmp
/symlink-test
/app-nodistro.raw \
446 --property ExtensionImages
=/etc
/symlink-test
/service-scoped-test.raw \
447 --property RootImage
="$MINIMAL_IMAGE.raw" \
448 cat /usr
/lib
/systemd
/system
/some_file |
grep -q -F "MARKER=1"
450 cat >/run
/systemd
/system
/testservice-50e.service
<<EOF
453 TemporaryFileSystem=/run /var/lib
455 RootImage=$MINIMAL_IMAGE.raw
456 ExtensionImages=/tmp/app0.raw /tmp/app1.raw:nosuid
457 # Relevant only for sanitizer runs
458 UnsetEnvironment=LD_PRELOAD
459 ExecStart=bash -c '/opt/script0.sh | grep ID'
460 ExecStart=bash -c '/opt/script1.sh | grep ID'
464 systemctl start testservice-50e.service
465 systemctl is-active testservice-50e.service
467 # Check vpick support in ExtensionImages=
470 EMPTY_VDIR
="/tmp/$VBASE-empty.v"
471 NONEXISTENT_VDIR
="/tmp/$VBASE-nonexistent.v"
472 mkdir
"$VDIR" "$EMPTY_VDIR"
474 ln -s /tmp
/app0.raw
"$VDIR/${VBASE}_0.raw"
475 ln -s /tmp
/app1.raw
"$VDIR/${VBASE}_1.raw"
477 systemd-run
-P -p ExtensionImages
="$VDIR -$EMPTY_VDIR -$NONEXISTENT_VDIR" bash
-c '/opt/script1.sh | grep ID'
479 rm -rf "$VDIR" "$EMPTY_VDIR"
481 # ExtensionDirectories will set up an overlay
482 mkdir
-p "$IMAGE_DIR/app0" "$IMAGE_DIR/app1" "$IMAGE_DIR/app-nodistro" "$IMAGE_DIR/service-scoped-test"
484 --property ExtensionDirectories
="$IMAGE_DIR/nonexistent" \
485 --property RootImage
="$MINIMAL_IMAGE.raw" \
488 --property ExtensionDirectories
="$IMAGE_DIR/app0" \
489 --property RootImage
="$MINIMAL_IMAGE.raw" \
491 systemd-dissect
--mount /tmp
/app0.raw
"$IMAGE_DIR/app0"
492 systemd-dissect
--mount /tmp
/app1.raw
"$IMAGE_DIR/app1"
493 systemd-dissect
--mount /tmp
/app-nodistro.raw
"$IMAGE_DIR/app-nodistro"
494 systemd-dissect
--mount /etc
/service-scoped-test.raw
"$IMAGE_DIR/service-scoped-test"
496 --property ExtensionDirectories
="$IMAGE_DIR/app0" \
497 --property RootImage
="$MINIMAL_IMAGE.raw" \
498 cat /opt
/script0.sh |
grep -q -F "extension-release.app0"
500 --property ExtensionDirectories
="$IMAGE_DIR/app0" \
501 --property RootImage
="$MINIMAL_IMAGE.raw" \
502 cat /usr
/lib
/systemd
/system
/some_file |
grep -q -F "MARKER=1"
504 --property ExtensionDirectories
="$IMAGE_DIR/app0 $IMAGE_DIR/app1" \
505 --property RootImage
="$MINIMAL_IMAGE.raw" \
506 cat /opt
/script0.sh |
grep -q -F "extension-release.app0"
508 --property ExtensionDirectories
="$IMAGE_DIR/app0 $IMAGE_DIR/app1" \
509 --property RootImage
="$MINIMAL_IMAGE.raw" \
510 cat /usr
/lib
/systemd
/system
/some_file |
grep -q -F "MARKER=1"
512 --property ExtensionDirectories
="$IMAGE_DIR/app0 $IMAGE_DIR/app1" \
513 --property RootImage
="$MINIMAL_IMAGE.raw" \
514 cat /opt
/script1.sh |
grep -q -F "extension-release.app2"
516 --property ExtensionDirectories
="$IMAGE_DIR/app0 $IMAGE_DIR/app1" \
517 --property RootImage
="$MINIMAL_IMAGE.raw" \
518 cat /usr
/lib
/systemd
/system
/other_file |
grep -q -F "MARKER=1"
520 --property ExtensionDirectories
="$IMAGE_DIR/app-nodistro" \
521 --property RootImage
="$MINIMAL_IMAGE.raw" \
522 cat /usr
/lib
/systemd
/system
/some_file |
grep -q -F "MARKER=1"
524 --property ExtensionDirectories
="$IMAGE_DIR/service-scoped-test" \
525 --property RootImage
="$MINIMAL_IMAGE.raw" \
526 cat /etc
/systemd
/system
/some_file |
grep -q -F "MARKER_CONFEXT_123"
527 cat >/run
/systemd
/system
/testservice-50f.service
<<EOF
530 TemporaryFileSystem=/run /var/lib
532 RootImage=$MINIMAL_IMAGE.raw
533 ExtensionDirectories=$IMAGE_DIR/app0 $IMAGE_DIR/app1
534 # Relevant only for sanitizer runs
535 UnsetEnvironment=LD_PRELOAD
536 ExecStart=bash -c '/opt/script0.sh | grep ID'
537 ExecStart=bash -c '/opt/script1.sh | grep ID'
541 systemctl start testservice-50f.service
542 systemctl is-active testservice-50f.service
544 # Check vpick support in ExtensionDirectories=
547 EMPTY_VDIR
="/tmp/$VBASE-empty.v"
548 NONEXISTENT_VDIR
="/tmp/$VBASE-nonexistent.v"
549 mkdir
"$VDIR" "$EMPTY_VDIR"
551 ln -s "$IMAGE_DIR/app0" "$VDIR/${VBASE}_0"
552 ln -s "$IMAGE_DIR/app1" "$VDIR/${VBASE}_1"
554 systemd-run
-P --property ExtensionDirectories
="$VDIR -$EMPTY_VDIR -$NONEXISTENT_VDIR" cat /opt
/script1.sh |
grep -q -F "extension-release.app2"
556 rm -rf "$VDIR" "$EMPTY_VDIR"
558 systemd-dissect
--umount "$IMAGE_DIR/app0"
559 systemd-dissect
--umount "$IMAGE_DIR/app1"
561 # Test that an extension consisting of an empty directory under /etc/extensions/ takes precedence
562 mkdir
-p /var
/lib
/extensions
/
563 ln -s /tmp
/app-nodistro.raw
/var
/lib
/extensions
/app-nodistro.raw
565 grep -q -F "MARKER=1" /usr
/lib
/systemd
/system
/some_file
566 systemd-sysext unmerge
567 mkdir
-p /etc
/extensions
/app-nodistro
569 test ! -e /usr
/lib
/systemd
/system
/some_file
570 systemd-sysext unmerge
571 rmdir /etc
/extensions
/app-nodistro
573 # Similar, but go via varlink
574 varlinkctl call
--more /run
/systemd
/io.systemd.sysext io.systemd.sysext.List
'{}'
575 (! grep -q -F "MARKER=1" /usr
/lib
/systemd
/system
/some_file
)
576 varlinkctl call
/run
/systemd
/io.systemd.sysext io.systemd.sysext.Merge
'{}'
577 grep -q -F "MARKER=1" /usr
/lib
/systemd
/system
/some_file
578 varlinkctl call
/run
/systemd
/io.systemd.sysext io.systemd.sysext.Refresh
'{}'
579 grep -q -F "MARKER=1" /usr
/lib
/systemd
/system
/some_file
580 varlinkctl call
/run
/systemd
/io.systemd.sysext io.systemd.sysext.Unmerge
'{}'
581 (! grep -q -F "MARKER=1" /usr
/lib
/systemd
/system
/some_file
)
583 # Check that extensions cannot contain os-release
584 mkdir
-p /run
/extensions
/app-reject
/usr
/lib
/{extension-release.d
/,systemd
/system
}
585 echo "ID=_any" >/run
/extensions
/app-reject
/usr
/lib
/extension-release.d
/extension-release.app-reject
586 echo "ID=_any" >/run
/extensions
/app-reject
/usr
/lib
/os-release
587 touch /run
/extensions
/app-reject
/usr
/lib
/systemd
/system
/other_file
588 (! systemd-sysext merge
)
589 test ! -e /usr
/lib
/systemd
/system
/some_file
590 test ! -e /usr
/lib
/systemd
/system
/other_file
591 systemd-sysext unmerge
592 rm -rf /run
/extensions
/app-reject
593 rm /var
/lib
/extensions
/app-nodistro.raw
595 # Some super basic test that RootImage= works with .v/ dirs
600 ln -s "$MINIMAL_IMAGE.raw" "$VDIR/${VBASE}_33.raw"
601 ln -s "$MINIMAL_IMAGE.raw" "$VDIR/${VBASE}_34.raw"
602 ln -s "$MINIMAL_IMAGE.raw" "$VDIR/${VBASE}_35.raw"
604 systemd-run
-P -p RootImage
="$VDIR" cat /usr
/lib
/os-release |
grep -q -F "MARKER=1"
606 rm "$VDIR/${VBASE}_33.raw" "$VDIR/${VBASE}_34.raw" "$VDIR/${VBASE}_35.raw"
609 mkdir
-p /run
/machines
/run
/portables
/run
/extensions
610 touch /run
/machines
/a.raw
/run
/portables
/b.raw
/run
/extensions
/c.raw
612 systemd-dissect
--discover --json=short
>/tmp
/discover.json
613 grep -q -F '{"name":"a","type":"raw","class":"machine","ro":false,"path":"/run/machines/a.raw"' /tmp
/discover.json
614 grep -q -F '{"name":"b","type":"raw","class":"portable","ro":false,"path":"/run/portables/b.raw"' /tmp
/discover.json
615 grep -q -F '{"name":"c","type":"raw","class":"sysext","ro":false,"path":"/run/extensions/c.raw"' /tmp
/discover.json
616 rm /tmp
/discover.json
/run
/machines
/a.raw
/run
/portables
/b.raw
/run
/extensions
/c.raw
618 systemd-dissect
--discover --system
619 systemd-dissect
--discover --user
620 systemd-dissect
--discover --system --user
622 LOOP
="$(systemd-dissect --attach --loop-ref=waldo "$MINIMAL_IMAGE.raw
")"
624 # Wait until the symlinks we want to test are established
625 udevadm trigger
-w "$LOOP"
627 # Check if the /dev/loop/* symlinks really reference the right device
628 test /dev
/disk
/by-loop-ref
/waldo
-ef "$LOOP"
630 if [ "$(stat -c '%Hd:%Ld' "$MINIMAL_IMAGE.raw
")" != '?d:?d' ] ; then
631 # Old stat didn't know the %Hd and %Ld specifiers and turned them into ?d
632 # instead. Let's simply skip the test on such old systems.
633 test "$(stat -c '/dev/disk/by-loop-inode/%Hd:%Ld-%i' "$MINIMAL_IMAGE.raw
")" -ef "$LOOP"
636 # Detach by loopback device
637 systemd-dissect
--detach "$LOOP"
639 # Test long reference name.
640 # Note, sizeof_field(struct loop_info64, lo_file_name) == 64,
641 # and --loop-ref accepts upto 63 characters, and udev creates symlink
642 # based on the name when it has upto _62_ characters.
643 name
="$(for _ in {1..62}; do echo -n 'x'; done)"
644 LOOP
="$(systemd-dissect --attach --loop-ref="$name" "$MINIMAL_IMAGE.raw
")"
645 udevadm trigger
-w "$LOOP"
647 # Check if the /dev/disk/by-loop-ref/$name symlink really references the right device
648 test "/dev/disk/by-loop-ref/$name" -ef "$LOOP"
650 # Detach by the /dev/disk/by-loop-ref symlink
651 systemd-dissect
--detach "/dev/disk/by-loop-ref/$name"
653 name
="$(for _ in {1..63}; do echo -n 'x'; done)"
654 LOOP
="$(systemd-dissect --attach --loop-ref="$name" "$MINIMAL_IMAGE.raw
")"
655 udevadm trigger
-w "$LOOP"
657 # Check if the /dev/disk/by-loop-ref/$name symlink does not exist
658 test ! -e "/dev/disk/by-loop-ref/$name"
660 # Detach by backing inode
661 systemd-dissect
--detach "$MINIMAL_IMAGE.raw"
662 (! systemd-dissect
--detach "$MINIMAL_IMAGE.raw")
664 # check for confext functionality
665 mkdir
-p /run
/confexts
/test
/etc
/extension-release.d
666 echo "ID=_any" >/run
/confexts
/test
/etc
/extension-release.d
/extension-release.
test
667 echo "ARCHITECTURE=_any" >>/run
/confexts
/test
/etc
/extension-release.d
/extension-release.
test
668 echo "MARKER_CONFEXT_123" >/run
/confexts
/test
/etc
/testfile
669 cat <<EOF >/run/confexts/test/etc/testscript
671 echo "This should not happen"
673 chmod +x
/run
/confexts
/test
/etc
/testscript
674 systemd-confext merge
675 grep -q -F "MARKER_CONFEXT_123" /etc
/testfile
677 systemd-confext status
678 systemd-confext unmerge
679 rm -rf /run
/confexts
/
681 unsquashfs
-no-xattrs -d /tmp
/img
"$MINIMAL_IMAGE.raw"
682 systemd-run
--unit=test-root-ephemeral \
683 -p RootDirectory
=/tmp
/img \
684 -p RootEphemeral
=yes \
686 bash
-c "touch /abc && sleep infinity"
687 test -n "$(ls -A /var/lib/systemd/ephemeral-trees)"
688 systemctl stop test-root-ephemeral
689 # shellcheck disable=SC2016
690 timeout
10 bash
-c 'until test -z "$(ls -A /var/lib/systemd/ephemeral-trees)"; do sleep .5; done'
691 test ! -f /tmp
/img
/abc
693 systemd-dissect
--mtree /tmp
/img
>/dev
/null
694 systemd-dissect
--list /tmp
/img
>/dev
/null
696 read -r SHA256SUM1 _
< <(systemd-dissect
--copy-from /tmp
/img etc
/os-release | sha256sum
)
697 test "$SHA256SUM1" != ""
700 systemd-dissect
--copy-to /tmp
/img abc
/abc
703 # Test for dissect tool support with systemd-sysext
704 mkdir
-p /run
/extensions
/ testkit
/usr
/lib
/extension-release.d
/
705 echo "ID=_any" >testkit
/usr
/lib
/extension-release.d
/extension-release.testkit
706 echo "ARCHITECTURE=_any" >>testkit
/usr
/lib
/extension-release.d
/extension-release.testkit
707 echo "MARKER_SYSEXT_123" >testkit
/usr
/lib
/testfile
708 mksquashfs testkit
/ testkit.raw
709 cp testkit.raw
/run
/extensions
/
710 unsquashfs
-l /run
/extensions
/testkit.raw
711 systemd-dissect
--no-pager /run
/extensions
/testkit.raw |
grep -q '✓ sysext for portable service'
712 systemd-dissect
--no-pager /run
/extensions
/testkit.raw |
grep -q '✓ sysext for system'
714 systemd-sysext status
715 grep -q -F "MARKER_SYSEXT_123" /usr
/lib
/testfile
716 systemd-sysext unmerge
717 rm -rf /run
/extensions
/ testkit
/
719 # Test for dissect tool support with systemd-confext
720 mkdir
-p /run
/confexts
/ testjob
/etc
/extension-release.d
/
721 echo "ID=_any" >testjob
/etc
/extension-release.d
/extension-release.testjob
722 echo "ARCHITECTURE=_any" >>testjob
/etc
/extension-release.d
/extension-release.testjob
723 echo "MARKER_CONFEXT_123" >testjob
/etc
/testfile
724 mksquashfs testjob
/ testjob.raw
725 cp testjob.raw
/run
/confexts
/
726 unsquashfs
-l /run
/confexts
/testjob.raw
727 systemd-dissect
--no-pager /run
/confexts
/testjob.raw |
grep -q '✓ confext for system'
728 systemd-dissect
--no-pager /run
/confexts
/testjob.raw |
grep -q '✓ confext for portable service'
729 systemd-confext merge
730 systemd-confext status
731 grep -q -F "MARKER_CONFEXT_123" /etc
/testfile
732 systemd-confext unmerge
733 rm -rf /run
/confexts
/ testjob
/
735 systemd-run
-P -p RootImage
="$MINIMAL_IMAGE.raw" cat /run
/host
/os-release |
cmp "$OS_RELEASE"
737 # Test that systemd-sysext reloads the daemon.
738 mkdir
-p /var
/lib
/extensions
/
739 ln -s /tmp
/app-reload.raw
/var
/lib
/extensions
/app-reload.raw
740 systemd-sysext merge
--no-reload
741 # the service should not be running
742 (! systemctl
--quiet is-active foo.service
)
743 systemd-sysext unmerge
--no-reload
747 # "journalctl -u foo.service" may not work as expected, especially entries for _TRANSPORT=stdout,
748 # for short-living services or when the service manager generates debugging logs.
749 # Instead, SYSLOG_IDENTIFIER= should be reliable for stdout. Let's use it.
750 timeout
-v 30s journalctl
-b SYSLOG_IDENTIFIER
=echo _TRANSPORT
=stdout
-o cat -n all
--follow |
grep -m 1 -q '^foo$'
752 systemd-sysext unmerge
--no-reload
753 # Grep on the Warning to find the warning helper mentioning the daemon reload.
754 systemctl status foo.service
2>&1 |
grep -q -F "Warning"
756 systemd-sysext unmerge
757 systemctl status foo.service
2>&1 |
grep -v -q -F "Warning"
758 rm /var
/lib
/extensions
/app-reload.raw
760 # Sneak in a couple of expected-to-fail invocations to cover
761 # https://github.com/systemd/systemd/issues/29610
762 (! systemd-run
-P -p MountImages
="/this/should/definitely/not/exist.img:/run/img2\:3:nosuid" false
)
763 (! systemd-run
-P -p ExtensionImages
="/this/should/definitely/not/exist.img" false
)
764 (! systemd-run
-P -p RootImage
="/this/should/definitely/not/exist.img" false
)
765 (! systemd-run
-P -p ExtensionDirectories
="/foo/bar /foo/baz" false
)