From 5160fd50cf2bf09700c20236cac992a7a85fc943 Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Tue, 28 Mar 2017 16:07:09 -0400 Subject: Use pxelinux "ipappend" option to choose rootfs source This fixes the issue described in the first 'netkeys' commit, where the network would need to be available even when it was not used. The "ipappend" option results in a $BOOTIF variable in the initrd environment. This variable is now used to determine whether to wait on the network for a rootfs & keys, or to wait on the boot device becoming available to determine whether it has the keys. That is, there may or may not be a boot device which may or may not have keys and/or rootfs, but we will always know for sure whether it does, therefore there are no races and no waiting on the network unnecessarily. The qemu.sh script was updated to provide the BOOTIF variable when PXE boot is emulated. --- src/initrd/btrfs-create.sh | 24 +++++++++++++++--------- src/initrd/grok-block | 7 +++++-- 2 files changed, 20 insertions(+), 11 deletions(-) (limited to 'src/initrd') diff --git a/src/initrd/btrfs-create.sh b/src/initrd/btrfs-create.sh index a1a53ed..8a0cd87 100644 --- a/src/initrd/btrfs-create.sh +++ b/src/initrd/btrfs-create.sh @@ -27,22 +27,28 @@ ceil4() printf '%d\n' "$x" } +cdrom_has_rootfs() +{ + [ ! "$BOOTIF" ] || return + bootwait samizdat-cdrom + [ -d /cdrom/rootfs ] +} + losetup_layers() { - if netbooting; then + if cdrom_has_rootfs; then + local fs fs_rw + for fs in /cdrom/rootfs/*.btrfs; do + fs_rw=/"${fs##*/}".rw + dd if=/dev/zero of="$fs_rw" bs=1M count=10 + losetup_snapshot "$fs" "$fs_rw" || return + done + else bootwait samizdat-nbd-dev dd if=/dev/zero of=/nbd0.rw bs=1M count=10 dm_snapshot /dev/nbd0 /nbd0.rw return fi - - bootwait samizdat-cdrom - local fs fs_rw - for fs in /cdrom/rootfs/*.btrfs; do - fs_rw=/"${fs##*/}".rw - dd if=/dev/zero of="$fs_rw" bs=1M count=10 - losetup_snapshot "$fs" "$fs_rw" || return - done } init_samizdat() diff --git a/src/initrd/grok-block b/src/initrd/grok-block index 3ad0432..f44ed19 100755 --- a/src/initrd/grok-block +++ b/src/initrd/grok-block @@ -150,8 +150,11 @@ grok_block() # because while it's mounted, the dmsetup stuff will fail with device busy. /dev/nbd0) if [ -e /bootwait/samizdat-nbd-dev ] - then return - else wait_for_files_ /sys/block/nbd0/pid + then + return + else + bootwait nbd-script + wait_for_files_ /sys/block/nbd0/pid fi ;; esac -- cgit v1.2.3