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
8 export SYSTEMD_LOG_LEVEL
=debug
10 # shellcheck disable=SC2317
14 if [ -z "${image_dir}" ]; then
17 umount
"${image_dir}/app0"
18 umount
"${image_dir}/app1"
19 umount
"${image_dir}/app-nodistro"
20 umount
"${image_dir}/service-scoped-test"
24 udevadm control
--log-level=debug
28 image_dir
="$(mktemp -d -t -p /tmp tmp.XXXXXX)"
29 if [ -z "${image_dir}" ] ||
[ ! -d "${image_dir}" ]; then
30 echo "mktemp under /tmp failed"
36 cp /usr
/share
/minimal
* "${image_dir}/"
37 image
="${image_dir}/minimal_0"
38 roothash
="$(cat "${image}.roothash
")"
40 os_release
="$(test -e /etc/os-release && echo /etc/os-release || echo /usr/lib/os-release)"
42 systemd-dissect
--json=short
"${image}.raw" |
grep -q -F '{"rw":"ro","designator":"root","partition_uuid":null,"partition_label":null,"fstype":"squashfs","architecture":null,"verity":"external"'
43 systemd-dissect
"${image}.raw" |
grep -q -F "MARKER=1"
44 systemd-dissect
"${image}.raw" |
grep -q -F -f <(sed 's/"//g' "$os_release")
46 systemd-dissect
--list "${image}.raw" |
grep -q '^etc/os-release$'
47 systemd-dissect
--mtree "${image}.raw" --mtree-hash yes |
grep -qe "^./usr/bin/cat type=file mode=0755 uid=0 gid=0 size=[0-9]* sha256sum=[a-z0-9]*$"
48 systemd-dissect
--mtree "${image}.raw" --mtree-hash no |
grep -qe "^./usr/bin/cat type=file mode=0755 uid=0 gid=0 size=[0-9]*$"
50 read -r SHA256SUM1 _
< <(systemd-dissect
--copy-from "${image}.raw" etc
/os-release | sha256sum
)
51 test "$SHA256SUM1" != ""
52 read -r SHA256SUM2 _
< <(systemd-dissect
--read-only --with "${image}.raw" sha256sum etc
/os-release
)
53 test "$SHA256SUM2" != ""
54 test "$SHA256SUM1" = "$SHA256SUM2"
56 mv "${image}.verity" "${image}.fooverity"
57 mv "${image}.roothash" "${image}.foohash"
58 systemd-dissect
--json=short
"${image}.raw" --root-hash="${roothash}" --verity-data="${image}.fooverity" |
grep -q -F '{"rw":"ro","designator":"root","partition_uuid":null,"partition_label":null,"fstype":"squashfs","architecture":null,"verity":"external"'
59 systemd-dissect
"${image}.raw" --root-hash="${roothash}" --verity-data="${image}.fooverity" |
grep -q -F "MARKER=1"
60 systemd-dissect
"${image}.raw" --root-hash="${roothash}" --verity-data="${image}.fooverity" |
grep -q -F -f <(sed 's/"//g' "$os_release")
61 mv "${image}.fooverity" "${image}.verity"
62 mv "${image}.foohash" "${image}.roothash"
64 mkdir
-p "${image_dir}/mount" "${image_dir}/mount2"
65 systemd-dissect
--mount "${image}.raw" "${image_dir}/mount"
66 grep -q -F -f "$os_release" "${image_dir}/mount/usr/lib/os-release"
67 grep -q -F -f "$os_release" "${image_dir}/mount/etc/os-release"
68 grep -q -F "MARKER=1" "${image_dir}/mount/usr/lib/os-release"
69 # Verity volume should be shared (opened only once)
70 systemd-dissect
--mount "${image}.raw" "${image_dir}/mount2"
71 verity_count
=$
(find /dev
/mapper
/ -name "*verity*" |
wc -l)
72 # In theory we should check that count is exactly one. In practice, libdevmapper
73 # randomly and unpredictably fails with an unhelpful EINVAL when a device is open
74 # (and even mounted and in use), so best-effort is the most we can do for now
75 if [ "${verity_count}" -lt 1 ]; then
76 echo "Verity device ${image}.raw not found in /dev/mapper/"
79 systemd-dissect
--umount "${image_dir}/mount"
80 systemd-dissect
--umount "${image_dir}/mount2"
82 systemd-run
-P -p RootImage
="${image}.raw" cat /usr
/lib
/os-release |
grep -q -F "MARKER=1"
83 mv "${image}.verity" "${image}.fooverity"
84 mv "${image}.roothash" "${image}.foohash"
85 systemd-run
-P -p RootImage
="${image}.raw" -p RootHash="${image}.foohash" -p RootVerity="${image}.fooverity" cat /usr
/lib
/os-release |
grep -q -F "MARKER=1"
86 # Let's use the long option name just here as a test
87 systemd-run
-P --property RootImage
="${image}.raw" --property RootHash="${roothash}" --property RootVerity="${image}.fooverity" cat /usr
/lib
/os-release |
grep -q -F "MARKER=1"
88 mv "${image}.fooverity" "${image}.verity"
89 mv "${image}.foohash" "${image}.roothash"
91 # Make a GPT disk on the fly, with the squashfs as partition 1 and the verity hash tree as partition 2
93 if [ "${machine}" = "x86_64" ]; then
94 root_guid
=4f68bce3-e8cd-4db1-96e7-fbcaf984b709
95 verity_guid
=2c7357ed-ebd2-46d9-aec1-23d437ec2bf5
96 signature_guid
=41092b05-9fc8-4523-994f-2def0408b176
98 elif [ "${machine}" = "i386" ] || [ "${machine}" = "i686" ] || [ "${machine}" = "x86" ]; then
99 root_guid
=44479540-f297-41b2-9af7-d131d5f0458a
100 verity_guid
=d13c5d3b-b5d1-422a-b29f-9454fdc89d76
101 signature_guid
=5996fc05-109c-48de-808b-23fa0830b676
103 elif [ "${machine}" = "aarch64" ] || [ "${machine}" = "aarch64_be" ] || [ "${machine}" = "armv8b" ] || [ "${machine}" = "armv8l" ]; then
104 root_guid
=b921b045-1df0-41c3-af44-4c6f280d3fae
105 verity_guid
=df3300ce-d69f-4c92-978c-9bfb0f38d820
106 signature_guid
=6db69de6-29f4-4758-a7a5-962190f00ce3
108 elif [ "${machine}" = "arm" ]; then
109 root_guid
=69dad710-2ce4-4e3c-b16c-21a1d49abed3
110 verity_guid
=7386cdf2-203c-47a9-a498-f2ecce45a2d6
111 signature_guid
=42b0455f-eb11-491d-98d3-56145ba9d037
113 elif [ "${machine}" = "loongarch64" ]; then
114 root_guid
=77055800-792c-4f94-b39a-98c91b762bb6
115 verity_guid
=f3393b22-e9af-4613-a948-9d3bfbd0c535
116 signature_guid
=5afb67eb-ecc8-4f85-ae8e-ac1e7c50e7d0
117 architecture
="loongarch64"
118 elif [ "${machine}" = "ia64" ]; then
119 root_guid
=993d8d3d-f80e-4225-855a-9daf8ed7ea97
120 verity_guid
=86ed10d5-b607-45bb-8957-d350f23d0571
121 signature_guid
=e98b36ee-32ba-4882-9b12-0ce14655f46a
123 elif [ "${machine}" = "s390x" ]; then
124 root_guid
=5eead9a9-fe09-4a1e-a1d7-520d00531306
125 verity_guid
=b325bfbe-c7be-4ab8-8357-139e652d2f6b
126 signature_guid
=c80187a5-73a3-491a-901a-017c3fa953e9
128 elif [ "${machine}" = "ppc64le" ]; then
129 root_guid
=c31c45e6-3f39-412e-80fb-4809c4980599
130 verity_guid
=906bd944-4589-4aae-a4e4-dd983917446a
131 signature_guid
=d4a236e7-e873-4c07-bf1d-bf6cf7f1c3c6
132 architecture
="ppc64-le"
134 echo "Unexpected uname -m: ${machine} in testsuite-50.sh, please fix me"
137 # du rounds up to block size, which is more helpful for partitioning
138 root_size
="$(du -k "${image}.raw
" | cut -f1)"
139 verity_size
="$(du -k "${image}.verity
" | cut -f1)"
141 # 4MB seems to be the minimum size blkid will accept, below that probing fails
142 dd if=/dev
/zero of
="${image}.gpt" bs
=512 count
=$
((8192+root_size
*2+verity_size
*2+signature_size
*2))
143 # sfdisk seems unhappy if the size overflows into the next unit, eg: 1580KiB will be interpreted as 1MiB
144 # so do some basic rounding up if the minimal image is more than 1 MB
145 if [ "${root_size}" -ge 1024 ]; then
146 root_size
="$((root_size/1024 + 1))MiB"
148 root_size
="${root_size}KiB"
150 verity_size
="$((verity_size * 2))KiB"
151 signature_size
="$((signature_size * 2))KiB"
154 if systemctl
--version |
grep -q -- +OPENSSL
; then
155 # The openssl binary is installed conditionally.
156 # If we have OpenSSL support enabled and openssl is missing, fail early
157 # with a proper error message.
158 if ! command -v openssl
>/dev
/null
2>&1; then
159 echo "openssl missing" >/failed
163 # Unfortunately OpenSSL insists on reading some config file, hence provide one with mostly placeholder contents
164 cat >>"${image}.openssl.cnf" <<EOF
167 distinguished_name = req_distinguished_name
169 [ req_distinguished_name ]
176 emailAddress = test@email.com
180 openssl req
-config "${image}.openssl.cnf" -new -x509 -newkey rsa:1024 -keyout "${image}.key" -out "${image}.crt" -days 365 -nodes
181 # Sign Verity root hash with it
182 openssl smime
-sign -nocerts -noattr -binary -in "${image}.roothash" -inkey "${image}.key" -signer "${image}.crt" -outform der -out "${image}.roothash.p7s"
183 # Generate signature partition JSON data
184 echo '{"rootHash":"'"${roothash}"'","signature":"'"$(base64 -w 0 <"${image}.roothash.p7s")"'"}' >"${image}.verity-sig
"
186 truncate -s "${signature_size}" "${image}.verity-sig
"
187 # Register certificate in the (userspace) verity key ring
188 mkdir -p /run/verity.d
189 ln -s "${image}.crt
" /run/verity.d/ok.crt
192 # Construct a UUID from hash
193 # input: 11111111222233334444555566667777
194 # output: 11111111-2222-3333-4444-555566667777
195 uuid="$
(head -c 32 "${image}.roothash" |
sed -r 's/(.{8})(.{4})(.{4})(.{4})(.+)/\1-\2-\3-\4-\5/')"
196 echo -e "label
: gpt
\nsize
=${root_size}, type=${root_guid}, uuid=${uuid}" | sfdisk "${image}.gpt
"
197 uuid="$
(tail -c 32 "${image}.roothash" |
sed -r 's/(.{8})(.{4})(.{4})(.{4})(.+)/\1-\2-\3-\4-\5/')"
198 echo -e "size
=${verity_size}, type=${verity_guid}, uuid=${uuid}" | sfdisk "${image}.gpt
" --append
199 if [ "${HAVE_OPENSSL}" -eq 1 ]; then
200 echo -e "size
=${signature_size}, type=${signature_guid}" | sfdisk "${image}.gpt
" --append
202 sfdisk --part-label "${image}.gpt
" 1 "Root Partition
"
203 sfdisk --part-label "${image}.gpt
" 2 "Verity Partition
"
204 if [ "${HAVE_OPENSSL}" -eq 1 ]; then
205 sfdisk --part-label "${image}.gpt
" 3 "Signature Partition
"
207 loop="$
(losetup
--show -P -f "${image}.gpt")"
212 if [ "${HAVE_OPENSSL}" -eq 1 ]; then
213 partitions+=( "${loop:?}p3
" )
215 # The kernel sometimes(?) does not emit "add
" uevent for loop block partition devices.
216 # Let's not expect the devices to be initialized.
217 udevadm wait --timeout 60 --settle --initialized=no "${partitions[@]}"
218 udevadm lock --device="${loop}p1" dd if="${image}.raw" of="${loop}p1
"
219 udevadm lock --device="${loop}p2" dd if="${image}.verity" of="${loop}p2
"
220 if [ "${HAVE_OPENSSL}" -eq 1 ]; then
221 udevadm lock --device="${loop}p3" dd if="${image}.verity-sig" of="${loop}p3
"
225 # Derive partition UUIDs from root hash, in UUID syntax
226 ROOT_UUID="$
(systemd-id128
-u show
"$(head -c 32 "${image}.roothash
")" -u |
tail -n 1 | cut
-b 6-)"
227 VERITY_UUID="$
(systemd-id128
-u show
"$(tail -c 32 "${image}.roothash
")" -u |
tail -n 1 | cut
-b 6-)"
229 systemd-dissect --json=short --root-hash "${roothash}" "${image}.gpt
" | grep -q '{"rw
":"ro
","designator
":"root
","partition_uuid
":"'"$ROOT_UUID"'","partition_label
":"Root Partition
","fstype
":"squashfs
","architecture
":"'"$architecture"'","verity
":"signed
",'
230 systemd-dissect --json=short --root-hash "${roothash}" "${image}.gpt
" | grep -q '{"rw
":"ro
","designator
":"root-verity
","partition_uuid
":"'"$VERITY_UUID"'","partition_label
":"Verity Partition
","fstype
":"DM_verity_hash
","architecture
":"'"$architecture"'","verity
":null,'
231 if [ "${HAVE_OPENSSL}" -eq 1 ]; then
232 systemd-dissect --json=short --root-hash "${roothash}" "${image}.gpt
" | grep -q -E '{"rw
":"ro
","designator
":"root-verity-sig
","partition_uuid
":"'".*"'","partition_label
":"Signature Partition
","fstype
":"verity_hash_signature
","architecture
":"'"$architecture"'","verity
":null,'
234 systemd-dissect --root-hash "${roothash}" "${image}.gpt
" | grep -q -F "MARKER
=1"
235 systemd-dissect --root-hash "${roothash}" "${image}.gpt
" | grep -q -F -f <(sed 's/"//g
' "$os_release")
237 # Test image policies
238 systemd-dissect --validate "${image}.gpt"
239 systemd-dissect --validate "${image}.gpt" --image-policy='*'
240 (! systemd-dissect --validate "${image}.gpt" --image-policy='~
')
241 (! systemd-dissect --validate "${image}.gpt" --image-policy='-')
242 (! systemd-dissect --validate "${image}.gpt" --image-policy=root=absent)
243 (! systemd-dissect --validate "${image}.gpt" --image-policy=swap=unprotected+encrypted+verity)
244 systemd-dissect --validate "${image}.gpt" --image-policy=root=unprotected
245 systemd-dissect --validate "${image}.gpt" --image-policy=root=verity
246 systemd-dissect --validate "${image}.gpt" --image-policy=root=verity:root-verity-sig=unused+absent
247 systemd-dissect --validate "${image}.gpt" --image-policy=root=verity:swap=absent
248 systemd-dissect --validate "${image}.gpt" --image-policy=root=verity:swap=absent+unprotected
249 (! systemd-dissect --validate "${image}.gpt" --image-policy=root=verity:root-verity=unused+absent)
250 systemd-dissect --validate "${image}.gpt" --image-policy=root=signed
251 (! systemd-dissect --validate "${image}.gpt" --image-policy=root=signed:root-verity-sig=unused+absent)
252 (! systemd-dissect --validate "${image}.gpt" --image-policy=root=signed:root-verity=unused+absent)
254 # Test RootImagePolicy= unit file setting
255 systemd-run --wait -P -p RootImage="${image}.gpt" -p RootHash="${roothash}" -p MountAPIVFS=yes cat /usr/lib/os-release | grep -q -F "MARKER=1"
256 systemd-run --wait -P -p RootImage="${image}.gpt" -p RootHash="${roothash}" -p RootImagePolicy='*' -p MountAPIVFS=yes cat /usr/lib/os-release | grep -q -F "MARKER=1"
257 (! systemd-run --wait -P -p RootImage="${image}.gpt" -p RootHash="${roothash}" -p RootImagePolicy='~
' -p MountAPIVFS=yes cat /usr/lib/os-release | grep -q -F "MARKER=1")
258 (! systemd-run --wait -P -p RootImage="${image}.gpt" -p RootHash="${roothash}" -p RootImagePolicy='-' -p MountAPIVFS=yes cat /usr/lib/os-release | grep -q -F "MARKER=1")
259 (! systemd-run --wait -P -p RootImage="${image}.gpt" -p RootHash="${roothash}" -p RootImagePolicy='root
=absent
' -p MountAPIVFS=yes cat /usr/lib/os-release | grep -q -F "MARKER=1")
260 systemd-run --wait -P -p RootImage="${image}.gpt" -p RootHash="${roothash}" -p RootImagePolicy='root
=verity
' -p MountAPIVFS=yes cat /usr/lib/os-release | grep -q -F "MARKER=1"
261 systemd-run --wait -P -p RootImage="${image}.gpt" -p RootHash="${roothash}" -p RootImagePolicy='root
=signed
' -p MountAPIVFS=yes cat /usr/lib/os-release | grep -q -F "MARKER=1"
262 (! systemd-run --wait -P -p RootImage="${image}.gpt" -p RootHash="${roothash}" -p RootImagePolicy='root
=encrypted
' -p MountAPIVFS=yes cat /usr/lib/os-release | grep -q -F "MARKER=1")
264 systemd-dissect --root-hash "${roothash}" --mount "${image}.gpt" "${image_dir}/mount"
265 grep -q -F -f "$os_release" "${image_dir}/mount/usr/lib/os-release"
266 grep -q -F -f "$os_release" "${image_dir}/mount/etc/os-release"
267 grep -q -F "MARKER=1" "${image_dir}/mount/usr/lib/os-release"
268 systemd-dissect --umount "${image_dir}/mount"
270 systemd-dissect --root-hash "${roothash}" --mount "${image}.gpt" --in-memory "${image_dir}/mount"
271 grep -q -F -f "$os_release" "${image_dir}/mount/usr/lib/os-release"
272 grep -q -F -f "$os_release" "${image_dir}/mount/etc/os-release"
273 grep -q -F "MARKER=1" "${image_dir}/mount/usr/lib/os-release"
274 systemd-dissect --umount "${image_dir}/mount"
276 # add explicit -p MountAPIVFS=yes once to test the parser
277 systemd-run -P -p RootImage="${image}.gpt" -p RootHash="${roothash}" -p MountAPIVFS=yes cat /usr/lib/os-release | grep -q -F "MARKER=1"
279 systemd-run -P -p RootImage="${image}.raw" -p RootImageOptions="root:nosuid,dev home:ro,dev ro,noatime" mount | grep -F "squashfs" | grep -q -F "nosuid"
280 systemd-run -P -p RootImage="${image}.gpt" -p RootImageOptions="root:ro,noatime root:ro,dev" mount | grep -F "squashfs" | grep -q -F "noatime"
282 mkdir -p "${image_dir}/result"
283 cat >/run/systemd/system/testservice-50a.service <<EOF
286 ExecStart=bash -c "mount >/run/result/a"
287 BindPaths=${image_dir}/result:/run/result
288 TemporaryFileSystem=/run
289 RootImage=${image}.raw
290 RootImageOptions=root:ro,noatime home:ro,dev relatime,dev
291 RootImageOptions=nosuid,dev
293 systemctl start testservice-50a.service
294 grep -F "squashfs" "${image_dir}/result/a" | grep -q -F "noatime"
295 grep -F "squashfs" "${image_dir}/result/a" | grep -q -F -v "nosuid"
297 cat >/run/systemd/system/testservice-50b.service <<EOF
300 ExecStart=bash -c "mount >/run/result/b"
301 BindPaths=${image_dir}/result:/run/result
302 TemporaryFileSystem=/run
303 RootImage=${image}.gpt
304 RootImageOptions=root:ro,noatime,nosuid home:ro,dev nosuid,dev
305 RootImageOptions=home:ro,dev nosuid,dev,%%foo
306 # this is the default, but let's specify once to
test the parser
309 systemctl start testservice-50b.service
310 grep -F "squashfs" "${image_dir}/result/b" |
grep -q -F "noatime"
312 # Check that specifier escape is applied %%foo → %foo
313 busctl get-property org.freedesktop.systemd1
/org
/freedesktop
/systemd
1/unit
/testservice_2d50b_2eservice org.freedesktop.systemd1.Service RootImageOptions |
grep -F "nosuid,dev,%foo"
315 # Now do some checks with MountImages, both by itself, with options and in combination with RootImage, and as single FS or GPT image
316 systemd-run
-P -p MountImages
="${image}.gpt:/run/img1 ${image}.raw:/run/img2" cat /run
/img
1/usr
/lib
/os-release |
grep -q -F "MARKER=1"
317 systemd-run
-P -p MountImages
="${image}.gpt:/run/img1 ${image}.raw:/run/img2" cat /run
/img
2/usr
/lib
/os-release |
grep -q -F "MARKER=1"
318 systemd-run
-P -p MountImages
="${image}.gpt:/run/img1 ${image}.raw:/run/img2:nosuid,dev" mount |
grep -F "squashfs" |
grep -q -F "nosuid"
319 systemd-run
-P -p MountImages
="${image}.gpt:/run/img1:root:nosuid ${image}.raw:/run/img2:home:suid" mount |
grep -F "squashfs" |
grep -q -F "nosuid"
320 systemd-run
-P -p MountImages
="${image}.raw:/run/img2\:3" cat /run
/img2
:3/usr
/lib
/os-release |
grep -q -F "MARKER=1"
321 systemd-run
-P -p MountImages
="${image}.raw:/run/img2\:3:nosuid" mount |
grep -F "squashfs" |
grep -q -F "nosuid"
322 systemd-run
-P -p TemporaryFileSystem
=/run
-p RootImage
="${image}.raw" -p MountImages="${image}.gpt:/run/img1 ${image}.raw:/run/img2" cat /usr
/lib
/os-release |
grep -q -F "MARKER=1"
323 systemd-run
-P -p TemporaryFileSystem
=/run
-p RootImage
="${image}.raw" -p MountImages="${image}.gpt:/run/img1 ${image}.raw:/run/img2" cat /run
/img
1/usr
/lib
/os-release |
grep -q -F "MARKER=1"
324 systemd-run
-P -p TemporaryFileSystem
=/run
-p RootImage
="${image}.gpt" -p RootHash="${roothash}" -p MountImages="${image}.gpt:/run/img1 ${image}.raw:/run/img2" cat /run
/img
2/usr
/lib
/os-release |
grep -q -F "MARKER=1"
325 cat >/run
/systemd
/system
/testservice-50c.service
<<EOF
328 TemporaryFileSystem=/run
329 RootImage=${image}.raw
330 MountImages=${image}.gpt:/run/img1:root:noatime:home:relatime
331 MountImages=${image}.raw:/run/img2\:3:nosuid
332 ExecStart=bash -c "cat /run/img1/usr/lib/os-release >/run/result/c"
333 ExecStart=bash -c "cat /run/img2:3/usr/lib/os-release >>/run/result/c"
334 ExecStart=bash -c "mount >>/run/result/c"
335 BindPaths=${image_dir}/result:/run/result
338 systemctl start testservice-50c.service
339 grep -q -F "MARKER=1" "${image_dir}/result/c"
340 grep -F "squashfs" "${image_dir}/result/c" |
grep -q -F "noatime"
341 grep -F "squashfs" "${image_dir}/result/c" |
grep -q -F -v "nosuid"
343 # Adding a new mounts at runtime works if the unit is in the active state,
344 # so use Type=notify to make sure there's no race condition in the test
345 cat >/run
/systemd
/system
/testservice-50d.service
<<EOF
352 ExecStart=/bin/sh -c ' \\
353 systemd-notify --ready; \\
354 while [[ ! -f /tmp/img/usr/lib/os-release ]] || ! grep -q -F MARKER /tmp/img/usr/lib/os-release; do \\
358 mount | grep -F "on /tmp/img type squashfs" | grep -q -F "nosuid"; \\
361 systemctl start testservice-50d.service
363 systemctl mount-image
--mkdir testservice-50d.service
"${image}.raw" /tmp
/img root
:nosuid
365 while systemctl show
-P SubState testservice-50d.service |
grep -q running
370 systemctl is-active testservice-50d.service
372 # ExtensionImages will set up an overlay
373 systemd-run
-P --property ExtensionImages
=/usr
/share
/app0.raw
--property RootImage
="${image}.raw" cat /opt
/script0.sh |
grep -q -F "extension-release.app0"
374 systemd-run
-P --property ExtensionImages
=/usr
/share
/app0.raw
--property RootImage
="${image}.raw" cat /usr
/lib
/systemd
/system
/some_file |
grep -q -F "MARKER=1"
375 systemd-run
-P --property ExtensionImages
="/usr/share/app0.raw /usr/share/app1.raw" --property RootImage
="${image}.raw" cat /opt
/script0.sh |
grep -q -F "extension-release.app0"
376 systemd-run
-P --property ExtensionImages
="/usr/share/app0.raw /usr/share/app1.raw" --property RootImage
="${image}.raw" cat /usr
/lib
/systemd
/system
/some_file |
grep -q -F "MARKER=1"
377 systemd-run
-P --property ExtensionImages
="/usr/share/app0.raw /usr/share/app1.raw" --property RootImage
="${image}.raw" cat /opt
/script1.sh |
grep -q -F "extension-release.app2"
378 systemd-run
-P --property ExtensionImages
="/usr/share/app0.raw /usr/share/app1.raw" --property RootImage
="${image}.raw" cat /usr
/lib
/systemd
/system
/other_file |
grep -q -F "MARKER=1"
379 systemd-run
-P --property ExtensionImages
=/usr
/share
/app-nodistro.raw
--property RootImage
="${image}.raw" cat /usr
/lib
/systemd
/system
/some_file |
grep -q -F "MARKER=1"
380 systemd-run
-P --property ExtensionImages
=/etc
/service-scoped-test.raw
--property RootImage
="${image}.raw" cat /etc
/systemd
/system
/some_file |
grep -q -F "MARKER_CONFEXT_123"
381 # Check that using a symlink to NAME-VERSION.raw works as long as the symlink has the correct name NAME.raw
382 mkdir
-p /usr
/share
/symlink-test
/
383 cp /usr
/share
/app-nodistro.raw
/usr
/share
/symlink-test
/app-nodistro-v1.raw
384 ln -fs /usr
/share
/symlink-test
/app-nodistro-v1.raw
/usr
/share
/symlink-test
/app-nodistro.raw
385 systemd-run
-P --property ExtensionImages
=/usr
/share
/symlink-test
/app-nodistro.raw
--property RootImage
="${image}.raw" cat /usr
/lib
/systemd
/system
/some_file |
grep -q -F "MARKER=1"
387 # Symlink check again but for confext
388 mkdir
-p /etc
/symlink-test
/
389 cp /etc
/service-scoped-test.raw
/etc
/symlink-test
/service-scoped-test-v1.raw
390 ln -fs /etc
/symlink-test
/service-scoped-test-v1.raw
/etc
/symlink-test
/service-scoped-test.raw
391 systemd-run
-P --property ExtensionImages
=/etc
/symlink-test
/service-scoped-test.raw
--property RootImage
="${image}.raw" cat /etc
/systemd
/system
/some_file |
grep -q -F "MARKER_CONFEXT_123"
393 cat >/run
/systemd
/system
/testservice-50e.service
<<EOF
396 TemporaryFileSystem=/run /var/lib
398 RootImage=${image}.raw
399 ExtensionImages=/usr/share/app0.raw /usr/share/app1.raw:nosuid
400 # Relevant only for sanitizer runs
401 UnsetEnvironment=LD_PRELOAD
402 ExecStart=/bin/bash -c '/opt/script0.sh | grep ID'
403 ExecStart=/bin/bash -c '/opt/script1.sh | grep ID'
407 systemctl start testservice-50e.service
408 systemctl is-active testservice-50e.service
410 # ExtensionDirectories will set up an overlay
411 mkdir
-p "${image_dir}/app0" "${image_dir}/app1" "${image_dir}/app-nodistro" "${image_dir}/service-scoped-test"
412 (! systemd-run
-P --property ExtensionDirectories
="${image_dir}/nonexistent" --property RootImage
="${image}.raw" cat /opt
/script0.sh
)
413 (! systemd-run
-P --property ExtensionDirectories
="${image_dir}/app0" --property RootImage
="${image}.raw" cat /opt
/script0.sh
)
414 systemd-dissect
--mount /usr
/share
/app0.raw
"${image_dir}/app0"
415 systemd-dissect
--mount /usr
/share
/app1.raw
"${image_dir}/app1"
416 systemd-dissect
--mount /usr
/share
/app-nodistro.raw
"${image_dir}/app-nodistro"
417 systemd-dissect
--mount /etc
/service-scoped-test.raw
"${image_dir}/service-scoped-test"
418 systemd-run
-P --property ExtensionDirectories
="${image_dir}/app0" --property RootImage
="${image}.raw" cat /opt
/script0.sh |
grep -q -F "extension-release.app0"
419 systemd-run
-P --property ExtensionDirectories
="${image_dir}/app0" --property RootImage
="${image}.raw" cat /usr
/lib
/systemd
/system
/some_file |
grep -q -F "MARKER=1"
420 systemd-run
-P --property ExtensionDirectories
="${image_dir}/app0 ${image_dir}/app1" --property RootImage="${image}.raw" cat /opt
/script0.sh |
grep -q -F "extension-release.app0"
421 systemd-run
-P --property ExtensionDirectories
="${image_dir}/app0 ${image_dir}/app1" --property RootImage="${image}.raw" cat /usr
/lib
/systemd
/system
/some_file |
grep -q -F "MARKER=1"
422 systemd-run
-P --property ExtensionDirectories
="${image_dir}/app0 ${image_dir}/app1" --property RootImage="${image}.raw" cat /opt
/script1.sh |
grep -q -F "extension-release.app2"
423 systemd-run
-P --property ExtensionDirectories
="${image_dir}/app0 ${image_dir}/app1" --property RootImage="${image}.raw" cat /usr
/lib
/systemd
/system
/other_file |
grep -q -F "MARKER=1"
424 systemd-run
-P --property ExtensionDirectories
="${image_dir}/app-nodistro" --property RootImage
="${image}.raw" cat /usr
/lib
/systemd
/system
/some_file |
grep -q -F "MARKER=1"
425 systemd-run
-P --property ExtensionDirectories
="${image_dir}/service-scoped-test" --property RootImage
="${image}.raw" cat /etc
/systemd
/system
/some_file |
grep -q -F "MARKER_CONFEXT_123"
426 cat >/run
/systemd
/system
/testservice-50f.service
<<EOF
429 TemporaryFileSystem=/run /var/lib
431 RootImage=${image}.raw
432 ExtensionDirectories=${image_dir}/app0 ${image_dir}/app1
433 # Relevant only for sanitizer runs
434 UnsetEnvironment=LD_PRELOAD
435 ExecStart=/bin/bash -c '/opt/script0.sh | grep ID'
436 ExecStart=/bin/bash -c '/opt/script1.sh | grep ID'
440 systemctl start testservice-50f.service
441 systemctl is-active testservice-50f.service
442 systemd-dissect
--umount "${image_dir}/app0"
443 systemd-dissect
--umount "${image_dir}/app1"
445 # Test that an extension consisting of an empty directory under /etc/extensions/ takes precedence
446 mkdir
-p /var
/lib
/extensions
/
447 ln -s /usr
/share
/app-nodistro.raw
/var
/lib
/extensions
/app-nodistro.raw
449 grep -q -F "MARKER=1" /usr
/lib
/systemd
/system
/some_file
450 systemd-sysext unmerge
451 mkdir
-p /etc
/extensions
/app-nodistro
453 test ! -e /usr
/lib
/systemd
/system
/some_file
454 systemd-sysext unmerge
455 rmdir /etc
/extensions
/app-nodistro
457 # Check that extensions cannot contain os-release
458 mkdir
-p /run
/extensions
/app-reject
/usr
/lib
/{extension-release.d
/,systemd
/system
}
459 echo "ID=_any" >/run
/extensions
/app-reject
/usr
/lib
/extension-release.d
/extension-release.app-reject
460 echo "ID=_any" >/run
/extensions
/app-reject
/usr
/lib
/os-release
461 touch /run
/extensions
/app-reject
/usr
/lib
/systemd
/system
/other_file
462 (! systemd-sysext merge
)
463 test ! -e /usr
/lib
/systemd
/system
/some_file
464 test ! -e /usr
/lib
/systemd
/system
/other_file
465 systemd-sysext unmerge
466 rm -rf /run
/extensions
/app-reject
467 rm /var
/lib
/extensions
/app-nodistro.raw
469 mkdir
-p /run
/machines
/run
/portables
/run
/extensions
470 touch /run
/machines
/a.raw
/run
/portables
/b.raw
/run
/extensions
/c.raw
472 systemd-dissect
--discover --json=short
>/tmp
/discover.json
473 grep -q -F '{"name":"a","type":"raw","class":"machine","ro":false,"path":"/run/machines/a.raw"' /tmp
/discover.json
474 grep -q -F '{"name":"b","type":"raw","class":"portable","ro":false,"path":"/run/portables/b.raw"' /tmp
/discover.json
475 grep -q -F '{"name":"c","type":"raw","class":"sysext","ro":false,"path":"/run/extensions/c.raw"' /tmp
/discover.json
476 rm /tmp
/discover.json
/run
/machines
/a.raw
/run
/portables
/b.raw
/run
/extensions
/c.raw
478 # Check that the /sbin/mount.ddi helper works
479 T
="/tmp/mounthelper.$RANDOM"
480 mount
-t ddi
"${image}.gpt" "$T" -o ro
,X-mount.mkdir
,discard
484 LOOP
="$(systemd-dissect --attach --loop-ref=waldo "${image}.raw
")"
486 # Wait until the symlinks we want to test are established
487 udevadm trigger
-w "$LOOP"
489 # Check if the /dev/loop/* symlinks really reference the right device
490 test /dev
/disk
/by-loop-ref
/waldo
-ef "$LOOP"
492 if [ "$(stat -c '%Hd:%Ld' "${image}.raw
")" != '?d:?d' ] ; then
493 # Old stat didn't know the %Hd and %Ld specifiers and turned them into ?d
494 # instead. Let's simply skip the test on such old systems.
495 test "$(stat -c '/dev/disk/by-loop-inode/%Hd:%Ld-%i' "${image}.raw
")" -ef "$LOOP"
498 # Detach by loopback device
499 systemd-dissect
--detach "$LOOP"
501 # Test long reference name.
502 # Note, sizeof_field(struct loop_info64, lo_file_name) == 64,
503 # and --loop-ref accepts upto 63 characters, and udev creates symlink
504 # based on the name when it has upto _62_ characters.
505 name
="$(for _ in {1..62}; do echo -n 'x'; done)"
506 LOOP
="$(systemd-dissect --attach --loop-ref="$name" "${image}.raw
")"
507 udevadm trigger
-w "$LOOP"
509 # Check if the /dev/disk/by-loop-ref/$name symlink really references the right device
510 test "/dev/disk/by-loop-ref/$name" -ef "$LOOP"
512 # Detach by the /dev/disk/by-loop-ref symlink
513 systemd-dissect
--detach "/dev/disk/by-loop-ref/$name"
515 name
="$(for _ in {1..63}; do echo -n 'x'; done)"
516 LOOP
="$(systemd-dissect --attach --loop-ref="$name" "${image}.raw
")"
517 udevadm trigger
-w "$LOOP"
519 # Check if the /dev/disk/by-loop-ref/$name symlink does not exist
520 test ! -e "/dev/disk/by-loop-ref/$name"
522 # Detach by backing inode
523 systemd-dissect
--detach "${image}.raw"
524 (! systemd-dissect
--detach "${image}.raw")
526 # check for confext functionality
527 mkdir
-p /run
/confexts
/test
/etc
/extension-release.d
528 echo "ID=_any" >/run
/confexts
/test
/etc
/extension-release.d
/extension-release.
test
529 echo "ARCHITECTURE=_any" >>/run
/confexts
/test
/etc
/extension-release.d
/extension-release.
test
530 echo "MARKER_CONFEXT_123" >/run
/confexts
/test
/etc
/testfile
531 cat <<EOF >/run/confexts/test/etc/testscript
533 echo "This should not happen"
535 chmod +x
/run
/confexts
/test
/etc
/testscript
536 systemd-confext merge
537 grep -q -F "MARKER_CONFEXT_123" /etc
/testfile
539 systemd-confext status
540 systemd-confext unmerge
541 rm -rf /run
/confexts
/
543 unsquashfs
-no-xattrs -d /tmp
/img
"${image}.raw"
544 systemd-run
--unit=test-root-ephemeral \
545 -p RootDirectory
=/tmp
/img \
546 -p RootEphemeral
=yes \
548 bash
-c "touch /abc && sleep infinity"
549 test -n "$(ls -A /var/lib/systemd/ephemeral-trees)"
550 systemctl stop test-root-ephemeral
551 # shellcheck disable=SC2016
552 timeout
10 bash
-c 'until test -z "$(ls -A /var/lib/systemd/ephemeral-trees)"; do sleep .5; done'
553 test ! -f /tmp
/img
/abc
555 systemd-dissect
--mtree /tmp
/img
556 systemd-dissect
--list /tmp
/img
558 read -r SHA256SUM1 _
< <(systemd-dissect
--copy-from /tmp
/img etc
/os-release | sha256sum
)
559 test "$SHA256SUM1" != ""
562 systemd-dissect
--copy-to /tmp
/img abc
/abc
565 # Test for dissect tool support with systemd-sysext
566 mkdir
-p /run
/extensions
/ testkit
/usr
/lib
/extension-release.d
/
567 echo "ID=_any" >testkit
/usr
/lib
/extension-release.d
/extension-release.testkit
568 echo "ARCHITECTURE=_any" >>testkit
/usr
/lib
/extension-release.d
/extension-release.testkit
569 echo "MARKER_SYSEXT_123" >testkit
/usr
/lib
/testfile
570 mksquashfs testkit
/ testkit.raw
571 cp testkit.raw
/run
/extensions
/
572 unsquashfs
-l /run
/extensions
/testkit.raw
573 systemd-dissect
--no-pager /run
/extensions
/testkit.raw |
grep -q '✓ sysext extension for portable service'
574 systemd-dissect
--no-pager /run
/extensions
/testkit.raw |
grep -q '✓ sysext extension for system'
576 systemd-sysext status
577 grep -q -F "MARKER_SYSEXT_123" /usr
/lib
/testfile
578 systemd-sysext unmerge
579 rm -rf /run
/extensions
/ testkit
/
581 # Test for dissect tool support with systemd-confext
582 mkdir
-p /run
/confexts
/ testjob
/etc
/extension-release.d
/
583 echo "ID=_any" >testjob
/etc
/extension-release.d
/extension-release.testjob
584 echo "ARCHITECTURE=_any" >>testjob
/etc
/extension-release.d
/extension-release.testjob
585 echo "MARKER_CONFEXT_123" >testjob
/etc
/testfile
586 mksquashfs testjob
/ testjob.raw
587 cp testjob.raw
/run
/confexts
/
588 unsquashfs
-l /run
/confexts
/testjob.raw
589 systemd-dissect
--no-pager /run
/confexts
/testjob.raw |
grep -q '✓ confext extension for system'
590 systemd-dissect
--no-pager /run
/confexts
/testjob.raw |
grep -q '✓ confext extension for portable service'
591 systemd-confext merge
592 systemd-confext status
593 grep -q -F "MARKER_CONFEXT_123" /etc
/testfile
594 systemd-confext unmerge
595 rm -rf /run
/confexts
/ testjob
/
597 systemd-run
-P -p RootImage
="${image}.raw" cat /run
/host
/os-release |
cmp "${os_release}"
599 # Test that systemd-sysext reloads the daemon.
600 mkdir
-p /var
/lib
/extensions
/
601 ln -s /usr
/share
/app-reload.raw
/var
/lib
/extensions
/app-reload.raw
602 systemd-sysext merge
--no-reload
603 # the service should not be running
604 if systemctl
--quiet is-active foo.service
; then
605 echo "foo.service should not be active"
608 systemd-sysext unmerge
--no-reload
610 for RETRY
in $
(seq 60) LAST
; do
611 if journalctl
--boot --unit foo.service |
grep -q -P 'echo\[[0-9]+\]: foo'; then
614 if [ "${RETRY}" = LAST
]; then
615 echo "Output of foo.service not found"
620 systemd-sysext unmerge
--no-reload
621 # Grep on the Warning to find the warning helper mentioning the daemon reload.
622 systemctl status foo.service
2>&1 |
grep -q -F "Warning"
624 systemd-sysext unmerge
625 systemctl status foo.service
2>&1 |
grep -v -q -F "Warning"