This patch include a script under finish-install.d/56netcfg-hostname that detect if netcfg/hostname is set in preseed file and override the hostname at the end of the installation. If not set then it keeps the hostname as is.
>From 53522b8129f9542a1d7c9a21344d8b8b2732c9ce Mon Sep 17 00:00:00 2001 From: Eric Desrochers <eric.desroch...@canonical.com> Date: Tue, 20 Sep 2016 20:02:16 -0400 Subject: [PATCH] Fix netcfg/hostname that does not set hostname
--- finish-install.d/56netcfg-hostname | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 finish-install.d/56netcfg-hostname diff --git a/finish-install.d/56netcfg-hostname b/finish-install.d/56netcfg-hostname new file mode 100755 index 0000000..2256c5b --- /dev/null +++ b/finish-install.d/56netcfg-hostname @@ -0,0 +1,17 @@ +#! /bin/sh +set -e + +PROGNAME=$(basename $0) +CURRENT_HOSTNAME=`/bin/hostname` +NETCFG_HOSTNAME=`/bin/debconf-get netcfg/hostname` + +# Override hostname, if "netcfg/hostname" is set in preseed file. # +if [ -n "$NETCFG_HOSTNAME" ]; then + /bin/sed -i "s/$CURRENT_HOSTNAME/$NETCFG_HOSTNAME/" /target/etc/hostname + /bin/sed -i "s/$CURRENT_HOSTNAME/$NETCFG_HOSTNAME/" /target/etc/hosts + /usr/bin/logger "$PROGNAME: d-i netcfg/hostname $NETCFG_HOSTNAME took precedence" + +# Keep hostname as is, if "netcfg/hostname" is not set in preseed file. # +else + exit 0 +fi -- 2.5.0