Debian Codegraph @

test/units/TEST-81-GENERATORS.fstab-generator.sh

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash
2 # SPDX-License-Identifier: LGPL-2.1-or-later
3 # shellcheck disable=SC2235,SC2233
4 set -eux
5 set -o pipefail
6
7 # shellcheck source=test/units/generator-utils.sh
8 . "$(dirnamescip-shell system . . dirname. "$0")/generator-utils.sh"
9
10 GENERATOR_BIN="/usr/lib/systemd/system-generators/systemd-fstab-generatorscip-shell filesystem . . `/usr/lib/systemd/system-generators/systemd-fstab-generator`."
11 NETWORK_FS_RX="^(afs|ceph|cifs|gfs|gfs2|ncp|ncpfs|nfs|nfs4|ocfs2|orangefs|pvfs2|smb3|smbfs|davfs|glusterfs|lustre|sshfs)$"
12 OUT_DIR="$(mktempscip-shell system . . mktemp. -d /tmp/fstab-generator.XXXscip-shell filesystem . . `/tmp/fstab-generator.XXX`.)"
13 FSTAB="$(mktempscip-shell system . . mktemp.)"
14
15 at_exitscip-shell shell systemd 261~rc3-1 at_exit().() {
16 mountpointscip-shell system . . mountpoint. -q /proc/cmdlinescip-shell filesystem . . `/proc/cmdline`. && umountscip-shell system . . umount. /proc/cmdlinescip-shell filesystem . . `/proc/cmdline`.
17 rmscip-shell system . . rm. -fr "${OUT_DIR:?}" "${FSTAB:?}"
18 }
19
20 trap at_exit EXIT
21
22 testscip-shell system . . test. -x "${GENERATOR_BIN:?}"
23
24 FSTAB_GENERAL=(
25 # Valid entries
26 "/dev/test2 /nofail ext4 nofail 0 0"
27 "/dev/test3 /regular btrfs defaults 0 0"
28 "/dev/test4 /x-systemd.requires xfs x-systemd.requires=foo.service 0 0"
29 "/dev/test5 /x-systemd.before-after xfs x-systemd.before=foo.service,x-systemd.after=bar.mount 0 0"
30 "/dev/test6 /x-systemd.wanted-required-by xfs x-systemd.wanted-by=foo.service,x-systemd.required-by=bar.device 0 0"
31 "/dev/test7 /x-systemd.requires-mounts-for xfs x-systemd.requires-mounts-for=/foo/bar/baz 0 0"
32 "/dev/test8 /x-systemd.automount-idle-timeout vfat x-systemd.automount,x-systemd.idle-timeout=50s 0 0"
33 "/dev/test9 /x-systemd.makefs xfs x-systemd.makefs 0 0"
34 "/dev/test10 /x-systemd.growfs xfs x-systemd.growfs 0 0"
35 "/dev/test11 /_netdev ext4 defaults,_netdev 0 0"
36 "/dev/test12 /_rwonly ext4 x-systemd.rw-only 0 0"
37 "/dev/test13 /chaos1 zfs x-systemd.rw-only,x-systemd.requires=hello.service,x-systemd.after=my.device 0 0"
38 "/dev/test14 /chaos2 zfs x.systemd.wanted-by=foo.service,x-systemd.growfs,x-systemd.makefs 0 0"
39 "/dev/test15 /fstype/auto auto defaults 0 0"
40 "/dev/test16 /fsck/me ext4 defaults 0 1"
41 "/dev/test17 /also/fsck/me ext4 defaults,x-systemd.requires-mounts-for=/var/lib/foo 0 99"
42 "/dev/test18 /swap swap defaults 0 0"
43 "/dev/test19 /swap/makefs swap defaults,x-systemd.makefs 0 0"
44 "/dev/test20 /var xfs defaults,x-systemd.device-timeout=1h 0 0"
45 "/dev/test21 /usr ext4 defaults 0 1"
46 "/dev/test22 /initrd/mount ext2 defaults,x-systemd.rw-only,x-initrd.mount 0 1"
47 "/dev/test23 /initrd/mount/nofail ext3 defaults,nofail,x-initrd.mount 0 1"
48 "/dev/test24 /initrd/mount/deps ext4 x-initrd.mount,x-systemd.before=early.service,x-systemd.after=late.service 0 1"
49 "/dev/test25 /x-systemd.validatefs xfs x-systemd.validatefs 0 0"
50
51 # Incomplete, but valid entries
52 "/dev/incomplete1 /incomplete1 ext4"
53 "/dev/incomplete2 /incomplete2 ext4 defaults"
54 "/dev/incomplete3 /incomplete3 ext4 defaults 0"
55
56 # Remote filesystems
57 "/dev/remote1 /nfs nfs bg 0 0"
58 "/dev/remote2 /nfs4 nfs4 bg 0 0"
59 "bar.tld:/store /remote/storage nfs ro,x-systemd.wanted-by=store.service 0 0"
60 "[email protected]:/remote/dir /remote/top-secret sshfs rw,x-systemd.before=naughty.service 0 0"
61 "foo.tld:/hello /hello/world ceph defaults 0 0"
62 "//192.168.0.1/storage /cifs-storage cifs automount,nofail 0 0"
63 )
64
65 FSTAB_GENERAL_ROOT=(
66 # rootfs with bunch of options we should ignore and fsck enabled
67 "/dev/test1 / ext4 noauto,nofail,x-systemd.automount,x-systemd.wanted-by=foo,x-systemd.required-by=bar 0 1"
68 "${FSTAB_GENERAL[@]}"
69 )
70
71 FSTAB_MINIMAL=(
72 "/dev/loop1 /foo/bar ext3 defaults 0 0"
73 )
74
75 FSTAB_DUPLICATE=(
76 "/dev/dup1 / ext4 defaults 0 1"
77 "/dev/dup2 / ext4 defaults,x-systemd.requires=foo.mount 0 2"
78 )
79
80 FSTAB_INVALID=(
81 # Ignored entries
82 "/dev/ignored1 /sys/fs/cgroup/foo ext4 defaults 0 0"
83 "/dev/ignored2 /sys/fs/selinux ext4 defaults 0 0"
84 "/dev/ignored3 /dev/console ext4 defaults 0 0"
85 "/dev/ignored4 /proc/kmsg ext4 defaults 0 0"
86 "/dev/ignored5 /proc/sys ext4 defaults 0 0"
87 "/dev/ignored6 /proc/sys/kernel/random/boot_id ext4 defaults 0 0"
88 "/dev/ignored7 /run/host ext4 defaults 0 0"
89 "/dev/ignored8 /run/host/foo ext4 defaults 0 0"
90 "/dev/ignored9 /autofs autofs defaults 0 0"
91 "/dev/invalid1 not-a-path ext4 defaults 0 0"
92 ""
93 "/dev/invalid1"
94 " "
95 "\\"
96 "$"
97 )
98
99 check_fstab_mount_unitsscip-shell shell systemd 261~rc3-1 check_fstab_mount_units().() {
100 local what where fstype opts passno unit
101 local item opt split_options filtered_options supp service device arg
102 local array_name="${1:?}"
103 local out_dir="${2:?}/normal"
104 # Get a reference to the array from its name
105 local -n fstab_entries="$array_name"
106
107 # Running the checks in a container is pretty much useless, since we don't
108 # generate any mounts, but don't skip the whole test to test the "skip"
109 # paths as well
110 in_container && return 0
111
112 for item in "${fstab_entries[@]}"; do
113 # Don't use a pipe here, as it would make the variables out of scope
114 read -r what where fstype opts _ passno <<< "$item"
115
116 # Skip non-initrd mounts in initrd
117 if in_initrd_host && ! [[ "$opts" =~ x-initrd.mount ]]; then
118 continue
119 fi
120
121 if [[ "$fstype" == swap ]]; then
122 unit="$(systemd-escape --suffix=swap --path "${what:?}")"
123 catscip-shell system . . cat. "$out_dir/$unit"
124
125 grepscip-shell system . . grep. -qE "^What=$what$" "$out_dir/$unit"
126 if [[ "$opts" != defaults ]]; then
127 grepscip-shell system . . grep. -qE "^Options=$opts$" "$out_dir/$unit"
128 fi
129
130 if [[ "$opts" =~ x-systemd.makefs ]]; then
131 service="$(systemd-escape [email protected] --path "$what")"
132 testscip-shell system . . test. -e "$out_dir/$service"
133 fi
134
135 continue
136 fi
137
138 # If we're parsing host's fstab in initrd, prefix all mount targets
139 # with /sysroot
140 in_initrd_host && where="/sysroot${where:?}"
141 unit="$(systemd-escape --suffix=mount --path "${where:?}")"
142 catscip-shell system . . cat. "$out_dir/$unit"
143
144 # Check the general stuff
145 grepscip-shell system . . grep. -qE "^What=$what$" "$out_dir/$unit"
146 grepscip-shell system . . grep. -qE "^Where=$where$" "$out_dir/$unit"
147 if [[ -n "$fstype" ]] && [[ "$fstype" != auto ]]; then
148 grepscip-shell system . . grep. -qE "^Type=$fstype$" "$out_dir/$unit"
149 fi
150 if [[ -n "$opts" ]] && [[ "$opts" != defaults ]]; then
151 # Some options are not propagated to the generated unit
152 if [[ "$where" == / || "$where" == /usr ]]; then
153 filtered_options="$(opt_filter "$opts" "(noauto|nofail|x-systemd.(wanted-by=|required-by=|automount|device-timeout=))")"
154 else
155 filtered_options="$(opt_filter "$opts" "^x-systemd.device-timeout=")"
156 fi
157
158 if [[ "${filtered_options[*]}" != defaults ]]; then
159 grepscip-shell system . . grep. -qE "^Options=.*$filtered_options.*$" "$out_dir/$unit"
160 fi
161 fi
162
163 if ! [[ "$opts" =~ (noauto|x-systemd.(wanted-by=|required-by=|automount)) ]]; then
164 # We don't create the Requires=/Wants= symlinks for noauto/automount mounts
165 # and for mounts that use x-systemd.wanted-by=/required-by=
166 if in_initrd_host; then
167 if [[ "$where" == / ]] || ! [[ "$opts" =~ nofail ]]; then
168 link_eq "$out_dir/initrd-fs.target.requires/$unit" "../$unit"
169 else
170 link_eq "$out_dir/initrd-fs.target.wants/$unit" "../$unit"
171 fi
172 elif [[ "$fstype" =~ $NETWORK_FS_RX || "$opts" =~ _netdev ]]; then
173 # Units with network filesystems should have a Requires= dependency
174 # on the remote-fs.target, unless they use nofail or are an nfs "bg"
175 # mounts, in which case the dependency is downgraded to Wants=
176 if [[ "$opts" =~ nofail ]] || [[ "$fstype" =~ ^(nfs|nfs4) && "$opts" =~ bg ]]; then
177 link_eq "$out_dir/remote-fs.target.wants/$unit" "../$unit"
178 else
179 link_eq "$out_dir/remote-fs.target.requires/$unit" "../$unit"
180 fi
181 else
182 # Similarly, local filesystems should have a Requires= dependency on
183 # the local-fs.target, unless they use nofail, in which case the
184 # dependency is downgraded to Wants=. Rootfs is a special case,
185 # since we always ignore nofail there
186 if [[ "$where" == / ]] || ! [[ "$opts" =~ nofail ]]; then
187 link_eq "$out_dir/local-fs.target.requires/$unit" "../$unit"
188 else
189 link_eq "$out_dir/local-fs.target.wants/$unit" "../$unit"
190 fi
191 fi
192 fi
193
194 if [[ "${passno:=0}" -ne 0 ]]; then
195 # Generate [email protected] dependencies, if applicable
196 if in_initrd && [[ "$where" == / || "$where" == /usr ]]; then
197 continue
198 fi
199
200 if [[ "$where" == / ]]; then
201 link_endswith "$out_dir/local-fs.target.wants/systemd-fsck-root.service" "/lib/systemd/system/systemd-fsck-root.servicescip-shell filesystem . . `/lib/systemd/system/systemd-fsck-root.service`."
202 else
203 service="$(systemd-escape [email protected] --path "$what")"
204 grepscip-shell system . . grep. -qE "^After=$service$" "$out_dir/$unit"
205 if [[ "$where" == /usr ]]; then
206 grepscip-shell system . . grep. -qE "^Wants=$service$" "$out_dir/$unit"
207 else
208 grepscip-shell system . . grep. -qE "^Requires=$service$" "$out_dir/$unit"
209 fi
210 fi
211 fi
212
213 # Check various x-systemd options
214 #
215 # First, split them into an array to make splitting them even further
216 # easier
217 IFS="," read -ra split_options <<< "$opts"
218 # and process them one by one.
219 #
220 # Note: the "machinery" below might (and probably does) miss some
221 # combinations of supported options, so tread carefully
222 for opt in "${split_options[@]}"; do
223 if [[ "$opt" =~ ^x-systemd.requires= ]]; then
224 service="$(opt_get_arg "$opt")"
225 grepscip-shell system . . grep. -qE "^Requires=$service$" "$out_dir/$unit"
226 grepscip-shell system . . grep. -qE "^After=$service$" "$out_dir/$unit"
227 elif [[ "$opt" =~ ^x-systemd.before= ]]; then
228 service="$(opt_get_arg "$opt")"
229 grepscip-shell system . . grep. -qE "^Before=$service$" "$out_dir/$unit"
230 elif [[ "$opt" =~ ^x-systemd.after= ]]; then
231 service="$(opt_get_arg "$opt")"
232 grepscip-shell system . . grep. -qE "^After=$service$" "$out_dir/$unit"
233 elif [[ "$opt" =~ ^x-systemd.wanted-by= ]]; then
234 service="$(opt_get_arg "$opt")"
235 if [[ "$where" == / ]]; then
236 # This option is ignored for rootfs mounts
237 (! link_eq "$out_dir/$service.wants/$unit" "../$unit")
238 else
239 link_eq "$out_dir/$service.wants/$unit" "../$unit"
240 fi
241 elif [[ "$opt" =~ ^x-systemd.required-by= ]]; then
242 service="$(opt_get_arg "$opt")"
243 if [[ "$where" == / ]]; then
244 # This option is ignored for rootfs mounts
245 (! link_eq "$out_dir/$service.requires/$unit" "../$unit")
246 else
247 link_eq "$out_dir/$service.requires/$unit" "../$unit"
248 fi
249 elif [[ "$opt" =~ ^x-systemd.requires-mounts-for= ]]; then
250 arg="$(opt_get_arg "$opt")"
251 grepscip-shell system . . grep. -qE "^RequiresMountsFor=$arg$" "$out_dir/$unit"
252 elif [[ "$opt" == x-systemd.device-bound ]]; then
253 # This is implied for fstab mounts
254 :
255 elif [[ "$opt" == x-systemd.automount ]]; then
256 # The $unit should have an accompanying automount unit
257 supp="$(systemd-escape --suffix=automount --path "$where")"
258 if [[ "$where" == / ]]; then
259 # This option is ignored for rootfs mounts
260 testscip-shell system . . test. ! -e "$out_dir/$supp"
261 (! link_eq "$out_dir/local-fs.target.requires/$supp" "../$supp")
262 else
263 testscip-shell system . . test. -e "$out_dir/$supp"
264 link_eq "$out_dir/local-fs.target.requires/$supp" "../$supp"
265 fi
266 elif [[ "$opt" =~ ^x-systemd.idle-timeout= ]]; then
267 # The timeout applies to the automount unit, not the original
268 # mount one
269 arg="$(opt_get_arg "$opt")"
270 supp="$(systemd-escape --suffix=automount --path "$where")"
271 grepscip-shell system . . grep. -qE "^TimeoutIdleSec=$arg$" "$out_dir/$supp"
272 elif [[ "$opt" =~ ^x-systemd.device-timeout= ]]; then
273 arg="$(opt_get_arg "$opt")"
274 device="$(systemd-escape --suffix=device --path "$what")"
275 grepscip-shell system . . grep. -qE "^JobRunningTimeoutSec=$arg$" "$out_dir/${device}.d/50-device-timeout.conf"
276 elif [[ "$opt" == x-systemd.makefs ]]; then
277 service="$(systemd-escape [email protected] --path "$what")"
278 testscip-shell system . . test. -e "$out_dir/$service"
279 link_eq "$out_dir/${unit}.requires/$service" "../$service"
280 elif [[ "$opt" == x-systemd.rw-only ]]; then
281 grepscip-shell system . . grep. -qE "^ReadWriteOnly=yes$" "$out_dir/$unit"
282 elif [[ "$opt" == x-systemd.growfs ]]; then
283 service="$(systemd-escape [email protected] --path "$where")"
284 link_endswith "$out_dir/${unit}.wants/$service" "/lib/systemd/system/[email protected]scip-shell filesystem . . `/lib/systemd/system/[email protected]`."
285 elif [[ "$opt" == x-systemd.validatefs ]]; then
286 service="$(systemd-escape [email protected] --path "$where")"
287 link_endswith "$out_dir/${unit}.wants/$service" "/lib/systemd/system/[email protected]scip-shell filesystem . . `/lib/systemd/system/[email protected]`."
288 elif [[ "$opt" == bg ]] && [[ "$fstype" =~ ^(nfs|nfs4)$ ]]; then
289 # We "convert" nfs bg mounts to fg, so we can do the job-control
290 # ourselves
291 grepscip-shell system . . grep. -qE "^Options=.*\bx-systemd.mount-timeout=infinity\b" "$out_dir/$unit"
292 grepscip-shell system . . grep. -qE "^Options=.*\bfg\b.*" "$out_dir/$unit"
293 elif [[ "$opt" =~ ^x-systemd\. ]]; then
294 echoscip-shell system . . echo. >&2 "Unhandled mount option: $opt"
295 exit 1
296 fi
297 done
298 done
299 }
300
301 : "fstab-generator: regular"
302 printfscip-shell system . . printf. "%s\n" "${FSTAB_GENERAL_ROOT[@]}" >"$FSTAB"
303 catscip-shell system . . cat. "$FSTAB"
304 SYSTEMD_FSTAB="$FSTAB" run_and_list "$GENERATOR_BIN" "$OUT_DIR"
305 check_fstab_mount_unitsscip-shell shell systemd 261~rc3-1 check_fstab_mount_units(). FSTAB_GENERAL_ROOT "$OUT_DIR"
306
307 # Skip the rest when running in a container, as it makes little sense to check
308 # initrd-related stuff there and fstab-generator might have a bit strange
309 # behavior during certain tests, like https://github.com/systemd/systemd/issues/27156
310 if in_container; then
311 echoscip-shell system . . echo. "Running in a container, skipping the rest of the fstab-generator tests..."
312 exit 0
313 fi
314
315 # In this mode we treat the entries as "regular" ones
316 : "fstab-generator: initrd - initrd fstab"
317 printfscip-shell system . . printf. "%s\n" "${FSTAB_GENERAL[@]}" >"$FSTAB"
318 catscip-shell system . . cat. "$FSTAB"
319 SYSTEMD_IN_INITRD=1 SYSTEMD_FSTAB="$FSTAB" SYSTEMD_SYSROOT_FSTAB=/dev/nullscip-shell filesystem . . `/dev/null`. run_and_list "$GENERATOR_BIN" "$OUT_DIR"
320 SYSTEMD_IN_INITRD=1 SYSTEMD_FSTAB="$FSTAB" SYSTEMD_SYSROOT_FSTAB=/dev/nullscip-shell filesystem . . `/dev/null`. check_fstab_mount_unitsscip-shell shell systemd 261~rc3-1 check_fstab_mount_units(). FSTAB_GENERAL "$OUT_DIR"
321
322 # In this mode we prefix the mount target with /sysroot and ignore all mounts
323 # that don't have the x-initrd.mount flag
324 : "fstab-generator: initrd - host fstab"
325 printfscip-shell system . . printf. "%s\n" "${FSTAB_GENERAL_ROOT[@]}" >"$FSTAB"
326 catscip-shell system . . cat. "$FSTAB"
327 SYSTEMD_IN_INITRD=1 SYSTEMD_FSTAB=/dev/nullscip-shell filesystem . . `/dev/null`. SYSTEMD_SYSROOT_FSTAB="$FSTAB" run_and_list "$GENERATOR_BIN" "$OUT_DIR"
328 SYSTEMD_IN_INITRD=1 SYSTEMD_FSTAB=/dev/nullscip-shell filesystem . . `/dev/null`. SYSTEMD_SYSROOT_FSTAB="$FSTAB" check_fstab_mount_unitsscip-shell shell systemd 261~rc3-1 check_fstab_mount_units(). FSTAB_GENERAL_ROOT "$OUT_DIR"
329
330 # Check the default stuff that we (almost) always create in initrd
331 : "fstab-generator: initrd default"
332 SYSTEMD_PROC_CMDLINE="root=/dev/sda2" SYSTEMD_IN_INITRD=1 SYSTEMD_FSTAB=/dev/nullscip-shell filesystem . . `/dev/null`. SYSTEMD_SYSROOT_FSTAB=/dev/nullscip-shell filesystem . . `/dev/null`. run_and_list "$GENERATOR_BIN" "$OUT_DIR"
333 testscip-shell system . . test. -e "$OUT_DIR/normal/sysroot.mount"
334 testscip-shell system . . test. -e "$OUT_DIR/normal/systemd-fsck-root.service"
335 link_eq "$OUT_DIR/normal/initrd-root-fs.target.requires/sysroot.mount" "../sysroot.mount"
336 link_eq "$OUT_DIR/normal/initrd-root-fs.target.requires/sysroot.mount" "../sysroot.mount"
337
338 : "fstab-generator: run as systemd-sysroot-fstab-check in initrd"
339 lnscip-shell system . . ln. -svf "$GENERATOR_BIN" /tmp/systemd-sysroot-fstab-checkscip-shell filesystem . . `/tmp/systemd-sysroot-fstab-check`.
340 (! /tmp/systemd-sysroot-fstab-checkscip-shell filesystem . . `/tmp/systemd-sysroot-fstab-check`. foo)
341 (! SYSTEMD_IN_INITRD=0 /tmp/systemd-sysroot-fstab-checkscip-shell filesystem . . `/tmp/systemd-sysroot-fstab-check`.)
342 printfscip-shell system . . printf. "%s\n" "${FSTAB_GENERAL[@]}" >"$FSTAB"
343 SYSTEMD_IN_INITRD=1 SYSTEMD_SYSROOT_FSTAB="$FSTAB" /tmp/systemd-sysroot-fstab-checkscip-shell filesystem . . `/tmp/systemd-sysroot-fstab-check`.
344
345 : "fstab-generator: duplicate"
346 printfscip-shell system . . printf. "%s\n" "${FSTAB_DUPLICATE[@]}" >"$FSTAB"
347 catscip-shell system . . cat. "$FSTAB"
348 (! SYSTEMD_FSTAB="$FSTAB" run_and_list "$GENERATOR_BIN" "$OUT_DIR")
349
350 : "fstab-generator: invalid"
351 printfscip-shell system . . printf. "%s\n" "${FSTAB_INVALID[@]}" >"$FSTAB"
352 catscip-shell system . . cat. "$FSTAB"
353 # Don't care about the exit code here
354 SYSTEMD_PROC_CMDLINE="" SYSTEMD_FSTAB="$FSTAB" run_and_list "$GENERATOR_BIN" "$OUT_DIR" || :
355 # No mounts should get created here
356 [[ "$(find "$OUT_DIR" -name "*.mount" | wc -l)" -eq 0 ]]
357
358 : "fstab-generator: kernel args - fstab=0"
359 printfscip-shell system . . printf. "%s\n" "${FSTAB_MINIMAL[@]}" >"$FSTAB"
360 SYSTEMD_FSTAB="$FSTAB" SYSTEMD_PROC_CMDLINE="fstab=0" run_and_list "$GENERATOR_BIN" "$OUT_DIR"
361 (! SYSTEMD_FSTAB="$FSTAB" check_fstab_mount_unitsscip-shell shell systemd 261~rc3-1 check_fstab_mount_units(). FSTAB_MINIMAL "$OUT_DIR")
362 SYSTEMD_IN_INITRD=1 SYSTEMD_FSTAB="$FSTAB" SYSTEMD_PROC_CMDLINE="fstab=0" run_and_list "$GENERATOR_BIN" "$OUT_DIR"
363 (! SYSTEMD_IN_INITRD=1 SYSTEMD_FSTAB="$FSTAB" check_fstab_mount_unitsscip-shell shell systemd 261~rc3-1 check_fstab_mount_units(). FSTAB_MINIMAL "$OUT_DIR")
364
365 : "fstab-generator: kernel args - rd.fstab=0"
366 printfscip-shell system . . printf. "%s\n" "${FSTAB_MINIMAL[@]}" >"$FSTAB"
367 SYSTEMD_FSTAB="$FSTAB" SYSTEMD_PROC_CMDLINE="rd.fstab=0" run_and_list "$GENERATOR_BIN" "$OUT_DIR"
368 SYSTEMD_FSTAB="$FSTAB" check_fstab_mount_unitsscip-shell shell systemd 261~rc3-1 check_fstab_mount_units(). FSTAB_MINIMAL "$OUT_DIR"
369 SYSTEMD_IN_INITRD=1 SYSTEMD_FSTAB="$FSTAB" SYSTEMD_PROC_CMDLINE="rd.fstab=0" run_and_list "$GENERATOR_BIN" "$OUT_DIR"
370 (! SYSTEMD_IN_INITRD=1 SYSTEMD_FSTAB="$FSTAB" check_fstab_mount_unitsscip-shell shell systemd 261~rc3-1 check_fstab_mount_units(). FSTAB_MINIMAL "$OUT_DIR")
371
372 : "fstab-generator: kernel args - systemd.swap=0"
373 printfscip-shell system . . printf. "%s\n" "${FSTAB_GENERAL_ROOT[@]}" >"$FSTAB"
374 catscip-shell system . . cat. "$FSTAB"
375 SYSTEMD_FSTAB="$FSTAB" SYSTEMD_PROC_CMDLINE="systemd.swap=0" run_and_list "$GENERATOR_BIN" "$OUT_DIR"
376 # No swap units should get created here
377 [[ "$(find "$OUT_DIR" -name "*.swap" | wc -l)" -eq 0 ]]
378
379 # Possible TODO
380 # - combine the rootfs & usrfs arguments and mix them with fstab entries
381 # - systemd.volatile=
382 : "fstab-generator: kernel args - root= + rootfstype= + rootflags="
383 # shellcheck disable=SC2034
384 EXPECTED_FSTAB=(
385 "/dev/disk/by-label/rootfs / ext4 noexec,ro 0 1"
386 )
387 CMDLINE="root=LABEL=rootfs rootfstype=ext4 rootflags=noexec"
388 SYSTEMD_IN_INITRD=1 SYSTEMD_FSTAB=/dev/nullscip-shell filesystem . . `/dev/null`. SYSTEMD_SYSROOT_FSTAB=/dev/nullscip-shell filesystem . . `/dev/null`. SYSTEMD_PROC_CMDLINE="$CMDLINE" run_and_list "$GENERATOR_BIN" "$OUT_DIR"
389 # The /proc/cmdline here is a dummy value to tell the in_initrd_host() function
390 # we're parsing host's fstab, but it's all on the kernel cmdline instead
391 SYSTEMD_IN_INITRD=1 SYSTEMD_SYSROOT_FSTAB=/proc/cmdlinescip-shell filesystem . . `/proc/cmdline`. check_fstab_mount_unitsscip-shell shell systemd 261~rc3-1 check_fstab_mount_units(). EXPECTED_FSTAB "$OUT_DIR"
392
393 # This is a very basic sanity test that involves manual checks, since adding it
394 # to the check_fstab_mount_units() function would make it way too complex
395 # (yet another possible TODO)
396 : "fstab-generator: kernel args - mount.usr= + mount.usrfstype= + mount.usrflags="
397 CMDLINE="mount.usr=UUID=be780f43-8803-4a76-9732-02ceda6e9808 mount.usrfstype=ext4 mount.usrflags=noexec,nodev"
398 SYSTEMD_IN_INITRD=1 SYSTEMD_FSTAB=/dev/nullscip-shell filesystem . . `/dev/null`. SYSTEMD_SYSROOT_FSTAB=/dev/nullscip-shell filesystem . . `/dev/null`. SYSTEMD_PROC_CMDLINE="$CMDLINE" run_and_list "$GENERATOR_BIN" "$OUT_DIR"
399 catscip-shell system . . cat. "$OUT_DIR/normal/sysroot-usr.mount" "$OUT_DIR/normal/sysusr-usr.mount"
400 # The general idea here is to mount the device to /sysusr/usr and then
401 # bind-mount /sysusr/usr to /sysroot/usr
402 grepscip-shell system . . grep. -qE "^What=/dev/disk/by-uuid/be780f43-8803-4a76-9732-02ceda6e9808$" "$OUT_DIR/normal/sysusr-usr.mount"
403 grepscip-shell system . . grep. -qE "^Where=/sysusr/usr$" "$OUT_DIR/normal/sysusr-usr.mount"
404 grepscip-shell system . . grep. -qE "^Type=ext4$" "$OUT_DIR/normal/sysusr-usr.mount"
405 grepscip-shell system . . grep. -qE "^Options=noexec,nodev,ro$" "$OUT_DIR/normal/sysusr-usr.mount"
406 link_eq "$OUT_DIR/normal/initrd-usr-fs.target.requires/sysusr-usr.mount" "../sysusr-usr.mount"
407 grepscip-shell system . . grep. -qE "^What=/sysusr/usr$" "$OUT_DIR/normal/sysroot-usr.mount"
408 grepscip-shell system . . grep. -qE "^Where=/sysroot/usr$" "$OUT_DIR/normal/sysroot-usr.mount"
409 grepscip-shell system . . grep. -qE "^Options=bind$" "$OUT_DIR/normal/sysroot-usr.mount"
410 link_eq "$OUT_DIR/normal/initrd-fs.target.requires/sysroot-usr.mount" "../sysroot-usr.mount"