]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
fix(nbd): make nbd work again with systemd
authorHarald Hoyer <harald@redhat.com>
Wed, 31 Mar 2021 14:29:31 +0000 (16:29 +0200)
committerHarald Hoyer <harald@hoyer.xyz>
Mon, 19 Apr 2021 20:41:01 +0000 (22:41 +0200)
* Correct the systemd generated sysroot.mount unit with the options
received by the DHCP request and do a `daemon-reload`.

* Inject the `nbd-client -check /dev/nbd0` in the finished initqueue.

* Reactivate the NBD tests and prepare them for NetworkManager tests.

modules.d/95nbd/nbdroot.sh
modules.d/95nbd/parse-nbdroot.sh
test/TEST-40-NBD/test.sh

index b485c081f2d9ae1270ea4a84d59d414aad5f3c6e..8760ab506799f50cf036e42a372d58ee6973d676 100755 (executable)
@@ -113,6 +113,16 @@ if [ "$root" = "block:/dev/root" -o "$root" = "dhcp" ]; then
         printf '/bin/mount %s\n' \
             "$NEWROOT" \
             > "$hookdir"/mount/01-$$-nbd.sh
+    else
+        mkdir -p /run/systemd/system/sysroot.mount.d
+        cat << EOF > /run/systemd/system/sysroot.mount.d/dhcp.conf
+[Mount]
+Where=/sysroot
+What=/dev/root
+Type=$nbdfstype
+Options=$fsopts
+EOF
+        systemctl --no-block daemon-reload
     fi
     # if we're on systemd, use the nbd-generator script
     # to create the /sysroot mount.
index 1c2e063815c21df97560e29ae7f56d1118ec07f3..1c3f0a0178c116bf7858181934913db8a7f5c66c 100755 (executable)
@@ -60,3 +60,5 @@ if [ -z "$root" ]; then
     root=block:/dev/root
     # the device is created and waited for in ./nbdroot.sh
 fi
+
+echo 'nbd-client -check /dev/nbd0 > /dev/null 2>&1' > "$hookdir"/initqueue/finished/nbdroot.sh
index e9063c2e0f7466f844ad9d65dea63c551bc35f77..3491dd2a65419525e7a758d3e7087e420091aee5 100755 (executable)
@@ -1,7 +1,15 @@
 #!/bin/bash
 
+if [[ $NM ]]; then
+    USE_NETWORK="network-manager"
+    OMIT_NETWORK="network-legacy"
+else
+    USE_NETWORK="network-legacy"
+    OMIT_NETWORK="network-manager"
+fi
+
 # shellcheck disable=SC2034
-TEST_DESCRIPTION="root filesystem on NBD"
+TEST_DESCRIPTION="root filesystem on NBD with $USE_NETWORK"
 
 KVERSION=${KVERSION-$(uname -r)}
 
