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