]> git.ipfire.org Git - thirdparty/dracut.git/blame - test/TEST-40-NBD/test.sh
fix: shellcheck 0.7.2
[thirdparty/dracut.git] / test / TEST-40-NBD / test.sh
CommitLineData
9ecbe2e4 1#!/bin/bash
967cc19a 2
77906443
HH
3if [[ $NM ]]; then
4 USE_NETWORK="network-manager"
5 OMIT_NETWORK="network-legacy"
6else
7 USE_NETWORK="network-legacy"
8 OMIT_NETWORK="network-manager"
9fi
10
77854c6d 11# shellcheck disable=SC2034
77906443 12TEST_DESCRIPTION="root filesystem on NBD with $USE_NETWORK"
9ecbe2e4
DD
13
14KVERSION=${KVERSION-$(uname -r)}
15
16# Uncomment this to debug failures
66a3d405 17#DEBUGFAIL="rd.shell rd.break rd.debug systemd.log_target=console loglevel=7 systemd.log_level=debug"
b0d6254d 18#SERIAL="tcp:127.0.0.1:9999"
9ecbe2e4 19
d63a4e28 20test_check() {
9a52c3fd 21 if ! type -p nbd-server 2> /dev/null; then
eb8856a5
HH
22 echo "Test needs nbd-server... Skipping"
23 return 1
24 fi
25
77854c6d 26 if ! modinfo -k "$KVERSION" nbd &> /dev/null; then
eb8856a5
HH
27 echo "Kernel module nbd does not exist"
28 return 1
29 fi
30
31 return 0
d63a4e28
HH
32}
33
9ecbe2e4
DD
34run_server() {
35 # Start server first
b2c5f5dc 36 echo "NBD TEST SETUP: Starting DHCP/NBD server"
9ecbe2e4 37
b80ee080
HH
38 declare -a disk_args=()
39 # shellcheck disable=SC2034
40 declare -i disk_index=0
41 qemu_add_drive_args disk_index disk_args "$TESTDIR"/unencrypted.img unencrypted
42 qemu_add_drive_args disk_index disk_args "$TESTDIR"/encrypted.img encrypted
43 qemu_add_drive_args disk_index disk_args "$TESTDIR"/server.img serverroot
44
77854c6d 45 "$testdir"/run-qemu \
b80ee080
HH
46 "${disk_args[@]}" \
47 -serial "${SERIAL:-"file:$TESTDIR/server.log"}" \
83691c41
HH
48 -net nic,macaddr=52:54:00:12:34:56,model=e1000 \
49 -net socket,listen=127.0.0.1:12340 \
909961d0 50 -append "panic=1 hung_task_panic=1 oops=panic softlockup_panic=1 rd.luks=0 systemd.crash_reboot quiet root=/dev/disk/by-id/ata-disk_serverroot rootfstype=ext3 rw console=ttyS0,115200n81 selinux=0 $SERVER_DEBUG" \
b80ee080
HH
51 -initrd "$TESTDIR"/initramfs.server \
52 -pidfile "$TESTDIR"/server.pid -daemonize || return 1
77854c6d 53 chmod 644 "$TESTDIR"/server.pid || return 1
9ecbe2e4
DD
54
55 # Cleanup the terminal if we have one
56 tty -s && stty sane
57
3aae122c
HH
58 if ! [[ $SERIAL ]]; then
59 echo "Waiting for the server to startup"
9a52c3fd 60 while :; do
3aae122c 61 grep Serving "$TESTDIR"/server.log && break
0f62da04 62 tail "$TESTDIR"/server.log
3aae122c
HH
63 sleep 1
64 done
65 else
66 echo Sleeping 10 seconds to give the server a head start
67 sleep 10
68 fi
9ecbe2e4
DD
69}
70
71client_test() {
72 local test_name="$1"
73 local mac=$2
74 local cmdline="$3"
a29f15a5
DD
75 local fstype=$4
76 local fsopt=$5
77 local found opts nbdinfo
78
79 [[ $fstype ]] || fstype=ext3
75e8f476 80 [[ $fsopt ]] || fsopt="ro"
9ecbe2e4
DD
81
82 echo "CLIENT TEST START: $test_name"
83
b80ee080
HH
84 dd if=/dev/zero of="$TESTDIR"/marker.img bs=1MiB count=1
85 declare -a disk_args=()
86 declare -i disk_index=0
87 qemu_add_drive_args disk_index disk_args "$TESTDIR"/marker.img marker
83691c41 88
77854c6d 89 "$testdir"/run-qemu \
b80ee080 90 "${disk_args[@]}" \
77854c6d 91 -net nic,macaddr="$mac",model=e1000 \
83691c41 92 -net socket,connect=127.0.0.1:12340 \
909961d0 93 -append "panic=1 hung_task_panic=1 oops=panic softlockup_panic=1 systemd.crash_reboot rd.shell=0 $cmdline $DEBUGFAIL rd.auto rd.info rd.retry=10 ro console=ttyS0,115200n81 selinux=0 " \
77854c6d 94 -initrd "$TESTDIR"/initramfs.testing
9ecbe2e4 95
77854c6d 96 # shellcheck disable=SC2181
b80ee080 97 if [[ $? -ne 0 ]] || ! grep -U --binary-files=binary -F -m 1 -q nbd-OK "$TESTDIR"/marker.img; then
83691c41
HH
98 echo "CLIENT TEST END: $test_name [FAILED - BAD EXIT]"
99 return 1
9ecbe2e4
DD
100 fi
101
a29f15a5 102 # nbdinfo=( fstype fsoptions )
b80ee080 103 read -r -a nbdinfo < <(awk '{print $2, $3; exit}' "$TESTDIR"/marker.img)
a29f15a5 104
75d758e8 105 if [[ ${nbdinfo[0]} != "$fstype" ]]; then
83691c41
HH
106 echo "CLIENT TEST END: $test_name [FAILED - WRONG FS TYPE] \"${nbdinfo[0]}\" != \"$fstype\""
107 return 1
a29f15a5
DD
108 fi
109
110 opts=${nbdinfo[1]},
111 while [[ $opts ]]; do
77854c6d 112 if [[ ${opts%%,*} == "$fsopt" ]]; then
83691c41
HH
113 found=1
114 break
115 fi
116 opts=${opts#*,}
a29f15a5
DD
117 done
118
119 if [[ ! $found ]]; then
83691c41
HH
120 echo "CLIENT TEST END: $test_name [FAILED - BAD FS OPTS] \"${nbdinfo[1]}\" != \"$fsopt\""
121 return 1
a29f15a5
DD
122 fi
123
9ecbe2e4
DD
124 echo "CLIENT TEST END: $test_name [OK]"
125}
126
127test_run() {
128 if ! run_server; then
83691c41
HH
129 echo "Failed to start server" 1>&2
130 return 1
9ecbe2e4 131 fi
57aa1e91
HH
132 client_run
133 kill_server
97add1b3
HH
134}
135
136client_run() {
a29f15a5
DD
137 # The default is ext3,errors=continue so use that to determine
138 # if our options were parsed and used
b070c1d3 139 client_test "NBD root=nbd:IP:port" 52:54:00:12:34:00 \
9a52c3fd 140 "root=nbd:192.168.50.1:raw rd.luks=0" || return 1
b070c1d3 141
83691c41 142 client_test "NBD root=nbd:IP:port::fsopts" 52:54:00:12:34:00 \
9a52c3fd
HH
143 "root=nbd:192.168.50.1:raw::errors=panic rd.luks=0" \
144 ext3 errors=panic || return 1
83691c41 145
bcf94bba 146 client_test "NBD root=nbd:IP:port:fstype" 52:54:00:12:34:00 \
9a52c3fd 147 "root=nbd:192.168.50.1:raw:ext3 rd.luks=0" ext3 || return 1
a29f15a5 148
bcf94bba 149 client_test "NBD root=nbd:IP:port:fstype:fsopts" 52:54:00:12:34:00 \
9a52c3fd
HH
150 "root=nbd:192.168.50.1:raw:ext3:errors=panic rd.luks=0" \
151 ext3 errors=panic || return 1
beb097d9 152
a29f15a5
DD
153 # DHCP root-path parsing
154
77906443
HH
155 client_test "NBD root=/dev/root netroot=dhcp DHCP root-path nbd:srv:port" 52:54:00:12:34:01 \
156 "root=/dev/root netroot=dhcp ip=dhcp rd.luks=0" || return 1
a29f15a5 157
77906443
HH
158 client_test "NBD root=/dev/root netroot=dhcp DHCP root-path nbd:srv:port:fstype" \
159 52:54:00:12:34:02 "root=/dev/root netroot=dhcp ip=dhcp rd.luks=0" ext2 || return 1
beb097d9 160
77906443
HH
161 client_test "NBD root=/dev/root netroot=dhcp DHCP root-path nbd:srv:port::fsopts" \
162 52:54:00:12:34:03 "root=/dev/root netroot=dhcp ip=dhcp rd.luks=0" ext3 errors=panic || return 1
a29f15a5 163
77906443
HH
164 client_test "NBD root=/dev/root netroot=dhcp DHCP root-path nbd:srv:port:fstype:fsopts" \
165 52:54:00:12:34:04 "root=/dev/root netroot=dhcp ip=dhcp rd.luks=0" ext2 errors=panic || return 1
aec48753
DD
166
167 # netroot handling
168
0f62da04 169 client_test "NBD netroot=nbd:IP:port" 52:54:00:12:34:00 \
77906443 170 "root=LABEL=dracut netroot=nbd:192.168.50.1:raw ip=dhcp rd.luks=0" || return 1
0f62da04 171
77906443
HH
172 client_test "NBD root=/dev/root netroot=dhcp DHCP root-path nbd:srv:port:fstype:fsopts" \
173 52:54:00:12:34:04 "root=/dev/root netroot=dhcp ip=dhcp rd.luks=0" ext2 errors=panic || return 1
8bd5873f
DD
174
175 # Encrypted root handling via LVM/LUKS over NBD
176
77854c6d
HH
177 # shellcheck disable=SC1090
178 . "$TESTDIR"/luks.uuid
0f62da04
HH
179
180 client_test "NBD root=LABEL=dracut netroot=nbd:IP:port" \
9a52c3fd 181 52:54:00:12:34:00 \
77906443 182 "root=LABEL=dracut rd.luks.uuid=$ID_FS_UUID rd.lv.vg=dracut ip=dhcp netroot=nbd:192.168.50.1:encrypted" || return 1
8bd5873f 183
0f62da04 184 # XXX This should be ext3,errors=panic but that doesn't currently
8bd5873f
DD
185 # XXX work when you have a real root= line in addition to netroot=
186 # XXX How we should work here needs clarification
9a52c3fd
HH
187 # client_test "NBD root=LABEL=dracut netroot=dhcp (w/ fstype and opts)" \
188 # 52:54:00:12:34:05 \
189 # "root=LABEL=dracut rd.luks.uuid=$ID_FS_UUID rd.lv.vg=dracut netroot=dhcp" || return 1
9ca74ffe
HH
190
191 if [[ -s server.pid ]]; then
77854c6d
HH
192 kill -TERM "$(cat "$TESTDIR"/server.pid)"
193 rm -f -- "$TESTDIR"/server.pid
9ca74ffe
HH
194 fi
195
8bd5873f
DD
196}
197
198make_encrypted_root() {
0f62da04 199 rm -fr "$TESTDIR"/overlay
8bd5873f
DD
200 kernel=$KVERSION
201 # Create what will eventually be our root filesystem onto an overlay
202 (
77854c6d 203 # shellcheck disable=SC2030
83691c41 204 export initdir=$TESTDIR/overlay/source
77854c6d
HH
205 # shellcheck disable=SC1090
206 . "$basedir"/dracut-init.sh
28f0b27f 207 mkdir -p "$initdir"
06853123 208 (
77854c6d 209 cd "$initdir" || exit
77906443 210 mkdir -p dev sys proc etc run var/run tmp
0f62da04 211 mkdir -p root usr/bin usr/lib usr/lib64 usr/sbin
06853123
HH
212 for i in bin sbin lib lib64; do
213 ln -sfnr usr/$i $i
214 done
215 )
0f62da04 216
af119460 217 inst_multiple sh df free ls shutdown poweroff stty cat ps ln ip \
b80ee080 218 mount dmesg mkdir cp ping dd sync
96d22bd7 219 for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
83691c41
HH
220 [ -f ${_terminfodir}/l/linux ] && break
221 done
af119460 222 inst_multiple -o ${_terminfodir}/l/linux
b80ee080
HH
223
224 inst_simple "${basedir}/modules.d/99base/dracut-lib.sh" "/lib/dracut-lib.sh"
225 inst_binary "${basedir}/dracut-util" "/usr/bin/dracut-util"
226 ln -s dracut-util "${initdir}/usr/bin/dracut-getarg"
227 ln -s dracut-util "${initdir}/usr/bin/dracut-getargs"
228
83691c41 229 inst ./client-init.sh /sbin/init
021b2fdd 230 inst_simple /etc/os-release
9a52c3fd 231 find_binary plymouth > /dev/null && inst_multiple plymouth
77854c6d 232 cp -a /etc/ld.so.conf* "$initdir"/etc
4bd0ab61 233 ldconfig -r "$initdir"
8bd5873f
DD
234 )
235
236 # second, install the files needed to make the root filesystem
237 (
77854c6d
HH
238 # shellcheck disable=SC2030
239 # shellcheck disable=SC2031
83691c41 240 export initdir=$TESTDIR/overlay
77854c6d
HH
241 # shellcheck disable=SC1090
242 . "$basedir"/dracut-init.sh
06853123 243 (
77854c6d 244 cd "$initdir" || exit
2f78bafa 245 mkdir -p dev sys proc etc tmp var run root usr/bin usr/lib usr/lib64 usr/sbin
06853123
HH
246 for i in bin sbin lib lib64; do
247 ln -sfnr usr/$i $i
248 done
2f78bafa 249 ln -s ../run var/run
06853123 250 )
77906443 251 inst_multiple mkfs.ext3 poweroff cp umount dd sync
4e882b80 252 inst_hook shutdown-emergency 000 ./hard-off.sh
781f1971 253 inst_hook emergency 000 ./hard-off.sh
0f62da04 254 inst_hook initqueue 01 ./create-encrypted-root.sh
356333b3 255 inst_hook initqueue/finished 01 ./finished-false.sh
8bd5873f
DD
256 )
257
258 # create an initramfs that will create the target root filesystem.
259 # We do it this way so that we do not risk trashing the host mdraid
260 # devices, volume groups, encrypted partitions, etc.
77854c6d 261 "$basedir"/dracut.sh -l -i "$TESTDIR"/overlay / \
9a52c3fd
HH
262 -m "dash crypt lvm mdraid udev-rules base rootfs-block fs-lib kernel-modules qemu" \
263 -d "piix ide-gd_mod ata_piix ext3 ext3 sd_mod" \
264 --no-hostonly-cmdline -N \
77854c6d
HH
265 -f "$TESTDIR"/initramfs.makeroot "$KVERSION" || return 1
266 rm -rf -- "$TESTDIR"/overlay
8bd5873f 267
b80ee080
HH
268 dd if=/dev/zero of="$TESTDIR"/encrypted.img bs=1MiB count=120
269 dd if=/dev/zero of="$TESTDIR"/marker.img bs=1MiB count=1
270 declare -a disk_args=()
271 # shellcheck disable=SC2034
272 declare -i disk_index=0
273 qemu_add_drive_args disk_index disk_args "$TESTDIR"/marker.img marker
274 qemu_add_drive_args disk_index disk_args "$TESTDIR"/encrypted.img root
275
8bd5873f 276 # Invoke KVM and/or QEMU to actually create the target filesystem.
77854c6d 277 "$testdir"/run-qemu \
b80ee080 278 "${disk_args[@]}" \
bb278147 279 -append "root=/dev/fakeroot rw quiet console=ttyS0,115200n81 selinux=0" \
77854c6d 280 -initrd "$TESTDIR"/initramfs.makeroot || return 1
b80ee080
HH
281 grep -U --binary-files=binary -F -m 1 -q dracut-root-block-created "$TESTDIR"/marker.img || return 1
282 grep -F -a -m 1 ID_FS_UUID "$TESTDIR"/marker.img > "$TESTDIR"/luks.uuid
9ecbe2e4
DD
283}
284
285make_client_root() {
0f62da04 286 rm -fr "$TESTDIR"/overlay
9ecbe2e4
DD
287 kernel=$KVERSION
288 (
77854c6d
HH
289 mkdir -p "$TESTDIR"/overlay/source
290 # shellcheck disable=SC2030
291 # shellcheck disable=SC2031
0f62da04 292 export initdir=$TESTDIR/overlay/source
77854c6d 293 # shellcheck disable=SC1090
0f62da04 294 . "$basedir"/dracut-init.sh
28f0b27f 295 mkdir -p "$initdir"
06853123 296 (
77854c6d 297 cd "$initdir" || exit
77906443 298 mkdir -p dev sys proc etc run var/run tmp
0f62da04 299 mkdir -p root usr/bin usr/lib usr/lib64 usr/sbin
06853123
HH
300 for i in bin sbin lib lib64; do
301 ln -sfnr usr/$i $i
302 done
303 )
af119460 304 inst_multiple sh ls shutdown poweroff stty cat ps ln ip \
b80ee080 305 dmesg mkdir cp ping dd mount sync
96d22bd7 306 for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
83691c41
HH
307 [ -f ${_terminfodir}/l/linux ] && break
308 done
af119460 309 inst_multiple -o ${_terminfodir}/l/linux
b80ee080
HH
310
311 inst_simple "${basedir}/modules.d/99base/dracut-lib.sh" "/lib/dracut-lib.sh"
312 inst_binary "${basedir}/dracut-util" "/usr/bin/dracut-util"
313 ln -s dracut-util "${initdir}/usr/bin/dracut-getarg"
314 ln -s dracut-util "${initdir}/usr/bin/dracut-getargs"
315
83691c41 316 inst ./client-init.sh /sbin/init
021b2fdd 317 inst_simple /etc/os-release
83691c41
HH
318 inst /etc/nsswitch.conf /etc/nsswitch.conf
319 inst /etc/passwd /etc/passwd
320 inst /etc/group /etc/group
9a52c3fd 321 for i in /usr/lib*/libnss_files* /lib*/libnss_files*; do
28f0b27f 322 [ -e "$i" ] || continue
77854c6d 323 inst "$i"
83691c41 324 done
77854c6d 325 cp -a /etc/ld.so.conf* "$initdir"/etc
4bd0ab61 326 ldconfig -r "$initdir"
9ecbe2e4
DD
327 )
328
0f62da04
HH
329 # second, install the files needed to make the root filesystem
330 (
77854c6d
HH
331 # shellcheck disable=SC2030
332 # shellcheck disable=SC2031
0f62da04 333 export initdir=$TESTDIR/overlay
77854c6d
HH
334 # shellcheck disable=SC1090
335 . "$basedir"/dracut-init.sh
0f62da04
HH
336 inst_multiple sfdisk mkfs.ext3 poweroff cp umount sync dd
337 inst_hook initqueue 01 ./create-client-root.sh
338 inst_hook initqueue/finished 01 ./finished-false.sh
0f62da04
HH
339 )
340
341 # create an initramfs that will create the target root filesystem.
342 # We do it this way so that we do not risk trashing the host mdraid
343 # devices, volume groups, encrypted partitions, etc.
77854c6d 344 "$basedir"/dracut.sh -l -i "$TESTDIR"/overlay / \
9a52c3fd
HH
345 -m "dash udev-rules base rootfs-block fs-lib kernel-modules fs-lib qemu" \
346 -d "piix ide-gd_mod ata_piix ext3 sd_mod" \
347 --nomdadmconf \
348 --no-hostonly-cmdline -N \
77854c6d 349 -f "$TESTDIR"/initramfs.makeroot "$KVERSION" || return 1
0f62da04 350
b80ee080
HH
351 dd if=/dev/zero of="$TESTDIR"/unencrypted.img bs=1MiB count=120
352 dd if=/dev/zero of="$TESTDIR"/marker.img bs=1MiB count=1
353 declare -a disk_args=()
354 # shellcheck disable=SC2034
355 declare -i disk_index=0
356 qemu_add_drive_args disk_index disk_args "$TESTDIR"/marker.img marker
357 qemu_add_drive_args disk_index disk_args "$TESTDIR"/unencrypted.img root
358
0f62da04 359 # Invoke KVM and/or QEMU to actually create the target filesystem.
77854c6d 360 "$testdir"/run-qemu \
b80ee080 361 "${disk_args[@]}" \
0f62da04 362 -append "root=/dev/dracut/root rw rootfstype=ext3 quiet console=ttyS0,115200n81 selinux=0" \
77854c6d 363 -initrd "$TESTDIR"/initramfs.makeroot || return 1
b80ee080 364 grep -U --binary-files=binary -F -m 1 -q dracut-root-block-created "$TESTDIR"/marker.img || return 1
0f62da04 365 rm -fr "$TESTDIR"/overlay
9ecbe2e4
DD
366}
367
368make_server_root() {
77854c6d 369 rm -fr "$TESTDIR"/overlay
909961d0 370 # shellcheck disable=SC2031
77906443 371 export kernel=$KVERSION
9ecbe2e4 372 (
77854c6d
HH
373 mkdir -p "$TESTDIR"/overlay/source
374 # shellcheck disable=SC2030
375 # shellcheck disable=SC2031
0f62da04 376 export initdir=$TESTDIR/overlay/source
77854c6d 377 # shellcheck disable=SC1090
0f62da04 378 . "$basedir"/dracut-init.sh
28f0b27f 379 mkdir -p "$initdir"
83691c41 380 (
77854c6d 381 cd "$initdir" || exit
d63a4e28 382 mkdir -p run dev sys proc etc var var/lib/dhcpd tmp etc/nbd-server
2f78bafa 383 ln -s ../run var/run
83691c41 384 )
9a52c3fd 385 cat > "$initdir/etc/nbd-server/config" << EOF
b070c1d3
HH
386[generic]
387[raw]
b80ee080 388exportname = /dev/disk/by-id/ata-disk_unencrypted
b070c1d3 389port = 2000
eb8856a5 390bs = 4096
b070c1d3 391[encrypted]
b80ee080 392exportname = /dev/disk/by-id/ata-disk_encrypted
b070c1d3 393port = 2001
eb8856a5 394bs = 4096
b070c1d3 395EOF
af119460 396 inst_multiple sh ls shutdown poweroff stty cat ps ln ip \
9a52c3fd
HH
397 dmesg mkdir cp ping grep \
398 sleep nbd-server chmod modprobe vi
96d22bd7 399 for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
83691c41
HH
400 [ -f ${_terminfodir}/l/linux ] && break
401 done
af119460 402 inst_multiple -o ${_terminfodir}/l/linux
83691c41 403 instmods af_packet
9a52c3fd 404 type -P dhcpd > /dev/null && inst_multiple dhcpd
83691c41
HH
405 [ -x /usr/sbin/dhcpd3 ] && inst /usr/sbin/dhcpd3 /usr/sbin/dhcpd
406 inst ./server-init.sh /sbin/init
021b2fdd 407 inst_simple /etc/os-release
83691c41
HH
408 inst ./hosts /etc/hosts
409 inst ./dhcpd.conf /etc/dhcpd.conf
410 inst /etc/nsswitch.conf /etc/nsswitch.conf
411 inst /etc/passwd /etc/passwd
412 inst /etc/group /etc/group
9a52c3fd 413 for i in /usr/lib*/libnss_files* /lib*/libnss_files*; do
28f0b27f 414 [ -e "$i" ] || continue
77854c6d 415 inst "$i"
83691c41 416 done
9ecbe2e4 417
77854c6d 418 cp -a /etc/ld.so.conf* "$initdir"/etc
4bd0ab61 419 ldconfig -r "$initdir"
9ecbe2e4
DD
420 )
421
0f62da04
HH
422 # second, install the files needed to make the root filesystem
423 (
77854c6d
HH
424 # shellcheck disable=SC2030
425 # shellcheck disable=SC2031
0f62da04 426 export initdir=$TESTDIR/overlay
77854c6d
HH
427 # shellcheck disable=SC1090
428 . "$basedir"/dracut-init.sh
77906443 429 inst_multiple sfdisk mkfs.ext3 poweroff cp umount sync dd sync
0f62da04
HH
430 inst_hook initqueue 01 ./create-server-root.sh
431 inst_hook initqueue/finished 01 ./finished-false.sh
0f62da04
HH
432 )
433
434 # create an initramfs that will create the target root filesystem.
435 # We do it this way so that we do not risk trashing the host mdraid
436 # devices, volume groups, encrypted partitions, etc.
77854c6d 437 "$basedir"/dracut.sh -l -i "$TESTDIR"/overlay / \
9a52c3fd
HH
438 -m "dash udev-rules base rootfs-block fs-lib kernel-modules fs-lib qemu" \
439 -d "piix ide-gd_mod ata_piix ext3 sd_mod" \
440 --nomdadmconf \
441 --no-hostonly-cmdline -N \
77854c6d 442 -f "$TESTDIR"/initramfs.makeroot "$KVERSION" || return 1
0f62da04 443
b80ee080
HH
444 dd if=/dev/zero of="$TESTDIR"/server.img bs=1MiB count=120
445 dd if=/dev/zero of="$TESTDIR"/marker.img bs=1MiB count=1
446 declare -a disk_args=()
447 # shellcheck disable=SC2034
448 declare -i disk_index=0
449 qemu_add_drive_args disk_index disk_args "$TESTDIR"/marker.img marker
450 qemu_add_drive_args disk_index disk_args "$TESTDIR"/server.img root
451
0f62da04 452 # Invoke KVM and/or QEMU to actually create the target filesystem.
77854c6d 453 "$testdir"/run-qemu \
b80ee080 454 "${disk_args[@]}" \
0f62da04 455 -append "root=/dev/dracut/root rw rootfstype=ext3 quiet console=ttyS0,115200n81 selinux=0" \
77854c6d 456 -initrd "$TESTDIR"/initramfs.makeroot || return 1
b80ee080 457 grep -U --binary-files=binary -F -m 1 -q dracut-root-block-created "$TESTDIR"/marker.img || return 1
0f62da04 458 rm -fr "$TESTDIR"/overlay
9ecbe2e4
DD
459}
460
461test_setup() {
8bd5873f 462 make_encrypted_root || return 1
9ecbe2e4
DD
463 make_client_root || return 1
464 make_server_root || return 1
465
77854c6d 466 rm -fr "$TESTDIR"/overlay
9ecbe2e4
DD
467 # Make the test image
468 (
77854c6d 469 # shellcheck disable=SC2031
83691c41 470 export initdir=$TESTDIR/overlay
77854c6d
HH
471 # shellcheck disable=SC1090
472 . "$basedir"/dracut-init.sh
9ca53063 473 inst_multiple poweroff shutdown dd
4e882b80 474 inst_hook shutdown-emergency 000 ./hard-off.sh
3f7e5358 475 inst ./cryptroot-ask.sh /sbin/cryptroot-ask
83691c41 476
d63a4e28
HH
477 # inst ./debug-shell.service /lib/systemd/system/debug-shell.service
478 # mkdir -p "${initdir}/lib/systemd/system/sysinit.target.wants"
479 # ln -fs ../debug-shell.service "${initdir}/lib/systemd/system/sysinit.target.wants/debug-shell.service"
83691c41 480
77854c6d
HH
481 # shellcheck disable=SC1090
482 . "$TESTDIR"/luks.uuid
483 mkdir -p "$initdir"/etc
484 echo "luks-$ID_FS_UUID /dev/nbd0 /etc/key" > "$initdir"/etc/crypttab
485 echo -n test > "$initdir"/etc/key
9ecbe2e4
DD
486 )
487
77854c6d 488 "$basedir"/dracut.sh -l -i "$TESTDIR"/overlay / \
b80ee080
HH
489 -a "udev-rules base rootfs-block fs-lib debug kernel-modules" \
490 -d "af_packet piix ide-gd_mod ata_piix ext3 sd_mod e1000 drbg" \
9a52c3fd 491 --no-hostonly-cmdline -N \
77854c6d 492 -f "$TESTDIR"/initramfs.server "$KVERSION" || return 1
9ecbe2e4 493
77854c6d 494 "$basedir"/dracut.sh -l -i "$TESTDIR"/overlay / \
77906443
HH
495 -o "plymouth dash iscsi nfs ${OMIT_NETWORK}" \
496 -a "debug watchdog ${USE_NETWORK}" \
9a52c3fd
HH
497 -d "af_packet piix ide-gd_mod ata_piix ext3 ext3 sd_mod e1000 i6300esb ib700wdt" \
498 --no-hostonly-cmdline -N \
77854c6d 499 -f "$TESTDIR"/initramfs.testing "$KVERSION" || return 1
9ecbe2e4
DD
500}
501
97add1b3 502kill_server() {
0be1785a 503 if [[ -s $TESTDIR/server.pid ]]; then
77854c6d
HH
504 kill -TERM "$(cat "$TESTDIR"/server.pid)"
505 rm -f -- "$TESTDIR"/server.pid
9ecbe2e4 506 fi
97add1b3
HH
507}
508
509test_cleanup() {
510 kill_server
9ecbe2e4
DD
511}
512
77854c6d
HH
513# shellcheck disable=SC1090
514. "$testdir"/test-functions