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