]>
git.ipfire.org Git - thirdparty/systemd.git/blob - test/TEST-08-INITRD/test.sh
2 # SPDX-License-Identifier: LGPL-2.1-or-later
5 TEST_DESCRIPTION
="Test various scenarios involving transition from/to initrd"
8 # shellcheck source=test/test-functions
9 .
"${TEST_BASE_DIR:?}/test-functions"
12 local workspace
="${1:?}"
13 local sd_initrd
file dir
15 # Create a shutdown initrd
17 # This should provide coverage for shutdown initrd related issues, see:
18 # - https://github.com/systemd/systemd/issues/28645
19 # - https://github.com/systemd/systemd/pull/28648
20 # - https://github.com/systemd/systemd/pull/28793
22 # This is a bit messier than I originally anticipated, as installing our own libraries
23 # is handled implicitly by install_systemd() which I don't want to use here, since
24 # I need only the systemd-shutdown binary
25 sd_initrd
="$workspace/shutdown-initrd"
26 mkdir
-p "$sd_initrd/etc" "$sd_initrd/usr"
27 initdir
="$sd_initrd" image_install bash
/usr
/lib
/os-release
28 ln -srf "$sd_initrd/usr/lib/os-release" "$sd_initrd/etc/initrd-release"
29 initdir
="$sd_initrd" inst_binary
"$workspace/usr/lib/systemd/systemd-shutdown" "/usr/lib/systemd/systemd-shutdown"
30 initdir
="$sd_initrd" inst_libs
"$sd_initrd/usr/lib/systemd/systemd-shutdown"
31 # We need to deal with libsystemd stuff explicitly, as we don't call install_systemd() here
32 while read -r file; do
33 initdir
="$sd_initrd" inst_library
"$file" "${file##"$workspace"}"
34 initdir
="$sd_initrd" inst_libs
"$file"
35 done < <(find "$workspace/usr/" -name "libsystemd*.so*")
36 # Call systemd-shutdown indirectly, so we can show a message that we can check for
37 # later to make sure the shutdown initrd was actually executed
38 cat >"$sd_initrd/shutdown" <<\EOF
40 echo "Hello from shutdown initrd"
41 exec /usr
/lib
/systemd
/systemd-shutdown
"$@"
43 chmod +x
"$sd_initrd/shutdown"
46 check_result_qemu_hook
() {
47 local console_log
="${TESTDIR:?}/console.log"
49 if [[ ! -e "$console_log" ]]; then
50 dfatal
"Missing console log - this shouldn't happen"
54 # The console log should not contain messages like:
55 # [ 6.245000] systemd-shutdown[1]: Failed to move /run/initramfs to /: Invalid argument
56 # [ 6.245955] systemd-shutdown[1]: Failed to switch root to "/run/initramfs": Invalid argument
57 if grep -qE "systemd-shutdown.+: Failed to move /run/initramfs" "$console_log" ||
58 grep -qE "systemd-shutdown.+: Failed to switch root" "$console_log"; then
59 derror
"sd-shutdown failed to switch root in shutdown initrd"
63 # Check if the shutdown initrd was executed at all
64 if ! grep -qE "^Hello from shutdown initrd\s*$" "$console_log"; then
65 derror
"Missing 'hello' message from shutdown initrd"
72 # Setup a one shot service in initrd that creates a dummy bind mount under /run
73 # to check if the mount persists though the initrd transition. The "check" part
74 # is in the respective testsuite-08.sh script.
76 # See: https://github.com/systemd/systemd/issues/28452
78 local extra
="${TESTDIR:?}/initrd.extra"
81 mkdir
-m 755 "$extra/etc" "$extra/etc/systemd" "$extra/etc/systemd/system" "$extra/etc/systemd/system/initrd.target.wants"
83 cat >"$extra/etc/systemd/system/initrd-run-mount.service" <<EOF
85 Description=Create a mount in /run that should survive the transition from initrd
90 ExecStart=mkdir /run/initrd-mount-source /run/initrd-mount-target
91 ExecStart=mount -v --bind /run/initrd-mount-source /run/initrd-mount-target
92 ExecStart=cp -v /etc/initrd-release /run/initrd-mount-target/hello-world
94 ln -svrf "$extra/etc/systemd/system/initrd-run-mount.service" "$extra/etc/systemd/system/initrd.target.wants/initrd-run-mount.service"
96 (cd "$extra" && find . |
cpio -o -H newc
-R root
:root
> "$extra.cpio")
98 INITRD_EXTRA
="$extra.cpio"