Create /etc/hostname in initramfs
authorBenjamin Drung <benjamin.drung@cloud.ionos.com>
Wed, 21 Aug 2019 14:52:54 +0000 (16:52 +0200)
committerBenjamin Drung <benjamin.drung@cloud.ionos.com>
Wed, 21 Aug 2019 14:52:54 +0000 (16:52 +0200)
Persist hostname in /etc/hostname in the initramfs if the hostname is
known.

Signed-off-by: Benjamin Drung <benjamin.drung@cloud.ionos.com>
components/9990-networking.sh

index cfafcb0..92c66ee 100755 (executable)
@@ -133,6 +133,12 @@ do_netsetup ()
                        HWADDR="$(cat "/sys/class/net/${interface}/address")"
                fi
 
+               if [ ! -e "/etc/hostname" ] && [ -n "${HOSTNAME}" ]
+               then
+                       echo "Creating /etc/hostname"
+                       echo "${HOSTNAME}" > /etc/hostname
+               fi
+
                # Only create /etc/hosts if FQDN is known (to let 'hostname -f' query
                # this file). Otherwise DNS will be queried to determine the FQDN.
                if [ ! -e "/etc/hosts" ] && [ -n "${DNSDOMAIN}" ]