@@ -10,9 +18,6 @@ KVERSION=${KVERSION-$(uname -r)}
 #SERIAL="tcp:127.0.0.1:9999"
 
 test_check() {
-    # NBD is still too flaky and hangs hard sometimes
-    return 1
-
     if ! type -p nbd-server 2> /dev/null; then
         echo "Test needs nbd-server... Skipping"
         return 1
@@ -90,7 +95,7 @@ client_test() {
     fi
 
     # nbdinfo=( fstype fsoptions )
-    read -a -r nbdinfo < <(awk '{print $2, $3; exit}' "$TESTDIR"/flag.img)
+    read -r -a nbdinfo < <(awk '{print $2, $3; exit}' "$TESTDIR"/flag.img)
 
     if [[ ${nbdinfo[0]} != "$fstype" ]]; then
         echo "CLIENT TEST END: $test_name [FAILED - WRONG FS TYPE] \"${nbdinfo[0]}\" != \"$fstype\""
@@ -140,45 +145,27 @@ client_run() {
         "root=nbd:192.168.50.1:raw:ext3:errors=panic rd.luks=0" \
         ext3 errors=panic || return 1
 
-    #
-    # FIXME! These fail, but probably shouldn't
-    #
-
-    # There doesn't seem to be a good way to validate the NBD options, so
-    # just check that we don't screw up the other options
-    #
-    #    client_test "NBD root=nbd:IP:port:::NBD opts" 52:54:00:12:34:00 \
-    #                "root=nbd:192.168.50.1:raw:::bs=2048 rd.luks=0" || return 1
-    #
-    #    client_test "NBD root=nbd:IP:port:fstype::NBD opts" 52:54:00:12:34:00 \
-    #                "root=nbd:192.168.50.1:raw:ext3::bs=2048 rd.luks=0" ext3 || return 1
-    #
-    #    client_test "NBD root=nbd:IP:port:fstype:fsopts:NBD opts" \
-    #                52:54:00:12:34:00 \
-    #                "root=nbd:192.168.50.1:raw:ext3:errors=panic:bs=2048 rd.luks=0" \
-    #                ext3 errors=panic || return 1
-
     # DHCP root-path parsing
 
-    client_test "NBD root=dhcp DHCP root-path nbd:srv:port" 52:54:00:12:34:01 \
-        "root=dhcp rd.luks=0" || return 1
+    client_test "NBD root=/dev/root netroot=dhcp DHCP root-path nbd:srv:port" 52:54:00:12:34:01 \
+        "root=/dev/root netroot=dhcp ip=dhcp rd.luks=0" || return 1
 
-    client_test "NBD root=dhcp DHCP root-path nbd:srv:port:fstype" \
-        52:54:00:12:34:02 "root=dhcp rd.luks=0" ext3 || return 1
+    client_test "NBD root=/dev/root netroot=dhcp DHCP root-path nbd:srv:port:fstype" \
+        52:54:00:12:34:02 "root=/dev/root netroot=dhcp ip=dhcp rd.luks=0" ext2 || return 1
 
-    client_test "NBD root=dhcp DHCP root-path nbd:srv:port::fsopts" \
-        52:54:00:12:34:03 "root=dhcp rd.luks=0" ext3 errors=panic || return 1
+    client_test "NBD root=/dev/root netroot=dhcp DHCP root-path nbd:srv:port::fsopts" \
+        52:54:00:12:34:03 "root=/dev/root netroot=dhcp ip=dhcp rd.luks=0" ext3 errors=panic || return 1
 
-    client_test "NBD root=dhcp DHCP root-path nbd:srv:port:fstype:fsopts" \
-        52:54:00:12:34:04 "root=dhcp rd.luks=0" ext3 errors=panic || return 1
+    client_test "NBD root=/dev/root netroot=dhcp DHCP root-path nbd:srv:port:fstype:fsopts" \
+        52:54:00:12:34:04 "root=/dev/root netroot=dhcp ip=dhcp rd.luks=0" ext2 errors=panic || return 1
 
     # netroot handling
 
     client_test "NBD netroot=nbd:IP:port" 52:54:00:12:34:00 \
-        "netroot=nbd:192.168.50.1:raw rd.luks=0" || return 1
+        "root=LABEL=dracut netroot=nbd:192.168.50.1:raw ip=dhcp rd.luks=0" || return 1
 
-    client_test "NBD netroot=dhcp DHCP root-path nbd:srv:port:fstype:fsopts" \
-        52:54:00:12:34:04 "netroot=dhcp rd.luks=0" ext3 errors=panic || return 1
+    client_test "NBD root=/dev/root netroot=dhcp DHCP root-path nbd:srv:port:fstype:fsopts" \
+        52:54:00:12:34:04 "root=/dev/root netroot=dhcp ip=dhcp rd.luks=0" ext2 errors=panic || return 1
 
     # Encrypted root handling via LVM/LUKS over NBD
 
@@ -187,7 +174,7 @@ client_run() {
 
     client_test "NBD root=LABEL=dracut netroot=nbd:IP:port" \
         52:54:00:12:34:00 \
-        "root=LABEL=dracut rd.luks.uuid=$ID_FS_UUID rd.lv.vg=dracut netroot=nbd:192.168.50.1:encrypted" || return 1
+        "root=LABEL=dracut rd.luks.uuid=$ID_FS_UUID rd.lv.vg=dracut ip=dhcp netroot=nbd:192.168.50.1:encrypted" || return 1
 
     # XXX This should be ext3,errors=panic but that doesn't currently
     # XXX work when you have a real root= line in addition to netroot=
@@ -219,7 +206,7 @@ make_encrypted_root() {
         mkdir -p "$initdir"
         (
             cd "$initdir" || exit
-            mkdir -p -- dev sys proc etc var/run tmp
+            mkdir -p dev sys proc etc run var/run tmp
             mkdir -p root usr/bin usr/lib usr/lib64 usr/sbin
             for i in bin sbin lib lib64; do
                 ln -sfnr usr/$i $i
@@ -254,7 +241,7 @@ make_encrypted_root() {
             done
             ln -s ../run var/run
         )
-        inst_multiple mkfs.ext3 poweroff cp umount dd
+        inst_multiple mkfs.ext3 poweroff cp umount dd sync
         inst_hook shutdown-emergency 000 ./hard-off.sh
         inst_hook emergency 000 ./hard-off.sh
         inst_hook initqueue 01 ./create-encrypted-root.sh
@@ -298,7 +285,7 @@ make_client_root() {
         mkdir -p "$initdir"
         (
             cd "$initdir" || exit
-            mkdir -p -- dev sys proc etc var/run tmp
+            mkdir -p dev sys proc etc run var/run tmp
             mkdir -p root usr/bin usr/lib usr/lib64 usr/sbin
             for i in bin sbin lib lib64; do
                 ln -sfnr usr/$i $i
@@ -361,7 +348,7 @@ make_server_root() {
     dd if=/dev/zero of="$TESTDIR"/flag.img bs=1M count=1
 
     rm -fr "$TESTDIR"/overlay
-    kernel=$KVERSION
+    export kernel=$KVERSION
     (
         mkdir -p "$TESTDIR"/overlay/source
         # shellcheck disable=SC2030
@@ -419,7 +406,7 @@ EOF
         export initdir=$TESTDIR/overlay
         # shellcheck disable=SC1090
         . "$basedir"/dracut-init.sh
-        inst_multiple sfdisk mkfs.ext3 poweroff cp umount sync dd
+        inst_multiple sfdisk mkfs.ext3 poweroff cp umount sync dd sync
         inst_hook initqueue 01 ./create-server-root.sh
         inst_hook initqueue/finished 01 ./finished-false.sh
         inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
@@ -480,8 +467,8 @@ test_setup() {
         -f "$TESTDIR"/initramfs.server "$KVERSION" || return 1
 
     "$basedir"/dracut.sh -l -i "$TESTDIR"/overlay / \
-        -o "plymouth" \
-        -a "debug watchdog" \
+        -o "plymouth dash iscsi nfs ${OMIT_NETWORK}" \
+        -a "debug watchdog ${USE_NETWORK}" \
         -d "af_packet piix ide-gd_mod ata_piix ext3 ext3 sd_mod e1000 i6300esb ib700wdt" \
         --no-hostonly-cmdline -N \
         -f "$TESTDIR"/initramfs.testing "$KVERSION" || return 1