]> git.ipfire.org Git - thirdparty/dracut-ng.git/commitdiff
fix(systemd-initrd): add base as dependency
authorDorina Kovacs <princessdorinakovacs@gmail.com>
Thu, 8 Aug 2024 15:00:43 +0000 (17:00 +0200)
committerLaszlo Gombos <laszlo.gombos@gmail.com>
Wed, 21 Aug 2024 13:34:45 +0000 (09:34 -0400)
For systemd to run properly inside initramfs, /etc/initrd-release is required to exist. [1]
/etc/initrd-release is only written in the base module.

[1]: https://systemd.io/INITRD_INTERFACE/#using-systemd-inside-an-initrd

.github/workflows/integration.yml
modules.d/01systemd-initrd/module-setup.sh
test/TEST-05-SYSTEMD-INITRD/Makefile [new file with mode: 0644]
test/TEST-05-SYSTEMD-INITRD/create-root.sh [new file with mode: 0755]
test/TEST-05-SYSTEMD-INITRD/test.sh [new file with mode: 0755]

index b15625eff073e2ee06cbc514a8a2f2063c9bb40b..16c0bbe862c489b195a87111adeaf433df7214ca 100644 (file)
@@ -64,6 +64,7 @@ jobs:
                         "02",
                         "03",
                         "04",
+                        "05",
                         "10",
                         "11",
                         "12",
index 957e7bea788e05f0679b4d3f2eab94ac02545657..603868612a187d08761759189116c6c8d80353d7 100755 (executable)
@@ -10,7 +10,7 @@ check() {
 
 # called by dracut
 depends() {
-    echo systemd-udevd systemd-journald systemd-tmpfiles
+    echo base systemd-udevd systemd-journald systemd-tmpfiles
 }
 
 installkernel() {
diff --git a/test/TEST-05-SYSTEMD-INITRD/Makefile b/test/TEST-05-SYSTEMD-INITRD/Makefile
new file mode 100644 (file)
index 0000000..2dcab81
--- /dev/null
@@ -0,0 +1 @@
+-include ../Makefile.testdir
diff --git a/test/TEST-05-SYSTEMD-INITRD/create-root.sh b/test/TEST-05-SYSTEMD-INITRD/create-root.sh
new file mode 100755 (executable)
index 0000000..5f82ac3
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+trap 'poweroff -f' EXIT
+
+# don't let udev and this script step on eachother's toes
+for x in 64-lvm.rules 70-mdadm.rules 99-mount-rules; do
+    : > "/etc/udev/rules.d/$x"
+done
+rm -f -- /etc/lvm/lvm.conf
+udevadm control --reload
+set -e
+
+udevadm settle
+mkfs.ext4 -q -L dracut /dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_root
+mkdir -p /root
+mount -t ext4 /dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_root /root
+cp -a -t /root /source/*
+mkdir -p /root/run
+umount /root
+echo "dracut-root-block-created" | dd oflag=direct,dsync of=/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_marker status=none
+poweroff -f
diff --git a/test/TEST-05-SYSTEMD-INITRD/test.sh b/test/TEST-05-SYSTEMD-INITRD/test.sh
new file mode 100755 (executable)
index 0000000..43eee0d
--- /dev/null
@@ -0,0 +1,85 @@
+#!/bin/bash
+# shellcheck disable=SC2034
+TEST_DESCRIPTION="root filesystem on a ext4 filesystem"
+
+test_check() {
+    command -v systemctl &> /dev/null
+}
+
+# Uncomment this to debug failures
+#DEBUGFAIL="rd.shell=1 rd.break=pre-mount"
+test_run() {
+    declare -a disk_args=()
+    declare -i disk_index=0
+    qemu_add_drive disk_index disk_args "$TESTDIR"/marker.img marker
+    qemu_add_drive disk_index disk_args "$TESTDIR"/root.img root
+
+    test_marker_reset
+    "$testdir"/run-qemu \
+        "${disk_args[@]}" \
+        -append "$TEST_KERNEL_CMDLINE root=LABEL=dracut rw systemd.log_target=console rd.retry=3 init=/sbin/init" \
+        -initrd "$TESTDIR"/initramfs.testing || return 1
+
+    test_marker_check || return 1
+}
+
+test_setup() {
+    # Create what will eventually be our root filesystem onto an overlay
+    "$DRACUT" -N -l --keep --tmpdir "$TESTDIR" \
+        -m "test-root" \
+        -f "$TESTDIR"/initramfs.root "$KVERSION" || return 1
+    mkdir -p "$TESTDIR"/overlay/source && mv "$TESTDIR"/dracut.*/initramfs/* "$TESTDIR"/overlay/source && rm -rf "$TESTDIR"/dracut.*
+
+    # second, install the files needed to make the root filesystem
+    # create an initramfs that will create the target root filesystem.
+    # We do it this way so that we do not risk trashing the host mdraid
+    # devices, volume groups, encrypted partitions, etc.
+    "$DRACUT" -N -l -i "$TESTDIR"/overlay / \
+        -m "test-makeroot" \
+        -i ./create-root.sh /lib/dracut/hooks/initqueue/01-create-root.sh \
+        --nomdadmconf \
+        --no-hostonly-cmdline -N \
+        -f "$TESTDIR"/initramfs.makeroot "$KVERSION" || return 1
+    rm -rf -- "$TESTDIR"/overlay
+
+    declare -a disk_args=()
+    declare -i disk_index=0
+    qemu_add_drive disk_index disk_args "$TESTDIR"/marker.img marker 1
+    qemu_add_drive disk_index disk_args "$TESTDIR"/root.img root 80
+
+    # Invoke KVM and/or QEMU to actually create the target filesystem.
+    "$testdir"/run-qemu \
+        "${disk_args[@]}" \
+        -append "root=/dev/fakeroot rw rootfstype=ext4 quiet console=ttyS0,115200n81" \
+        -initrd "$TESTDIR"/initramfs.makeroot || return 1
+    test_marker_check dracut-root-block-created || return 1
+    rm -- "$TESTDIR"/marker.img
+
+    # directory for test configurations
+    mkdir -p /tmp/dracut.conf.d
+
+    # grab the distro configuration from the host and make it available for the tests
+    if [ -d /usr/lib/dracut/dracut.conf.d ]; then
+        cp -a /usr/lib/dracut/dracut.conf.d /tmp/
+    fi
+
+    # pick up configuration from /tmp/dracut.conf.d when running the tests
+    TEST_DRACUT_ARGS+=" --local --confdir /tmp/dracut.conf.d --no-early-microcode --force --kver $KVERSION"
+
+    # include $TESTDIR"/overlay if exists
+    if [ -d "$TESTDIR"/overlay ]; then
+        TEST_DRACUT_ARGS+=" --include $TESTDIR/overlay /"
+    fi
+
+    # shellcheck disable=SC2162
+    IFS=' ' read -a TEST_DRACUT_ARGS_ARRAY <<< "$TEST_DRACUT_ARGS"
+
+    "$DRACUT" \
+        --kernel-cmdline "rd.retry=10 rd.info rd.shell=0" \
+        "${TEST_DRACUT_ARGS_ARRAY[@]}" \
+        -m "kernel-modules systemd-initrd qemu test-root" \
+        "$TESTDIR"/initramfs.testing
+}
+
+# shellcheck disable=SC1090
+. "$testdir"/test-functions