Skip to content

Commit

Permalink
fix(nbd): make nbd work again with systemd
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
haraldh committed Apr 19, 2021
1 parent 8cd5023 commit 7790644
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 42 deletions.
10 changes: 10 additions & 0 deletions modules.d/95nbd/nbdroot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions modules.d/95nbd/parse-nbdroot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
71 changes: 29 additions & 42 deletions test/TEST-40-NBD/test.sh
Original file line number Diff line number Diff line change
@@ -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)}

Expand All @@ -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
Expand Down Expand Up @@ -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\""
Expand Down Expand Up @@ -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

Expand All @@ -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=
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7790644

Please sign in to comment.