From 25a95110cb37f679b47551ffa337ae33b21e18c1 Mon Sep 17 00:00:00 2001 From: Ben Howard Date: Tue, 10 Mar 2020 16:14:21 -0600 Subject: [PATCH] persist-ifcfg: persist the hostname as well For RHCOS, if an admin uses the legacy kargs to set the hostname, then we need to persist the name into /sysroot. This change persist the hostname ONLY if the hostname originated from `ip=...`. --- dracut/30ignition/persist-ifcfg.sh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/dracut/30ignition/persist-ifcfg.sh b/dracut/30ignition/persist-ifcfg.sh index 772ac0b..6590c2a 100755 --- a/dracut/30ignition/persist-ifcfg.sh +++ b/dracut/30ignition/persist-ifcfg.sh @@ -2,6 +2,8 @@ # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh +type info >/dev/null 2>&1 || . /lib/net-lib.sh + cmdline=( $( /proc/sys/kernel/hostname. + read _ iface_hostname _ < "${iface_totems}.hostname" + + # Ensure that the hostname used by the kernel is the same one + # used by this interface. This guard is intended to protect against + # mixed `ip=` or where one is set via dhcp. + if [ "${iface_hostname}" == "${hname}" ]; then + echo "${hname}" > "${hpath}" + echo -ne '/etc/hostname/\0' >> /sysroot/etc/selinux/ignition.relabel + info "persisting hostname set by kargs for ${iface}" + break + fi + done + fi + # Unless overridden, propagate the kernel commandline networking into # ifcfg files, so that users don't have to write the config in both kernel # commandline *and* Ignition.