From mboxrd@z Thu Jan 1 00:00:00 1970
Return-Path: <f.weber@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
(No client certificate requested)
by lists.proxmox.com (Postfix) with ESMTPS id 84B2094EB1
for <pve-devel@lists.proxmox.com>; Mon, 16 Jan 2023 17:53:46 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
by firstgate.proxmox.com (Proxmox) with ESMTP id 29B9C24A0
for <pve-devel@lists.proxmox.com>; Mon, 16 Jan 2023 17:53:16 +0100 (CET)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
[94.136.29.106])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
(No client certificate requested)
by firstgate.proxmox.com (Proxmox) with ESMTPS
for <pve-devel@lists.proxmox.com>; Mon, 16 Jan 2023 17:53:14 +0100 (CET)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
by proxmox-new.maurer-it.com (Proxmox) with ESMTP id F1EF2404F8
for <pve-devel@lists.proxmox.com>; Mon, 16 Jan 2023 17:53:12 +0100 (CET)
From: Friedrich Weber <f.weber@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Mon, 16 Jan 2023 17:52:34 +0100
Message-Id: <20230116165234.1460117-1-f.weber@proxmox.com>
X-Mailer: git-send-email 2.30.2
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results: 0
BAYES_00 -1.9 Bayes spam probability is 0 to 1%
KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record
SPF_PASS -0.001 SPF: sender matches SPF record
Subject: [pve-devel] [PATCH container] fix #4460: setup: centos: create
/etc/hostname if it does not exist
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>,
<mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>,
<mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Mon, 16 Jan 2023 16:53:46 -0000
Previously, Setup/CentOS.pm only wrote to /etc/hostname if the file
already existed. Many CT templates of Redhat-derived distros do not
contain that file, so the containers ended up without /etc/hostname.
This caused systemd-hostnamed to report the "static hostname" to be
empty. If networking is handled by NetworkManager, the empty static
hostname caused DHCP requests to be sent without the "Hostname" field,
as reported in #4460.
With this fix, Setup/CentOS.pm creates /etc/hostname if it does not
exist, so NetworkManager correctly reads the hostname and includes it in
DHCP requests.
Manually tested with the following CT templates (checking that
/etc/hostname exists and DHCP requests include the hostname):
* Distros using NetworkManager:
- Alma Linux 9 (almalinux-9-default_20221108_amd64.tar.xz)
- CentOS 8 (centos-8-default_20201210_amd64.tar.xz)
- CentOS 9 Stream (centos-9-stream-default_20221109_amd64.tar.xz)
- Rocky Linux 9 (rockylinux-9-default_20221109_amd64.tar.xz)
* Distros using network-scripts (here, DHCP requests already contained the
hostname without this fix, as network-scripts does not rely on
systemd-hostnamed):
- Alma Linux 8 (almalinux-8-default_20210928_amd64.tar.xz)
- CentOS 7 (centos-7-default_20190926_amd64.tar.xz)
- CentOS 8 Stream (centos-8-stream-default_20220327_amd64.tar.xz)
- Rocky Linux 8 (rockylinux-8-default_20210929_amd64.tar.xz)
Signed-off-by: Friedrich Weber <f.weber@proxmox.com>
---
Question: This will cause Setup/CentOS.pm to create /etc/hostname also
in already-existing containers. I don't think this should any cause
issues for users, but I'm not sure. What do you think?
src/PVE/LXC/Setup/CentOS.pm | 5 ++---
src/test/test-centos6-001/etc/hostname.exp | 1 +
src/test/test-centos6-002/etc/hostname.exp | 1 +
src/test/test-centos8-001/etc/hostname.exp | 1 +
4 files changed, 5 insertions(+), 3 deletions(-)
create mode 100644 src/test/test-centos6-001/etc/hostname.exp
create mode 100644 src/test/test-centos6-002/etc/hostname.exp
create mode 100644 src/test/test-centos8-001/etc/hostname.exp
diff --git a/src/PVE/LXC/Setup/CentOS.pm b/src/PVE/LXC/Setup/CentOS.pm
index 00fecc6..1d31cee 100644
--- a/src/PVE/LXC/Setup/CentOS.pm
+++ b/src/PVE/LXC/Setup/CentOS.pm
@@ -157,9 +157,8 @@ sub set_hostname {
$self->update_etc_hosts($hostip, $oldname, $hostname, $searchdomains);
- if ($self->ct_file_exists($hostname_fn)) {
- $self->ct_file_set_contents($hostname_fn, "$hostname\n");
- }
+ # Always write /etc/hostname, even if it does not exist yet
+ $self->ct_file_set_contents($hostname_fn, "$hostname\n");
if ($self->ct_file_exists($sysconfig_network)) {
my $data = $self->ct_file_get_contents($sysconfig_network);
diff --git a/src/test/test-centos6-001/etc/hostname.exp b/src/test/test-centos6-001/etc/hostname.exp
new file mode 100644
index 0000000..a5bce3f
--- /dev/null
+++ b/src/test/test-centos6-001/etc/hostname.exp
@@ -0,0 +1 @@
+test1
diff --git a/src/test/test-centos6-002/etc/hostname.exp b/src/test/test-centos6-002/etc/hostname.exp
new file mode 100644
index 0000000..180cf83
--- /dev/null
+++ b/src/test/test-centos6-002/etc/hostname.exp
@@ -0,0 +1 @@
+test2
diff --git a/src/test/test-centos8-001/etc/hostname.exp b/src/test/test-centos8-001/etc/hostname.exp
new file mode 100644
index 0000000..a5bce3f
--- /dev/null
+++ b/src/test/test-centos8-001/etc/hostname.exp
@@ -0,0 +1 @@
+test1
--
2.30.2