9abf8c
From b75ab376748ee698763610769601bd81296bd060 Mon Sep 17 00:00:00 2001
9abf8c
From: Beniamino Galvani <bgalvani@redhat.com>
9abf8c
Date: Thu, 7 May 2020 07:48:12 +0200
9abf8c
Subject: [PATCH] network-manager: set kernel hostname from the command line
9abf8c
9abf8c
Since commit ff70adf873ef ("initrd: save hostname to a file in /run"),
9abf8c
the initrd generator of NetworkManager parses the hostname from 'ip='
9abf8c
options of the kernel command line and writes it to
9abf8c
/run/NetworkManager/initrd/hostname.
9abf8c
9abf8c
When that file exists, set the kernel hostname.
9abf8c
9abf8c
In presence of multiple hostnames in the command line, the last one
9abf8c
wins. Hostnames from command line always have precedence over ones
9abf8c
received through DHCP. This is a bit different from the legacy network
9abf8c
module that gives higher precedence to the hostname (from DHCP or
9abf8c
command line) of the last interface that is brought up, which depends
9abf8c
on the udev order.
9abf8c
9abf8c
(cherry picked from commit eb770a4a207b2e9e3080068c1df22b69ed44d4b5)
9abf8c
9abf8c
Resolves: #1881974
9abf8c
---
9abf8c
 modules.d/35network-manager/nm-run.sh | 4 ++++
9abf8c
 1 file changed, 4 insertions(+)
9abf8c
9abf8c
diff --git a/modules.d/35network-manager/nm-run.sh b/modules.d/35network-manager/nm-run.sh
9abf8c
index fc5280a1..61752384 100755
9abf8c
--- a/modules.d/35network-manager/nm-run.sh
9abf8c
+++ b/modules.d/35network-manager/nm-run.sh
9abf8c
@@ -10,6 +10,10 @@ for i in /usr/lib/NetworkManager/system-connections/* \
9abf8c
   else
9abf8c
       /usr/sbin/NetworkManager --configure-and-quit=initrd --no-daemon
9abf8c
   fi
9abf8c
+
9abf8c
+  if [ -s /run/NetworkManager/initrd/hostname ]; then
9abf8c
+      cat /run/NetworkManager/initrd/hostname > /proc/sys/kernel/hostname
9abf8c
+  fi
9abf8c
   break
9abf8c
 done
9abf8c
 
9abf8c