From 24e952ea0368f829efae65aa9a7b444a7eebc4e0 Mon Sep 17 00:00:00 2001 From: Yu Qi Zhang Date: Thu, 23 May 2019 11:11:44 -0400 Subject: [PATCH] overlay: add 40coreos-network dracut module Add coreos-teardown-initramfs-network.service to run after ignition has finished using initramfs networking, so NetworkManager properly brings up ignition-configured networking in the real root. Otherwise the initramfs network persists into the real root. Signed-off-by: Yu Qi Zhang --- .../coreos-teardown-initramfs-network.service | 20 +++++++++++++++++++ .../coreos-teardown-initramfs-network.sh | 16 +++++++++++++++ .../40coreos-network/module-setup.sh | 14 +++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 overlay/usr/lib/dracut/modules.d/40coreos-network/coreos-teardown-initramfs-network.service create mode 100755 overlay/usr/lib/dracut/modules.d/40coreos-network/coreos-teardown-initramfs-network.sh create mode 100755 overlay/usr/lib/dracut/modules.d/40coreos-network/module-setup.sh diff --git a/overlay/usr/lib/dracut/modules.d/40coreos-network/coreos-teardown-initramfs-network.service b/overlay/usr/lib/dracut/modules.d/40coreos-network/coreos-teardown-initramfs-network.service new file mode 100644 index 000000000..044925382 --- /dev/null +++ b/overlay/usr/lib/dracut/modules.d/40coreos-network/coreos-teardown-initramfs-network.service @@ -0,0 +1,20 @@ +# Clean up the initramfs networking on first boot +# so the real network is being brought up + +[Unit] +Description=Tear down initramfs networking +DefaultDependencies=false +After=ignition-files.service + +# Make sure ExecStop= runs before we switch root +Conflicts=initrd-switch-root.target umount.target +Before=initrd-switch-root.target + +# Make sure if ExecStop= fails, the boot fails +OnFailure=emergency.target +OnFailureJobMode=isolate + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStop=/usr/sbin/coreos-teardown-initramfs-network diff --git a/overlay/usr/lib/dracut/modules.d/40coreos-network/coreos-teardown-initramfs-network.sh b/overlay/usr/lib/dracut/modules.d/40coreos-network/coreos-teardown-initramfs-network.sh new file mode 100755 index 000000000..de40ce539 --- /dev/null +++ b/overlay/usr/lib/dracut/modules.d/40coreos-network/coreos-teardown-initramfs-network.sh @@ -0,0 +1,16 @@ +#!/bin/bash +set -euo pipefail + +# Clean up the interfaces set up in the initramfs +# This mimics the behaviour of dracut's ifdown() in net-lib.sh +# This script should be considered temporary. We eventually +# want to move to NetworkManager based dracut modules. See: +# https://github.com/dracutdevs/dracut/tree/master/modules.d/35network-manager +if ! [ -z "$(ls /sys/class/net)" ]; then + for f in /sys/class/net/*; do + interface=$(basename "$f") + ip link set $interface down + ip addr flush dev $interface + rm -f -- /tmp/net.$interface.did-setup + done +fi diff --git a/overlay/usr/lib/dracut/modules.d/40coreos-network/module-setup.sh b/overlay/usr/lib/dracut/modules.d/40coreos-network/module-setup.sh new file mode 100755 index 000000000..7c9a1a274 --- /dev/null +++ b/overlay/usr/lib/dracut/modules.d/40coreos-network/module-setup.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- +# ex: ts=8 sw=4 sts=4 et filetype=sh + +depends() { + echo ignition +} + +install() { + local unit=coreos-teardown-initramfs-network.service + inst_simple "$moddir/$unit" "$systemdsystemunitdir/$unit" + inst_script "$moddir/coreos-teardown-initramfs-network.sh" \ + "/usr/sbin/coreos-teardown-initramfs-network" +}