Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

overlay/fcos: pin legacy ifnames on existing machines #490

Merged
merged 1 commit into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions overlay.d/15fcos/usr/lib/systemd/system-preset/45-fcos.preset
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ enable fedora-coreos-pinger.service
# Provide information if no ignition is provided
enable coreos-check-ignition-config.service
enable coreos-check-ssh-keys.service
# Pinning script for legacy interface names, see
# https://github.com/coreos/fedora-coreos-tracker/issues/484
enable coreos-keep-legacy-ifnames.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[Unit]
Description=CoreOS Keep Legacy Network Interface Names
Documentation=https://github.com/coreos/fedora-coreos-tracker/issues/484
RequiresMountsFor=/boot
ConditionPathExists=!/usr/lib/systemd/network/99-default.link
# NOTE: we do not conditionalize on ConditionKernelCommandLine= here because
# kernel args might have been tweaked manually just for this boot; we still
# want to change the BLS entries in that case.

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/libexec/coreos-keep-legacy-ifnames

[Install]
WantedBy=multi-user.target
34 changes: 34 additions & 0 deletions overlay.d/15fcos/usr/libexec/coreos-keep-legacy-ifnames
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash
# This is a pinning script to keep legacy ifnames on machines that were
# installed on an OS version where `99-default.link` was missing due to
# https://github.com/coreos/fedora-coreos-tracker/issues/484

set -euo pipefail

injected=0

if test -e /usr/lib/systemd/network/99-default.link; then
echo "unit /usr/lib/systemd/network/99-default.link found, no actions performed"
exit 0;
fi

for f in /boot/loader/entries/*.conf; do
options=$(grep '^options ' "$f" | cut -f2- -d' ')

# If it is already specified, do not touch whatever value is there.
# This is in order to avoid messing with user customization, and to
# make the logic idempotent.
if grep -q "net.ifnames" <<< "$options"; then
continue
fi

# Otherwise, make sure we stay on legacy ifnames.
sed -e "/^options / s/$/ net.ifnames=0/" -i "$f"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jlebon please double-check the my knowledge here: if injected this way, the net.ifnames=0 will be retained even if the next update payload does not have it in its embedded kargs. Correct?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The update payload doesn't have kargs. Supporting that is ostreedev/ostree#479

So yes it will be retained because there's nothing to override it.

echo "$(basename "$f"): injected net.ifnames=0"
injected=1
done

if [[ $injected -eq 0 ]]; then
echo "existing net.ifnames karg detected, no actions performed"
fi