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.