forked from coreos/ignition-dracut
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add coreos-teardown-initramfs-network.service
This is a forward port of coreos-teardown-initramfs-network.service from the spec2x branch [1] (used for RHEL CoreOS). When moving to NM in the initrd [2] we decided that we also needed a mechanism to take down the networking between the initramfs and the real root. While we would like to use NetworkManager's logic to do this operation in the future it's currently not easily achieved because NetworkManager is not running persistently in the initramfs [3]. [1] coreos#78 [2] coreos/fedora-coreos-tracker#394 [3] https://bugzilla.redhat.com/show_bug.cgi?id=1814038
- Loading branch information
Showing
4 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
dracut/30ignition/coreos-teardown-initramfs-network.service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Clean up the initramfs networking on first boot | ||
# so the real network is being brought up | ||
# https://github.com/coreos/fedora-coreos-tracker/issues/394#issuecomment-599721763 | ||
|
||
[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 ExecStart= fails, the boot fails | ||
OnFailure=emergency.target | ||
OnFailureJobMode=isolate | ||
|
||
[Service] | ||
Type=oneshot | ||
RemainAfterExit=yes | ||
ExecStop=/usr/sbin/coreos-teardown-initramfs-network |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/bin/bash | ||
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- | ||
# ex: ts=8 sw=4 sts=4 et filetype=sh | ||
|
||
set -euo pipefail | ||
|
||
down_interface() { | ||
ip link set $1 down | ||
ip addr flush dev $1 | ||
rm -f -- /tmp/net.$1.did-setup | ||
} | ||
|
||
# We want to take down the bonded interfaces first | ||
if [ -f "/sys/class/net/bonding_masters" ]; then | ||
bonds="$(cat /sys/class/net/bonding_masters)" | ||
for b in ${bonds[@]}; do | ||
down_interface ${b} | ||
echo -"${b}" > /sys/class/net/bonding_masters | ||
done | ||
fi | ||
|
||
# Clean up the interfaces set up in the initramfs | ||
# This mimics the behaviour of dracut's ifdown() in net-lib.sh | ||
if ! [ -z "$(ls /sys/class/net)" ]; then | ||
for f in /sys/class/net/*; do | ||
interface=$(basename "$f") | ||
# The `bonding_masters` entry is not a true interface and thus | ||
# cannot be taken down. If they existed, the bonded interfaces | ||
# were taken down earlier in this script. | ||
if [ "$interface" == "bonding_masters" ]; then continue; fi | ||
down_interface $interface | ||
done | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters