]>
Commit | Line | Data |
---|---|---|
5a3b8640 | 1 | #!/usr/bin/env bash |
7b3cec95 | 2 | # SPDX-License-Identifier: LGPL-2.1-or-later |
5a3b8640 | 3 | set -eux |
30f56248 | 4 | set -o pipefail |
5a3b8640 | 5 | |
e2d05745 DDM |
6 | runas() { |
7 | declare userid=$1 | |
8 | shift | |
9 | # shellcheck disable=SC2016 | |
10 | su "$userid" -s /bin/sh -c 'XDG_RUNTIME_DIR=/run/user/$UID exec "$@"' -- sh "$@" | |
11 | } | |
12 | ||
f89a20f1 ZJS |
13 | if ! command -v systemd-repart &>/dev/null; then |
14 | echo "no systemd-repart" >/skipped | |
15 | exit 0 | |
16 | fi | |
17 | ||
5996f116 YW |
18 | # shellcheck source=test/units/assert.sh |
19 | . "$(dirname "$0")"/assert.sh | |
20 | ||
5a3b8640 LP |
21 | export SYSTEMD_LOG_LEVEL=debug |
22 | export PAGER=cat | |
23 | ||
71ea8436 LP |
24 | # Disable use of special glyphs such as → |
25 | export SYSTEMD_UTF8=0 | |
26 | ||
5996f116 YW |
27 | seed=750b6cd5c4ae4012a15e7be3c29e6a47 |
28 | ||
76097112 | 29 | if ! systemd-detect-virt --quiet --container; then |
e867b016 | 30 | udevadm control --log-level debug |
76097112 | 31 | fi |
2b21522e | 32 | |
8e65d93e LB |
33 | machine="$(uname -m)" |
34 | if [ "${machine}" = "x86_64" ]; then | |
5996f116 | 35 | root_guid=4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709 |
8e65d93e | 36 | root_uuid=60F33797-1D71-4DCB-AA6F-20564F036CD0 |
2b21522e | 37 | root_uuid2=73A4CCD2-EAF5-44DA-A366-F99188210FDC |
5996f116 | 38 | usr_guid=8484680C-9521-48C6-9C11-B0720656F69E |
8e65d93e LB |
39 | usr_uuid=7E3369DD-D653-4513-ADF5-B993A9F20C16 |
40 | architecture="x86-64" | |
41 | elif [ "${machine}" = "i386" ] || [ "${machine}" = "i686" ] || [ "${machine}" = "x86" ]; then | |
5996f116 YW |
42 | root_guid=44479540-F297-41B2-9AF7-D131D5F0458A |
43 | root_uuid=02B4253F-29A4-404E-8972-1669D3B03C87 | |
2b21522e | 44 | root_uuid2=268E0FD3-B468-4806-A823-E533FE9BB9CC |
5996f116 YW |
45 | usr_guid=75250D76-8CC6-458E-BD66-BD47CC81A812 |
46 | usr_uuid=7B42FFB0-B0E1-4395-B20B-C78F4A571648 | |
8e65d93e LB |
47 | architecture="x86" |
48 | elif [ "${machine}" = "aarch64" ] || [ "${machine}" = "aarch64_be" ] || [ "${machine}" = "armv8b" ] || [ "${machine}" = "armv8l" ]; then | |
5996f116 YW |
49 | root_guid=B921B045-1DF0-41C3-AF44-4C6F280D3FAE |
50 | root_uuid=055D0227-53A6-4033-85C3-9A5973EFF483 | |
2b21522e | 51 | root_uuid2=F7DBBE48-8FD0-4833-8411-AA34E7C8E60A |
5996f116 YW |
52 | usr_guid=B0E01050-EE5F-4390-949A-9101B17104E9 |
53 | usr_uuid=FCE3C75E-D6A4-44C0-87F0-4C105183FB1F | |
8e65d93e LB |
54 | architecture="arm64" |
55 | elif [ "${machine}" = "arm" ]; then | |
5996f116 YW |
56 | root_guid=69DAD710-2CE4-4E3C-B16C-21A1D49ABED3 |
57 | root_uuid=567DA89E-8DE2-4499-8D10-18F212DFF034 | |
2b21522e | 58 | root_uuid2=813ECFE5-4C89-4193-8A52-437493F2F96E |
5996f116 YW |
59 | usr_guid=7D0359A3-02B3-4F0A-865C-654403E70625 |
60 | usr_uuid=71E93DC2-5073-42CB-8A84-A354E64D8966 | |
8e65d93e LB |
61 | architecture="arm" |
62 | elif [ "${machine}" = "loongarch64" ]; then | |
5996f116 YW |
63 | root_guid=77055800-792C-4F94-B39A-98C91B762BB6 |
64 | root_uuid=D8EFC2D2-0133-41E4-BDCB-3B9F4CFDDDE8 | |
2b21522e | 65 | root_uuid2=36499F9E-0688-40C1-A746-EA8FD9543C56 |
5996f116 YW |
66 | usr_guid=E611C702-575C-4CBE-9A46-434FA0BF7E3F |
67 | usr_uuid=031FFA75-00BB-49B6-A70D-911D2D82A5B7 | |
8e65d93e LB |
68 | architecture="loongarch64" |
69 | elif [ "${machine}" = "ia64" ]; then | |
5996f116 YW |
70 | root_guid=993D8D3D-F80E-4225-855A-9DAF8ED7EA97 |
71 | root_uuid=DCF33449-0896-4EA9-BC24-7D58AEEF522D | |
2b21522e | 72 | root_uuid2=C2A6CAB7-ABEA-4FBA-8C48-CB4C52E6CA38 |
5996f116 YW |
73 | usr_guid=4301D2A6-4E3B-4B2A-BB94-9E0B2C4225EA |
74 | usr_uuid=BC2BCCE7-80D6-449A-85CC-637424CE5241 | |
8e65d93e LB |
75 | architecture="ia64" |
76 | elif [ "${machine}" = "s390x" ]; then | |
5996f116 YW |
77 | root_guid=5EEAD9A9-FE09-4A1E-A1D7-520D00531306 |
78 | root_uuid=7EBE0C85-E27E-48EC-B164-F4807606232E | |
2b21522e | 79 | root_uuid2=2A074E1C-2A19-4094-A0C2-24B1A5D52FCB |
5996f116 YW |
80 | usr_guid=8A4F5770-50AA-4ED3-874A-99B710DB6FEA |
81 | usr_uuid=51171D30-35CF-4A49-B8B5-9478B9B796A5 | |
8e65d93e LB |
82 | architecture="s390x" |
83 | elif [ "${machine}" = "ppc64le" ]; then | |
5996f116 YW |
84 | root_guid=C31C45E6-3F39-412E-80FB-4809C4980599 |
85 | root_uuid=061E67A1-092F-482F-8150-B525D50D6654 | |
2b21522e | 86 | root_uuid2=A6687CEF-4E4F-44E7-90B3-CDA52EA81739 |
5996f116 YW |
87 | usr_guid=15BB03AF-77E7-4D4A-B12B-C0D084F7491C |
88 | usr_uuid=C0D0823B-8040-4C7C-A629-026248E297FB | |
8e65d93e LB |
89 | architecture="ppc64-le" |
90 | else | |
91 | echo "Unexpected uname -m: ${machine} in testsuite-58.sh, please fix me" | |
92 | exit 1 | |
93 | fi | |
94 | ||
2b21522e YW |
95 | test_basic() { |
96 | local defs imgs output | |
97 | local loop volume | |
98 | ||
e2d05745 DDM |
99 | defs="$(runas testuser mktemp --directory "/tmp/test-repart.XXXXXXXXXX")" |
100 | imgs="$(runas testuser mktemp --directory "/var/tmp/test-repart.XXXXXXXXXX")" | |
2b21522e YW |
101 | # shellcheck disable=SC2064 |
102 | trap "rm -rf '$defs' '$imgs'" RETURN | |
103 | ||
104 | # 1. create an empty image | |
105 | ||
e2d05745 DDM |
106 | runas testuser systemd-repart --empty=create \ |
107 | --size=1G \ | |
108 | --seed="$seed" \ | |
109 | "$imgs/zzz" | |
2b21522e YW |
110 | |
111 | output=$(sfdisk -d "$imgs/zzz" | grep -v -e 'sector-size' -e '^$') | |
112 | ||
113 | assert_eq "$output" "label: gpt | |
114 | label-id: 1D2CE291-7CCE-4F7D-BC83-FDB49AD74EBD | |
115 | device: $imgs/zzz | |
116 | unit: sectors | |
117 | first-lba: 2048 | |
118 | last-lba: 2097118" | |
119 | ||
120 | # 2. Testing with root, root2, home, and swap | |
121 | ||
ff1b55ff | 122 | runas testuser tee "$defs/root.conf" <<EOF |
2b21522e YW |
123 | [Partition] |
124 | Type=root | |
125 | EOF | |
126 | ||
127 | ln -s root.conf "$defs/root2.conf" | |
128 | ||
ff1b55ff | 129 | runas testuser tee "$defs/home.conf" <<EOF |
2b21522e YW |
130 | [Partition] |
131 | Type=home | |
132 | Label=home-first | |
133 | Label=home-always-too-long-xxxxxxxxxxxxxx-%v | |
134 | EOF | |
135 | ||
ff1b55ff | 136 | runas testuser tee "$defs/swap.conf" <<EOF |
2b21522e YW |
137 | [Partition] |
138 | Type=swap | |
139 | SizeMaxBytes=64M | |
140 | PaddingMinBytes=92M | |
141 | EOF | |
142 | ||
e2d05745 DDM |
143 | runas testuser systemd-repart --definitions="$defs" \ |
144 | --dry-run=no \ | |
145 | --seed="$seed" \ | |
146 | --include-partitions=home,swap \ | |
147 | "$imgs/zzz" | |
56bb434e DDM |
148 | |
149 | output=$(sfdisk -d "$imgs/zzz" | grep -v -e 'sector-size' -e '^$') | |
150 | ||
151 | assert_eq "$output" "label: gpt | |
152 | label-id: 1D2CE291-7CCE-4F7D-BC83-FDB49AD74EBD | |
153 | device: $imgs/zzz | |
154 | unit: sectors | |
155 | first-lba: 2048 | |
156 | last-lba: 2097118 | |
7d505753 DDM |
157 | $imgs/zzz1 : start= 2048, size= 1775576, type=933AC7E1-2EB4-4F13-B844-0E14E2AEF915, uuid=4980595D-D74A-483A-AA9E-9903879A0EE5, name=\"home-first\", attrs=\"GUID:59\" |
158 | $imgs/zzz2 : start= 1777624, size= 131072, type=0657FD6D-A4AB-43C4-84E5-0933C84B4F4F, uuid=78C92DB8-3D2B-4823-B0DC-792B78F66F1E, name=\"swap\"" | |
56bb434e | 159 | |
e2d05745 DDM |
160 | runas testuser systemd-repart --definitions="$defs" \ |
161 | --dry-run=no \ | |
162 | --seed="$seed" \ | |
7d505753 | 163 | --empty=force \ |
8275334b | 164 | --defer-partitions=home,root \ |
e2d05745 | 165 | "$imgs/zzz" |
56bb434e DDM |
166 | |
167 | output=$(sfdisk -d "$imgs/zzz" | grep -v -e 'sector-size' -e '^$') | |
168 | ||
169 | assert_eq "$output" "label: gpt | |
170 | label-id: 1D2CE291-7CCE-4F7D-BC83-FDB49AD74EBD | |
171 | device: $imgs/zzz | |
172 | unit: sectors | |
173 | first-lba: 2048 | |
174 | last-lba: 2097118 | |
56bb434e DDM |
175 | $imgs/zzz4 : start= 1777624, size= 131072, type=0657FD6D-A4AB-43C4-84E5-0933C84B4F4F, uuid=78C92DB8-3D2B-4823-B0DC-792B78F66F1E, name=\"swap\"" |
176 | ||
e2d05745 DDM |
177 | runas testuser systemd-repart --definitions="$defs" \ |
178 | --dry-run=no \ | |
179 | --seed="$seed" \ | |
180 | "$imgs/zzz" | |
2b21522e YW |
181 | |
182 | output=$(sfdisk -d "$imgs/zzz" | grep -v -e 'sector-size' -e '^$') | |
183 | ||
184 | assert_eq "$output" "label: gpt | |
185 | label-id: 1D2CE291-7CCE-4F7D-BC83-FDB49AD74EBD | |
186 | device: $imgs/zzz | |
187 | unit: sectors | |
188 | first-lba: 2048 | |
189 | last-lba: 2097118 | |
190 | $imgs/zzz1 : start= 2048, size= 591856, type=933AC7E1-2EB4-4F13-B844-0E14E2AEF915, uuid=4980595D-D74A-483A-AA9E-9903879A0EE5, name=\"home-first\", attrs=\"GUID:59\" | |
191 | $imgs/zzz2 : start= 593904, size= 591856, type=${root_guid}, uuid=${root_uuid}, name=\"root-${architecture}\", attrs=\"GUID:59\" | |
192 | $imgs/zzz3 : start= 1185760, size= 591864, type=${root_guid}, uuid=${root_uuid2}, name=\"root-${architecture}-2\", attrs=\"GUID:59\" | |
193 | $imgs/zzz4 : start= 1777624, size= 131072, type=0657FD6D-A4AB-43C4-84E5-0933C84B4F4F, uuid=78C92DB8-3D2B-4823-B0DC-792B78F66F1E, name=\"swap\"" | |
194 | ||
195 | # 3. Testing with root, root2, home, swap, and another partition | |
196 | ||
ff1b55ff | 197 | runas testuser tee "$defs/swap.conf" <<EOF |
2b21522e YW |
198 | [Partition] |
199 | Type=swap | |
200 | SizeMaxBytes=64M | |
201 | EOF | |
202 | ||
ff1b55ff | 203 | runas testuser tee "$defs/extra.conf" <<EOF |
2b21522e YW |
204 | [Partition] |
205 | Type=linux-generic | |
206 | Label=custom_label | |
207 | UUID=a0a1a2a3a4a5a6a7a8a9aaabacadaeaf | |
208 | EOF | |
209 | ||
210 | echo "Label=ignored_label" >>"$defs/home.conf" | |
211 | echo "UUID=b0b1b2b3b4b5b6b7b8b9babbbcbdbebf" >>"$defs/home.conf" | |
212 | ||
e2d05745 DDM |
213 | runas testuser systemd-repart --definitions="$defs" \ |
214 | --dry-run=no \ | |
215 | --seed="$seed" \ | |
216 | "$imgs/zzz" | |
2b21522e YW |
217 | |
218 | output=$(sfdisk -d "$imgs/zzz" | grep -v -e 'sector-size' -e '^$') | |
219 | ||
220 | assert_eq "$output" "label: gpt | |
221 | label-id: 1D2CE291-7CCE-4F7D-BC83-FDB49AD74EBD | |
222 | device: $imgs/zzz | |
223 | unit: sectors | |
224 | first-lba: 2048 | |
225 | last-lba: 2097118 | |
226 | $imgs/zzz1 : start= 2048, size= 591856, type=933AC7E1-2EB4-4F13-B844-0E14E2AEF915, uuid=4980595D-D74A-483A-AA9E-9903879A0EE5, name=\"home-first\", attrs=\"GUID:59\" | |
227 | $imgs/zzz2 : start= 593904, size= 591856, type=${root_guid}, uuid=${root_uuid}, name=\"root-${architecture}\", attrs=\"GUID:59\" | |
228 | $imgs/zzz3 : start= 1185760, size= 591864, type=${root_guid}, uuid=${root_uuid2}, name=\"root-${architecture}-2\", attrs=\"GUID:59\" | |
229 | $imgs/zzz4 : start= 1777624, size= 131072, type=0657FD6D-A4AB-43C4-84E5-0933C84B4F4F, uuid=78C92DB8-3D2B-4823-B0DC-792B78F66F1E, name=\"swap\" | |
230 | $imgs/zzz5 : start= 1908696, size= 188416, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=A0A1A2A3-A4A5-A6A7-A8A9-AAABACADAEAF, name=\"custom_label\"" | |
231 | ||
232 | # 4. Resizing to 2G | |
233 | ||
e2d05745 DDM |
234 | runas testuser systemd-repart --definitions="$defs" \ |
235 | --size=2G \ | |
236 | --dry-run=no \ | |
237 | --seed="$seed" \ | |
238 | "$imgs/zzz" | |
2b21522e YW |
239 | |
240 | output=$(sfdisk -d "$imgs/zzz" | grep -v -e 'sector-size' -e '^$') | |
241 | ||
242 | assert_eq "$output" "label: gpt | |
243 | label-id: 1D2CE291-7CCE-4F7D-BC83-FDB49AD74EBD | |
244 | device: $imgs/zzz | |
245 | unit: sectors | |
246 | first-lba: 2048 | |
247 | last-lba: 4194270 | |
248 | $imgs/zzz1 : start= 2048, size= 591856, type=933AC7E1-2EB4-4F13-B844-0E14E2AEF915, uuid=4980595D-D74A-483A-AA9E-9903879A0EE5, name=\"home-first\", attrs=\"GUID:59\" | |
249 | $imgs/zzz2 : start= 593904, size= 591856, type=${root_guid}, uuid=${root_uuid}, name=\"root-${architecture}\", attrs=\"GUID:59\" | |
250 | $imgs/zzz3 : start= 1185760, size= 591864, type=${root_guid}, uuid=${root_uuid2}, name=\"root-${architecture}-2\", attrs=\"GUID:59\" | |
251 | $imgs/zzz4 : start= 1777624, size= 131072, type=0657FD6D-A4AB-43C4-84E5-0933C84B4F4F, uuid=78C92DB8-3D2B-4823-B0DC-792B78F66F1E, name=\"swap\" | |
252 | $imgs/zzz5 : start= 1908696, size= 2285568, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=A0A1A2A3-A4A5-A6A7-A8A9-AAABACADAEAF, name=\"custom_label\"" | |
253 | ||
254 | # 5. Testing with root, root2, home, swap, another partition, and partition copy | |
255 | ||
256 | dd if=/dev/urandom of="$imgs/block-copy" bs=4096 count=10240 | |
257 | ||
ff1b55ff | 258 | runas testuser tee "$defs/extra2.conf" <<EOF |
2b21522e YW |
259 | [Partition] |
260 | Type=linux-generic | |
261 | Label=block-copy | |
262 | UUID=2a1d97e1d0a346cca26eadc643926617 | |
263 | CopyBlocks=$imgs/block-copy | |
264 | EOF | |
265 | ||
e2d05745 DDM |
266 | runas testuser systemd-repart --definitions="$defs" \ |
267 | --size=3G \ | |
268 | --dry-run=no \ | |
269 | --seed="$seed" \ | |
270 | "$imgs/zzz" | |
2b21522e YW |
271 | |
272 | output=$(sfdisk -d "$imgs/zzz" | grep -v -e 'sector-size' -e '^$') | |
273 | ||
274 | assert_eq "$output" "label: gpt | |
275 | label-id: 1D2CE291-7CCE-4F7D-BC83-FDB49AD74EBD | |
276 | device: $imgs/zzz | |
277 | unit: sectors | |
278 | first-lba: 2048 | |
279 | last-lba: 6291422 | |
280 | $imgs/zzz1 : start= 2048, size= 591856, type=933AC7E1-2EB4-4F13-B844-0E14E2AEF915, uuid=4980595D-D74A-483A-AA9E-9903879A0EE5, name=\"home-first\", attrs=\"GUID:59\" | |
281 | $imgs/zzz2 : start= 593904, size= 591856, type=${root_guid}, uuid=${root_uuid}, name=\"root-${architecture}\", attrs=\"GUID:59\" | |
282 | $imgs/zzz3 : start= 1185760, size= 591864, type=${root_guid}, uuid=${root_uuid2}, name=\"root-${architecture}-2\", attrs=\"GUID:59\" | |
283 | $imgs/zzz4 : start= 1777624, size= 131072, type=0657FD6D-A4AB-43C4-84E5-0933C84B4F4F, uuid=78C92DB8-3D2B-4823-B0DC-792B78F66F1E, name=\"swap\" | |
284 | $imgs/zzz5 : start= 1908696, size= 2285568, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=A0A1A2A3-A4A5-A6A7-A8A9-AAABACADAEAF, name=\"custom_label\" | |
285 | $imgs/zzz6 : start= 4194264, size= 2097152, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=2A1D97E1-D0A3-46CC-A26E-ADC643926617, name=\"block-copy\"" | |
286 | ||
287 | cmp --bytes=$((4096*10240)) --ignore-initial=0:$((512*4194264)) "$imgs/block-copy" "$imgs/zzz" | |
288 | ||
289 | # 6. Testing Format=/Encrypt=/CopyFiles= | |
290 | ||
ff1b55ff | 291 | runas testuser tee "$defs/extra3.conf" <<EOF |
2b21522e YW |
292 | [Partition] |
293 | Type=linux-generic | |
294 | Label=luks-format-copy | |
295 | UUID=7b93d1f2-595d-4ce3-b0b9-837fbd9e63b0 | |
296 | Format=ext4 | |
297 | Encrypt=yes | |
298 | CopyFiles=$defs:/def | |
299 | SizeMinBytes=48M | |
300 | EOF | |
301 | ||
e2d05745 DDM |
302 | runas testuser systemd-repart --definitions="$defs" \ |
303 | --size=auto \ | |
304 | --dry-run=no \ | |
305 | --seed="$seed" \ | |
306 | "$imgs/zzz" | |
2b21522e YW |
307 | |
308 | output=$(sfdisk -d "$imgs/zzz" | grep -v -e 'sector-size' -e '^$') | |
309 | ||
310 | assert_eq "$output" "label: gpt | |
311 | label-id: 1D2CE291-7CCE-4F7D-BC83-FDB49AD74EBD | |
312 | device: $imgs/zzz | |
313 | unit: sectors | |
314 | first-lba: 2048 | |
315 | last-lba: 6389726 | |
316 | $imgs/zzz1 : start= 2048, size= 591856, type=933AC7E1-2EB4-4F13-B844-0E14E2AEF915, uuid=4980595D-D74A-483A-AA9E-9903879A0EE5, name=\"home-first\", attrs=\"GUID:59\" | |
317 | $imgs/zzz2 : start= 593904, size= 591856, type=${root_guid}, uuid=${root_uuid}, name=\"root-${architecture}\", attrs=\"GUID:59\" | |
318 | $imgs/zzz3 : start= 1185760, size= 591864, type=${root_guid}, uuid=${root_uuid2}, name=\"root-${architecture}-2\", attrs=\"GUID:59\" | |
319 | $imgs/zzz4 : start= 1777624, size= 131072, type=0657FD6D-A4AB-43C4-84E5-0933C84B4F4F, uuid=78C92DB8-3D2B-4823-B0DC-792B78F66F1E, name=\"swap\" | |
320 | $imgs/zzz5 : start= 1908696, size= 2285568, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=A0A1A2A3-A4A5-A6A7-A8A9-AAABACADAEAF, name=\"custom_label\" | |
321 | $imgs/zzz6 : start= 4194264, size= 2097152, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=2A1D97E1-D0A3-46CC-A26E-ADC643926617, name=\"block-copy\" | |
322 | $imgs/zzz7 : start= 6291416, size= 98304, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=7B93D1F2-595D-4CE3-B0B9-837FBD9E63B0, name=\"luks-format-copy\"" | |
323 | ||
e2d05745 DDM |
324 | if systemd-detect-virt --quiet --container; then |
325 | echo "Skipping encrypt mount tests in container." | |
326 | return | |
327 | fi | |
328 | ||
2b21522e YW |
329 | loop="$(losetup -P --show --find "$imgs/zzz")" |
330 | udevadm wait --timeout 60 --settle "${loop:?}" | |
331 | ||
332 | volume="test-repart-$RANDOM" | |
333 | ||
334 | touch "$imgs/empty-password" | |
335 | cryptsetup open --type=luks2 --key-file="$imgs/empty-password" "${loop}p7" "$volume" | |
336 | mkdir -p "$imgs/mount" | |
337 | mount -t ext4 "/dev/mapper/$volume" "$imgs/mount" | |
338 | # Use deferred closing on the mapper and autoclear on the loop, so they are cleaned up on umount | |
339 | cryptsetup close --deferred "$volume" | |
340 | losetup -d "$loop" | |
341 | diff -r "$imgs/mount/def" "$defs" >/dev/null | |
342 | umount "$imgs/mount" | |
343 | } | |
344 | ||
345 | test_dropin() { | |
346 | local defs imgs output | |
347 | ||
e2d05745 DDM |
348 | defs="$(runas testuser mktemp --directory "/tmp/test-repart.XXXXXXXXXX")" |
349 | imgs="$(runas testuser mktemp --directory "/var/tmp/test-repart.XXXXXXXXXX")" | |
2b21522e YW |
350 | # shellcheck disable=SC2064 |
351 | trap "rm -rf '$defs' '$imgs'" RETURN | |
352 | ||
ff1b55ff | 353 | runas testuser tee "$defs/root.conf" <<EOF |
2b21522e YW |
354 | [Partition] |
355 | Type=swap | |
356 | SizeMaxBytes=64M | |
357 | UUID=837c3d67-21b3-478e-be82-7e7f83bf96d3 | |
358 | EOF | |
359 | ||
ff1b55ff DDM |
360 | runas testuser mkdir -p "$defs/root.conf.d" |
361 | runas testuser tee "$defs/root.conf.d/override1.conf" <<EOF | |
2b21522e YW |
362 | [Partition] |
363 | Label=label1 | |
364 | SizeMaxBytes=32M | |
365 | EOF | |
366 | ||
ff1b55ff | 367 | runas testuser tee "$defs/root.conf.d/override2.conf" <<EOF |
2b21522e YW |
368 | [Partition] |
369 | Label=label2 | |
370 | EOF | |
371 | ||
e2d05745 DDM |
372 | output=$(runas testuser systemd-repart --definitions="$defs" \ |
373 | --empty=create \ | |
374 | --size=100M \ | |
375 | --json=pretty \ | |
376 | "$imgs/zzz") | |
2b21522e | 377 | |
71ea8436 | 378 | diff -u <(echo "$output") - <<EOF |
2b21522e YW |
379 | [ |
380 | { | |
381 | "type" : "swap", | |
382 | "label" : "label2", | |
383 | "uuid" : "837c3d67-21b3-478e-be82-7e7f83bf96d3", | |
d0242ac9 | 384 | "file" : "$defs/root.conf", |
2b21522e YW |
385 | "node" : "$imgs/zzz1", |
386 | "offset" : 1048576, | |
387 | "old_size" : 0, | |
388 | "raw_size" : 33554432, | |
71ea8436 | 389 | "size" : "-> 32.0M", |
2b21522e YW |
390 | "old_padding" : 0, |
391 | "raw_padding" : 0, | |
71ea8436 | 392 | "padding" : "-> 0B", |
2b21522e YW |
393 | "activity" : "create", |
394 | "drop-in_files" : [ | |
395 | "$defs/root.conf.d/override1.conf", | |
396 | "$defs/root.conf.d/override2.conf" | |
397 | ] | |
398 | } | |
399 | ] | |
400 | EOF | |
401 | } | |
402 | ||
403 | test_multiple_definitions() { | |
404 | local defs imgs output | |
405 | ||
e2d05745 DDM |
406 | defs="$(runas testuser mktemp --directory "/tmp/test-repart.XXXXXXXXXX")" |
407 | imgs="$(runas testuser mktemp --directory "/var/tmp/test-repart.XXXXXXXXXX")" | |
2b21522e YW |
408 | # shellcheck disable=SC2064 |
409 | trap "rm -rf '$defs' '$imgs'" RETURN | |
410 | ||
ff1b55ff | 411 | runas testuser mkdir -p "$defs/1" |
2b21522e | 412 | |
ff1b55ff | 413 | runas testuser tee "$defs/1/root1.conf" <<EOF |
2b21522e YW |
414 | [Partition] |
415 | Type=swap | |
416 | SizeMaxBytes=32M | |
417 | UUID=7b93d1f2-595d-4ce3-b0b9-837fbd9e63b0 | |
418 | Label=label1 | |
419 | EOF | |
420 | ||
ff1b55ff | 421 | runas testuser mkdir -p "$defs/2" |
2b21522e | 422 | |
ff1b55ff | 423 | runas testuser tee "$defs/2/root2.conf" <<EOF |
2b21522e YW |
424 | [Partition] |
425 | Type=swap | |
426 | SizeMaxBytes=32M | |
427 | UUID=837c3d67-21b3-478e-be82-7e7f83bf96d3 | |
428 | Label=label2 | |
429 | EOF | |
430 | ||
e2d05745 DDM |
431 | output=$(runas testuser systemd-repart --definitions="$defs/1" \ |
432 | --definitions="$defs/2" \ | |
433 | --empty=create \ | |
434 | --size=100M \ | |
435 | --json=pretty \ | |
436 | "$imgs/zzz") | |
2b21522e | 437 | |
71ea8436 | 438 | diff -u <(echo "$output") - <<EOF |
2b21522e YW |
439 | [ |
440 | { | |
441 | "type" : "swap", | |
442 | "label" : "label1", | |
443 | "uuid" : "7b93d1f2-595d-4ce3-b0b9-837fbd9e63b0", | |
d0242ac9 | 444 | "file" : "$defs/1/root1.conf", |
2b21522e YW |
445 | "node" : "$imgs/zzz1", |
446 | "offset" : 1048576, | |
447 | "old_size" : 0, | |
448 | "raw_size" : 33554432, | |
71ea8436 | 449 | "size" : "-> 32.0M", |
2b21522e YW |
450 | "old_padding" : 0, |
451 | "raw_padding" : 0, | |
71ea8436 | 452 | "padding" : "-> 0B", |
2b21522e YW |
453 | "activity" : "create" |
454 | }, | |
455 | { | |
456 | "type" : "swap", | |
457 | "label" : "label2", | |
458 | "uuid" : "837c3d67-21b3-478e-be82-7e7f83bf96d3", | |
d0242ac9 | 459 | "file" : "$defs/2/root2.conf", |
2b21522e YW |
460 | "node" : "$imgs/zzz2", |
461 | "offset" : 34603008, | |
462 | "old_size" : 0, | |
463 | "raw_size" : 33554432, | |
71ea8436 | 464 | "size" : "-> 32.0M", |
2b21522e YW |
465 | "old_padding" : 0, |
466 | "raw_padding" : 0, | |
71ea8436 | 467 | "padding" : "-> 0B", |
2b21522e YW |
468 | "activity" : "create" |
469 | } | |
470 | ] | |
471 | EOF | |
472 | } | |
473 | ||
5996f116 YW |
474 | test_copy_blocks() { |
475 | local defs imgs output | |
476 | ||
e2d05745 DDM |
477 | defs="$(runas testuser mktemp --directory "/tmp/test-repart.XXXXXXXXXX")" |
478 | imgs="$(runas testuser mktemp --directory "/var/tmp/test-repart.XXXXXXXXXX")" | |
5996f116 YW |
479 | # shellcheck disable=SC2064 |
480 | trap "rm -rf '$defs' '$imgs'" RETURN | |
5a3b8640 | 481 | |
5996f116 | 482 | # First, create a disk image and verify its in order |
5a3b8640 | 483 | |
ff1b55ff | 484 | runas testuser tee "$defs/esp.conf" <<EOF |
5a3b8640 LP |
485 | [Partition] |
486 | Type=esp | |
487 | SizeMinBytes=10M | |
488 | Format=vfat | |
489 | EOF | |
490 | ||
ff1b55ff | 491 | runas testuser tee "$defs/usr.conf" <<EOF |
5a3b8640 | 492 | [Partition] |
8e65d93e | 493 | Type=usr-${architecture} |
5a3b8640 LP |
494 | SizeMinBytes=10M |
495 | Format=ext4 | |
496 | ReadOnly=yes | |
497 | EOF | |
498 | ||
ff1b55ff | 499 | runas testuser tee "$defs/root.conf" <<EOF |
5a3b8640 | 500 | [Partition] |
8e65d93e | 501 | Type=root-${architecture} |
5a3b8640 LP |
502 | SizeMinBytes=10M |
503 | Format=ext4 | |
504 | MakeDirectories=/usr /efi | |
505 | EOF | |
506 | ||
e2d05745 DDM |
507 | runas testuser systemd-repart --definitions="$defs" \ |
508 | --empty=create \ | |
509 | --size=auto \ | |
510 | --seed="$seed" \ | |
511 | "$imgs/zzz" | |
5a3b8640 | 512 | |
5996f116 | 513 | output=$(sfdisk --dump "$imgs/zzz") |
5a3b8640 | 514 | |
5996f116 YW |
515 | assert_in "$imgs/zzz1 : start= 2048, size= 20480, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=39107B09-615D-48FB-BA37-C663885FCE67, name=\"esp\"" "$output" |
516 | assert_in "$imgs/zzz2 : start= 22528, size= 20480, type=${root_guid}, uuid=${root_uuid}, name=\"root-${architecture}\", attrs=\"GUID:59\"" "$output" | |
517 | assert_in "$imgs/zzz3 : start= 43008, size= 20480, type=${usr_guid}, uuid=${usr_uuid}, name=\"usr-${architecture}\", attrs=\"GUID:60\"" "$output" | |
5a3b8640 | 518 | |
e2d05745 DDM |
519 | if systemd-detect-virt --quiet --container; then |
520 | echo "Skipping second part of copy blocks tests in container." | |
521 | return | |
522 | fi | |
523 | ||
5996f116 | 524 | # Then, create another image with CopyBlocks=auto |
5a3b8640 | 525 | |
ff1b55ff | 526 | runas testuser tee "$defs/esp.conf" <<EOF |
5a3b8640 LP |
527 | [Partition] |
528 | Type=esp | |
529 | CopyBlocks=auto | |
530 | EOF | |
531 | ||
ff1b55ff | 532 | runas testuser tee "$defs/usr.conf" <<EOF |
5a3b8640 | 533 | [Partition] |
8e65d93e | 534 | Type=usr-${architecture} |
5a3b8640 LP |
535 | ReadOnly=yes |
536 | CopyBlocks=auto | |
537 | EOF | |
538 | ||
ff1b55ff | 539 | runas testuser tee "$defs/root.conf" <<EOF |
5a3b8640 | 540 | [Partition] |
8e65d93e | 541 | Type=root-${architecture} |
5a3b8640 LP |
542 | CopyBlocks=auto |
543 | EOF | |
544 | ||
e2d05745 | 545 | # --image needs root privileges so skip runas testuser here. |
5996f116 YW |
546 | systemd-repart --definitions="$defs" \ |
547 | --empty=create \ | |
548 | --size=auto \ | |
549 | --seed="$seed" \ | |
550 | --image="$imgs/zzz" \ | |
551 | "$imgs/yyy" | |
5a3b8640 | 552 | |
5996f116 YW |
553 | cmp "$imgs/zzz" "$imgs/yyy" |
554 | } | |
5a3b8640 | 555 | |
5996f116 YW |
556 | test_unaligned_partition() { |
557 | local defs imgs output | |
5a3b8640 | 558 | |
e2d05745 DDM |
559 | defs="$(runas testuser mktemp --directory "/tmp/test-repart.XXXXXXXXXX")" |
560 | imgs="$(runas testuser mktemp --directory "/var/tmp/test-repart.XXXXXXXXXX")" | |
5996f116 YW |
561 | # shellcheck disable=SC2064 |
562 | trap "rm -rf '$defs' '$imgs'" RETURN | |
15c59776 | 563 | |
5996f116 | 564 | # Operate on an image with unaligned partition. |
15c59776 | 565 | |
ff1b55ff | 566 | runas testuser tee "$defs/root.conf" <<EOF |
15c59776 | 567 | [Partition] |
8e65d93e | 568 | Type=root-${architecture} |
15c59776 LP |
569 | EOF |
570 | ||
e2d05745 | 571 | runas testuser truncate -s 10g "$imgs/unaligned" |
5996f116 | 572 | sfdisk "$imgs/unaligned" <<EOF |
15c59776 LP |
573 | label: gpt |
574 | ||
575 | start=2048, size=69044 | |
576 | start=71092, size=3591848 | |
577 | EOF | |
578 | ||
e2d05745 DDM |
579 | runas testuser systemd-repart --definitions="$defs" \ |
580 | --seed="$seed" \ | |
581 | --dry-run=no \ | |
582 | "$imgs/unaligned" | |
5996f116 YW |
583 | |
584 | output=$(sfdisk --dump "$imgs/unaligned") | |
15c59776 | 585 | |
5996f116 YW |
586 | assert_in "$imgs/unaligned1 : start= 2048, size= 69044," "$output" |
587 | assert_in "$imgs/unaligned2 : start= 71092, size= 3591848," "$output" | |
588 | assert_in "$imgs/unaligned3 : start= 3662944, size= 17308536, type=${root_guid}, uuid=${root_uuid}, name=\"root-${architecture}\", attrs=\"GUID:59\"" "$output" | |
589 | } | |
590 | ||
591 | test_issue_21817() { | |
592 | local defs imgs output | |
15c59776 | 593 | |
5996f116 | 594 | # testcase for #21817 |
15c59776 | 595 | |
e2d05745 DDM |
596 | defs="$(runas testuser mktemp --directory "/tmp/test-repart.XXXXXXXXXX")" |
597 | imgs="$(runas testuser mktemp --directory "/var/tmp/test-repart.XXXXXXXXXX")" | |
5996f116 YW |
598 | # shellcheck disable=SC2064 |
599 | trap "rm -rf '$defs' '$imgs'" RETURN | |
15c59776 | 600 | |
ff1b55ff | 601 | runas testuser tee "$defs/test.conf" <<EOF |
5996f116 YW |
602 | [Partition] |
603 | Type=root | |
604 | EOF | |
605 | ||
e2d05745 | 606 | runas testuser truncate -s 100m "$imgs/21817.img" |
5996f116 | 607 | sfdisk "$imgs/21817.img" <<EOF |
70a3ce51 YW |
608 | label: gpt |
609 | ||
610 | size=50M, type=${root_guid} | |
611 | , | |
612 | EOF | |
71bb6048 | 613 | |
e2d05745 DDM |
614 | runas testuser systemd-repart --pretty=yes \ |
615 | --definitions "$imgs" \ | |
616 | --seed="$seed" \ | |
617 | --dry-run=no \ | |
618 | "$imgs/21817.img" | |
71bb6048 | 619 | |
5996f116 | 620 | output=$(sfdisk --dump "$imgs/21817.img") |
71bb6048 | 621 | |
5996f116 YW |
622 | assert_in "$imgs/21817.img1 : start= 2048, size= 102400, type=${root_guid}," "$output" |
623 | # Accept both unpadded (pre-v2.38 util-linux) and padded (v2.38+ util-linux) sizes | |
624 | assert_in "$imgs/21817.img2 : start= 104448, size= (100319| 98304)," "$output" | |
625 | } | |
2cd341af | 626 | |
3b19e160 YW |
627 | test_issue_24553() { |
628 | local defs imgs output | |
629 | ||
630 | # testcase for #24553 | |
631 | ||
e2d05745 DDM |
632 | defs="$(runas testuser mktemp --directory "/tmp/test-repart.XXXXXXXXXX")" |
633 | imgs="$(runas testuser mktemp --directory "/var/tmp/test-repart.XXXXXXXXXX")" | |
3b19e160 YW |
634 | # shellcheck disable=SC2064 |
635 | trap "rm -rf '$defs' '$imgs'" RETURN | |
636 | ||
ff1b55ff | 637 | runas testuser tee "$defs/root.conf" <<EOF |
3b19e160 YW |
638 | [Partition] |
639 | Type=root | |
640 | SizeMinBytes=10G | |
641 | SizeMaxBytes=120G | |
642 | EOF | |
643 | ||
ff1b55ff | 644 | runas testuser tee "$imgs/partscript" <<EOF |
3b19e160 YW |
645 | label: gpt |
646 | label-id: C9FFE979-A415-C449-B729-78C7AA664B10 | |
647 | unit: sectors | |
648 | first-lba: 40 | |
649 | ||
650 | start=40, size=524288, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=F2E89C8A-DC5D-4C4C-A29C-6CFB643B74FD, name="ESP System Partition" | |
651 | start=524328, size=14848000, type=${root_guid}, uuid=${root_uuid}, name="root-${architecture}" | |
652 | EOF | |
653 | ||
654 | # 1. Operate on a small image compared with SizeMinBytes=. | |
e2d05745 | 655 | runas testuser truncate -s 8g "$imgs/zzz" |
3b19e160 YW |
656 | sfdisk "$imgs/zzz" <"$imgs/partscript" |
657 | ||
658 | # This should fail, but not trigger assertions. | |
e2d05745 DDM |
659 | assert_rc 1 runas testuser systemd-repart --definitions="$defs" \ |
660 | --seed="$seed" \ | |
661 | --dry-run=no \ | |
662 | "$imgs/zzz" | |
3b19e160 YW |
663 | |
664 | output=$(sfdisk --dump "$imgs/zzz") | |
665 | assert_in "$imgs/zzz2 : start= 524328, size= 14848000, type=${root_guid}, uuid=${root_uuid}, name=\"root-${architecture}\"" "$output" | |
666 | ||
667 | # 2. Operate on an larger image compared with SizeMinBytes=. | |
668 | rm -f "$imgs/zzz" | |
e2d05745 | 669 | runas testuser truncate -s 12g "$imgs/zzz" |
3b19e160 YW |
670 | sfdisk "$imgs/zzz" <"$imgs/partscript" |
671 | ||
672 | # This should succeed. | |
e2d05745 DDM |
673 | runas testuser systemd-repart --definitions="$defs" \ |
674 | --seed="$seed" \ | |
675 | --dry-run=no \ | |
676 | "$imgs/zzz" | |
3b19e160 YW |
677 | |
678 | output=$(sfdisk --dump "$imgs/zzz") | |
679 | assert_in "$imgs/zzz2 : start= 524328, size= 24641456, type=${root_guid}, uuid=${root_uuid}, name=\"root-${architecture}\"" "$output" | |
680 | ||
681 | # 3. Multiple partitions with Priority= (small disk) | |
ff1b55ff | 682 | runas testuser tee "$defs/root.conf" <<EOF |
3b19e160 YW |
683 | [Partition] |
684 | Type=root | |
685 | SizeMinBytes=10G | |
686 | SizeMaxBytes=120G | |
687 | Priority=100 | |
688 | EOF | |
689 | ||
ff1b55ff | 690 | runas testuser tee "$defs/usr.conf" <<EOF |
3b19e160 YW |
691 | [Partition] |
692 | Type=usr | |
693 | SizeMinBytes=10M | |
694 | Priority=10 | |
695 | EOF | |
696 | ||
697 | rm -f "$imgs/zzz" | |
e2d05745 | 698 | runas testuser truncate -s 8g "$imgs/zzz" |
3b19e160 YW |
699 | sfdisk "$imgs/zzz" <"$imgs/partscript" |
700 | ||
701 | # This should also succeed, but root is not extended. | |
e2d05745 DDM |
702 | runas testuser systemd-repart --definitions="$defs" \ |
703 | --seed="$seed" \ | |
704 | --dry-run=no \ | |
705 | "$imgs/zzz" | |
3b19e160 YW |
706 | |
707 | output=$(sfdisk --dump "$imgs/zzz") | |
708 | assert_in "$imgs/zzz2 : start= 524328, size= 14848000, type=${root_guid}, uuid=${root_uuid}, name=\"root-${architecture}\"" "$output" | |
709 | assert_in "$imgs/zzz3 : start= 15372328, size= 1404848, type=${usr_guid}, uuid=${usr_uuid}, name=\"usr-${architecture}\", attrs=\"GUID:59\"" "$output" | |
710 | ||
711 | # 4. Multiple partitions with Priority= (large disk) | |
712 | rm -f "$imgs/zzz" | |
e2d05745 | 713 | runas testuser truncate -s 12g "$imgs/zzz" |
3b19e160 YW |
714 | sfdisk "$imgs/zzz" <"$imgs/partscript" |
715 | ||
716 | # This should also succeed, and root is extended. | |
e2d05745 DDM |
717 | runas testuser systemd-repart --definitions="$defs" \ |
718 | --seed="$seed" \ | |
719 | --dry-run=no \ | |
720 | "$imgs/zzz" | |
3b19e160 YW |
721 | |
722 | output=$(sfdisk --dump "$imgs/zzz") | |
723 | assert_in "$imgs/zzz2 : start= 524328, size= 20971520, type=${root_guid}, uuid=${root_uuid}, name=\"root-${architecture}\"" "$output" | |
724 | assert_in "$imgs/zzz3 : start= 21495848, size= 3669936, type=${usr_guid}, uuid=${usr_uuid}, name=\"usr-${architecture}\", attrs=\"GUID:59\"" "$output" | |
725 | } | |
726 | ||
11749b61 DDM |
727 | test_zero_uuid() { |
728 | local defs imgs output | |
729 | ||
e2d05745 DDM |
730 | defs="$(runas testuser mktemp --directory "/tmp/test-repart.XXXXXXXXXX")" |
731 | imgs="$(runas testuser mktemp --directory "/var/tmp/test-repart.XXXXXXXXXX")" | |
11749b61 DDM |
732 | # shellcheck disable=SC2064 |
733 | trap "rm -rf '$defs' '$imgs'" RETURN | |
734 | ||
735 | # Test image with zero UUID. | |
736 | ||
ff1b55ff | 737 | runas testuser tee "$defs/root.conf" <<EOF |
11749b61 DDM |
738 | [Partition] |
739 | Type=root-${architecture} | |
740 | UUID=null | |
741 | EOF | |
742 | ||
e2d05745 DDM |
743 | runas testuser systemd-repart --definitions="$defs" \ |
744 | --seed="$seed" \ | |
745 | --dry-run=no \ | |
746 | --empty=create \ | |
747 | --size=auto \ | |
748 | "$imgs/zero" | |
11749b61 DDM |
749 | |
750 | output=$(sfdisk --dump "$imgs/zero") | |
751 | ||
752 | assert_in "$imgs/zero1 : start= 2048, size= 20480, type=${root_guid}, uuid=00000000-0000-0000-0000-000000000000" "$output" | |
753 | } | |
754 | ||
b5b7879a DDM |
755 | test_verity() { |
756 | local defs imgs output | |
757 | ||
e2d05745 DDM |
758 | defs="$(runas testuser mktemp --directory "/tmp/test-repart.XXXXXXXXXX")" |
759 | imgs="$(runas testuser mktemp --directory "/var/tmp/test-repart.XXXXXXXXXX")" | |
b5b7879a DDM |
760 | # shellcheck disable=SC2064 |
761 | trap "rm -rf '$defs' '$imgs'" RETURN | |
762 | ||
ff1b55ff | 763 | runas testuser tee "$defs/verity-data.conf" <<EOF |
b5b7879a DDM |
764 | [Partition] |
765 | Type=root-${architecture} | |
766 | CopyFiles=${defs} | |
767 | Verity=data | |
768 | VerityMatchKey=root | |
769 | EOF | |
770 | ||
ff1b55ff | 771 | runas testuser tee "$defs/verity-hash.conf" <<EOF |
b5b7879a DDM |
772 | [Partition] |
773 | Type=root-${architecture}-verity | |
774 | Verity=hash | |
775 | VerityMatchKey=root | |
776 | EOF | |
777 | ||
ff1b55ff | 778 | runas testuser tee "$defs/verity-sig.conf" <<EOF |
b456191d DDM |
779 | [Partition] |
780 | Type=root-${architecture}-verity-sig | |
781 | Verity=signature | |
782 | VerityMatchKey=root | |
783 | EOF | |
784 | ||
785 | # Unfortunately OpenSSL insists on reading some config file, hence provide one with mostly placeholder contents | |
7a17e41d | 786 | runas testuser tee >"$defs/verity.openssl.cnf" <<EOF |
b456191d DDM |
787 | [ req ] |
788 | prompt = no | |
789 | distinguished_name = req_distinguished_name | |
790 | ||
791 | [ req_distinguished_name ] | |
792 | C = DE | |
793 | ST = Test State | |
794 | L = Test Locality | |
795 | O = Org Name | |
796 | OU = Org Unit Name | |
797 | CN = Common Name | |
798 | emailAddress = test@email.com | |
799 | EOF | |
800 | ||
e2d05745 DDM |
801 | runas testuser openssl req -config "$defs/verity.openssl.cnf" \ |
802 | -new -x509 \ | |
803 | -newkey rsa:1024 \ | |
804 | -keyout "$defs/verity.key" \ | |
805 | -out "$defs/verity.crt" \ | |
806 | -days 365 \ | |
807 | -nodes | |
b456191d DDM |
808 | |
809 | mkdir -p /run/verity.d | |
810 | ln -s "$defs/verity.crt" /run/verity.d/ok.crt | |
811 | ||
e2d05745 DDM |
812 | output=$(runas testuser systemd-repart --definitions="$defs" \ |
813 | --seed="$seed" \ | |
814 | --dry-run=no \ | |
815 | --empty=create \ | |
816 | --size=auto \ | |
817 | --json=pretty \ | |
818 | --private-key="$defs/verity.key" \ | |
819 | --certificate="$defs/verity.crt" \ | |
820 | "$imgs/verity") | |
b5b7879a | 821 | |
2ecc7a5b DDM |
822 | drh=$(jq -r ".[] | select(.type == \"root-${architecture}\") | .roothash" <<< "$output") |
823 | hrh=$(jq -r ".[] | select(.type == \"root-${architecture}-verity\") | .roothash" <<< "$output") | |
824 | srh=$(jq -r ".[] | select(.type == \"root-${architecture}-verity-sig\") | .roothash" <<< "$output") | |
825 | ||
826 | assert_eq "$drh" "$hrh" | |
827 | assert_eq "$hrh" "$srh" | |
b5b7879a | 828 | |
63b130a6 | 829 | # Check that we can dissect, mount and unmount a repart verity image. (and that the image UUID is deterministic) |
b5b7879a | 830 | |
e2d05745 DDM |
831 | if systemd-detect-virt --quiet --container; then |
832 | echo "Skipping verity test dissect part in container." | |
833 | return | |
834 | fi | |
835 | ||
2ecc7a5b DDM |
836 | systemd-dissect "$imgs/verity" --root-hash "$drh" |
837 | systemd-dissect "$imgs/verity" --root-hash "$drh" --json=short | grep -q '"imageUuid":"1d2ce291-7cce-4f7d-bc83-fdb49ad74ebd"' | |
838 | systemd-dissect "$imgs/verity" --root-hash "$drh" -M "$imgs/mnt" | |
b5b7879a DDM |
839 | systemd-dissect -U "$imgs/mnt" |
840 | } | |
841 | ||
bd69c2a8 DDM |
842 | test_issue_24786() { |
843 | local defs imgs root output | |
844 | ||
e2d05745 DDM |
845 | defs="$(runas testuser mktemp --directory "/tmp/test-repart.XXXXXXXXXX")" |
846 | imgs="$(runas testuser mktemp --directory "/var/tmp/test-repart.XXXXXXXXXX")" | |
847 | root="$(runas testuser mktemp --directory "/var/tmp/test-repart.XXXXXXXXXX")" | |
bd69c2a8 DDM |
848 | # shellcheck disable=SC2064 |
849 | trap "rm -rf '$defs' '$imgs' '$root'" RETURN | |
850 | ||
ff1b55ff DDM |
851 | runas testuser touch "$root/abc" |
852 | runas testuser mkdir "$root/usr" | |
853 | runas testuser touch "$root/usr/def" | |
bd69c2a8 | 854 | |
ff1b55ff | 855 | runas testuser tee "$defs/00-root.conf" <<EOF |
bd69c2a8 DDM |
856 | [Partition] |
857 | Type=root-${architecture} | |
858 | CopyFiles=/ | |
859 | EOF | |
860 | ||
ff1b55ff | 861 | runas testuser tee "$defs/10-usr.conf" <<EOF |
bd69c2a8 DDM |
862 | [Partition] |
863 | Type=usr-${architecture} | |
864 | CopyFiles=/usr:/ | |
865 | EOF | |
866 | ||
e2d05745 DDM |
867 | output=$(runas testuser systemd-repart --definitions="$defs" \ |
868 | --seed="$seed" \ | |
869 | --dry-run=no \ | |
870 | --empty=create \ | |
871 | --size=auto \ | |
872 | --json=pretty \ | |
873 | --root="$root" \ | |
874 | "$imgs/zzz") | |
875 | ||
876 | if systemd-detect-virt --quiet --container; then | |
877 | echo "Skipping issue 24786 test loop/mount parts in container." | |
878 | return | |
879 | fi | |
bd69c2a8 DDM |
880 | |
881 | loop=$(losetup -P --show -f "$imgs/zzz") | |
882 | udevadm wait --timeout 60 --settle "${loop:?}" | |
883 | ||
884 | mkdir "$imgs/mnt" | |
885 | mount -t ext4 "${loop}p1" "$imgs/mnt" | |
886 | assert_rc 0 ls "$imgs/mnt/abc" | |
887 | assert_rc 2 ls "$imgs/mnt/usr" | |
888 | mkdir "$imgs/mnt/usr" | |
889 | mount -t ext4 "${loop}p2" "$imgs/mnt/usr" | |
890 | assert_rc 0 ls "$imgs/mnt/usr/def" | |
891 | ||
892 | umount -R "$imgs/mnt" | |
893 | losetup -d "$loop" | |
894 | } | |
895 | ||
14697c41 DDM |
896 | test_minimize() { |
897 | local defs imgs output | |
898 | ||
899 | if systemd-detect-virt --quiet --container; then | |
900 | echo "Skipping minimize test in container." | |
901 | return | |
902 | fi | |
903 | ||
904 | defs="$(mktemp --directory "/tmp/test-repart.XXXXXXXXXX")" | |
905 | imgs="$(mktemp --directory "/var/tmp/test-repart.XXXXXXXXXX")" | |
906 | # shellcheck disable=SC2064 | |
907 | trap "rm -rf '$defs' '$imgs'" RETURN | |
908 | ||
09e917ea | 909 | for format in ext4 vfat erofs; do |
14697c41 DDM |
910 | if ! command -v "mkfs.$format" >/dev/null; then |
911 | continue | |
912 | fi | |
913 | ||
ff1b55ff | 914 | tee "$defs/root-$format.conf" <<EOF |
14697c41 DDM |
915 | [Partition] |
916 | Type=root-${architecture} | |
917 | Format=${format} | |
918 | CopyFiles=${defs} | |
640c02d5 | 919 | Minimize=guess |
14697c41 DDM |
920 | EOF |
921 | done | |
922 | ||
923 | if ! command -v mksquashfs >/dev/null; then | |
ff1b55ff | 924 | tee "$defs/root-squashfs.conf" <<EOF |
14697c41 DDM |
925 | [Partition] |
926 | Type=root-${architecture} | |
927 | Format=squashfs | |
928 | CopyFiles=${defs} | |
640c02d5 | 929 | Minimize=best |
14697c41 DDM |
930 | EOF |
931 | fi | |
932 | ||
933 | output=$(systemd-repart --definitions="$defs" \ | |
934 | --seed="$seed" \ | |
935 | --dry-run=no \ | |
936 | --empty=create \ | |
937 | --size=auto \ | |
938 | --json=pretty \ | |
939 | "$imgs/zzz") | |
940 | ||
941 | # Check that we can dissect, mount and unmount a minimized image. | |
942 | ||
943 | systemd-dissect "$imgs/zzz" | |
944 | systemd-dissect "$imgs/zzz" -M "$imgs/mnt" | |
945 | systemd-dissect -U "$imgs/mnt" | |
946 | } | |
947 | ||
5996f116 YW |
948 | test_sector() { |
949 | local defs imgs output loop | |
950 | local start size ratio | |
951 | local sector="${1?}" | |
952 | ||
76097112 YW |
953 | if systemd-detect-virt --quiet --container; then |
954 | echo "Skipping sector size tests in container." | |
955 | return | |
956 | fi | |
957 | ||
5996f116 YW |
958 | defs="$(mktemp --directory "/tmp/test-repart.XXXXXXXXXX")" |
959 | imgs="$(mktemp --directory "/var/tmp/test-repart.XXXXXXXXXX")" | |
960 | # shellcheck disable=SC2064 | |
961 | trap "rm -rf '$defs' '$imgs'" RETURN | |
962 | ||
ff1b55ff | 963 | tee "$defs/a.conf" <<EOF |
2cd341af LP |
964 | [Partition] |
965 | Type=root | |
966 | SizeMaxBytes=15M | |
967 | SizeMinBytes=15M | |
968 | EOF | |
ff1b55ff | 969 | tee "$defs/b.conf" <<EOF |
2cd341af LP |
970 | [Partition] |
971 | Type=linux-generic | |
972 | Weight=250 | |
973 | EOF | |
974 | ||
ff1b55ff | 975 | tee "$defs/c.conf" <<EOF |
2cd341af LP |
976 | [Partition] |
977 | Type=linux-generic | |
978 | Weight=750 | |
979 | EOF | |
980 | ||
5996f116 YW |
981 | truncate -s 100m "$imgs/$sector.img" |
982 | loop=$(losetup -b "$sector" -P --show -f "$imgs/$sector.img" ) | |
983 | udevadm wait --timeout 60 --settle "${loop:?}" | |
e2d05745 DDM |
984 | # This operates on a loop device which we don't support doing without root privileges so we skip runas |
985 | # here. | |
5996f116 YW |
986 | systemd-repart --pretty=yes \ |
987 | --definitions="$defs" \ | |
988 | --seed="$seed" \ | |
989 | --empty=require \ | |
990 | --dry-run=no \ | |
991 | "$loop" | |
992 | ||
993 | sfdisk --verify "$loop" | |
994 | output=$(sfdisk --dump "$loop") | |
995 | losetup -d "$loop" | |
996 | ||
997 | ratio=$(( sector / 512 )) | |
998 | start=$(( 2048 / ratio )) | |
999 | size=$(( 30720 / ratio )) | |
1000 | assert_in "${loop}p1 : start= *${start}, size= *${size}, type=${root_guid}, uuid=${root_uuid}, name=\"root-${architecture}\", attrs=\"GUID:59\"" "$output" | |
1001 | start=$(( start + size )) | |
1002 | size=$(( 42992 / ratio )) | |
1003 | assert_in "${loop}p2 : start= *${start}, size= *${size}, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=DF71F5E3-080A-4D16-824B-18591B881380, name=\"linux-generic\"" "$output" | |
1004 | start=$(( start + size )) | |
1005 | size=$(( 129000 / ratio )) | |
1006 | assert_in "${loop}p3 : start= *${start}, size= *${size}, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=DB081670-07AE-48CA-9F5E-813D5E40B976, name=\"linux-generic-2\"" "$output" | |
2cd341af LP |
1007 | } |
1008 | ||
2b21522e YW |
1009 | test_basic |
1010 | test_dropin | |
1011 | test_multiple_definitions | |
5996f116 YW |
1012 | test_copy_blocks |
1013 | test_unaligned_partition | |
1014 | test_issue_21817 | |
3b19e160 | 1015 | test_issue_24553 |
11749b61 | 1016 | test_zero_uuid |
b5b7879a | 1017 | test_verity |
bd69c2a8 | 1018 | test_issue_24786 |
14697c41 | 1019 | test_minimize |
5996f116 | 1020 | |
2cd341af LP |
1021 | # Valid block sizes on the Linux block layer are >= 512 and <= PAGE_SIZE, and |
1022 | # must be powers of 2. Which leaves exactly four different ones to test on | |
1023 | # typical hardware | |
5996f116 YW |
1024 | test_sector 512 |
1025 | test_sector 1024 | |
1026 | test_sector 2048 | |
1027 | test_sector 4096 | |
2cd341af | 1028 | |
5a3b8640 LP |
1029 | echo OK >/testok |
1030 | ||
1031 | exit 0 |