]> git.ipfire.org Git - thirdparty/dracut-ng.git/commitdiff
test: support systemd in target rootfs
authorBenjamin Drung <benjamin.drung@canonical.com>
Tue, 28 Oct 2025 13:13:28 +0000 (14:13 +0100)
committerNeal Gompa (ニール・ゴンパ) <ngompa13@gmail.com>
Wed, 29 Oct 2025 00:54:14 +0000 (20:54 -0400)
The test-root module installs `test-init.sh` in `/sbin/test-init` and
adds `testsuite.service` if systemd is used. When systemd is used in the
target client/server rootfs, the systemd in the initrd hands over the
control to the systemd in the rootfs. Then `testsuite.service` executes
`test-init.sh` instead of the wanted client/server init scripts.

Add the helper function `inst_init` to override the init script from the
test-root dracut module.

test/TEST-60-NFS/test.sh
test/TEST-70-ISCSI/test.sh
test/TEST-71-ISCSI-MULTI/test.sh
test/TEST-72-NBD/test.sh
test/test-functions

index 2e922bb685ce21955fada461f8bb5a60db3fb0fc..0b6946bd03b9491e4ab1254b4b12e53736ec3f4b 100755 (executable)
@@ -250,7 +250,7 @@ test_setup() {
     export initdir=$TESTDIR/server/overlay/source
     mkdir -p "$initdir"/var/lib/{dhcpd,rpcbind} "$initdir"/var/lib/nfs/{v4recovery,rpc_pipefs}
     chmod 777 "$initdir"/var/lib/{dhcpd,rpcbind}
-    cp ./server-init.sh "$initdir"/sbin/init
+    inst_init ./server-init.sh "$initdir"
     cp ./exports "$initdir"/etc/exports
     cp ./dhcpd.conf "$initdir"/etc/dhcpd.conf
 
@@ -261,7 +261,7 @@ test_setup() {
     mv "$TESTDIR"/dracut.*/initramfs/* "$initdir"
     rm -rf "$TESTDIR"/dracut.*
     echo "TEST FETCH FILE" > "$initdir"/root/fetchfile
-    cp ./client-init.sh "$initdir"/sbin/init
+    inst_init ./client-init.sh "$initdir"
 
     # 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
index 384cdf3068dc5c5316734e6cb175fd5a8cce508c..54a6ef3845331961c55e2d3d54c9e5fe03825216 100755 (executable)
@@ -139,7 +139,7 @@ test_setup() {
     rm -rf "$TESTDIR"/dracut.*
 
     mkdir -p -- "$TESTDIR"/overlay/source/var/lib/nfs/rpc_pipefs
-    cp ./client-init.sh "$TESTDIR"/overlay/source/sbin/init
+    inst_init ./client-init.sh "$TESTDIR"/overlay/source
 
     # 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
@@ -181,7 +181,7 @@ test_setup() {
     rm -rf "$TESTDIR"/dracut.*
 
     mkdir -p "$TESTDIR"/overlay/source/var/lib/dhcpd
-    cp ./server-init.sh "$TESTDIR"/overlay/source/sbin/init
+    inst_init ./server-init.sh "$TESTDIR"/overlay/source
 
     # 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
index 4733e3ade314eed8389dd8fca620c5c6597e1c94..ff7b85659961fe04b1535a30db9ea0426ed34426 100755 (executable)
@@ -147,7 +147,7 @@ test_setup() {
     mv "$TESTDIR"/dracut.*/initramfs/* "$TESTDIR"/overlay/source
     rm -rf "$TESTDIR"/dracut.*
     mkdir -p -- "$TESTDIR"/overlay/source/var/lib/nfs/rpc_pipefs
-    cp ./client-init.sh "$TESTDIR"/overlay/source/sbin/init
+    inst_init ./client-init.sh "$TESTDIR"/overlay/source
 
     # 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
@@ -190,7 +190,7 @@ test_setup() {
     rm -rf "$TESTDIR"/dracut.*
 
     mkdir -p -- "$TESTDIR"/overlay/source/var/lib/dhcpd "$TESTDIR"/overlay/source/etc/iscsi
-    cp ./server-init.sh "$TESTDIR"/overlay/source/sbin/init
+    inst_init ./server-init.sh "$TESTDIR"/overlay/source
 
     # 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
index 83e96d3d277d49539a744942cdbc15c6d3c3b5e6..a5694a45267b6a79747699fb61b797a058f7fb25 100755 (executable)
@@ -185,7 +185,7 @@ make_encrypted_root() {
     mkdir -p "$TESTDIR"/overlay/source
     mv "$TESTDIR"/dracut.*/initramfs/* "$TESTDIR"/overlay/source
     rm -rf "$TESTDIR"/dracut.*
-    cp ./client-init.sh "$TESTDIR"/overlay/source/sbin/init
+    inst_init ./client-init.sh "$TESTDIR"/overlay/source
 
     # 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
@@ -222,7 +222,7 @@ make_client_root() {
     mkdir -p "$TESTDIR"/overlay/source
     mv "$TESTDIR"/dracut.*/initramfs/* "$TESTDIR"/overlay/source
     rm -rf "$TESTDIR"/dracut.*
-    cp ./client-init.sh "$TESTDIR"/overlay/source/sbin/init
+    inst_init ./client-init.sh "$TESTDIR"/overlay/source
 
     # 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
@@ -275,7 +275,7 @@ EOF
     rm -rf "$TESTDIR"/dracut.*
 
     mkdir -p -- "$TESTDIR"/overlay/source/var/lib/dhcpd "$TESTDIR"/overlay/source/etc/nbd-server
-    cp ./server-init.sh "$TESTDIR"/overlay/source/sbin/init
+    inst_init ./server-init.sh "$TESTDIR"/overlay/source
 
     # 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
index abb526faad109c5562d2e7dd1122a3f63a47b9ec..ef41815442204a7ffa39f44b59125acd41e3ac5c 100644 (file)
@@ -146,6 +146,17 @@ COLOR_FAILURE='\033[0;31m'
 COLOR_WARNING='\033[0;33m'
 COLOR_NORMAL='\033[0;39m'
 
+# override the init script from the test-root dracut module (see module-setup.sh)
+inst_init() {
+    local init_script="$1"
+    local rootdir="$2"
+    if [ -e "$rootdir/sbin/test-init" ]; then
+        cp "$init_script" "$rootdir/sbin/test-init"
+    else
+        cp "$init_script" "$rootdir/sbin/init"
+    fi
+}
+
 # generate qemu arguments for named raw disks
 #
 # qemu_add_drive <index> <args> <filename> <id-name> [<bootindex>]