From: Stoiko Ivanov <s.ivanov@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH container] setup: template_fixup: remove bogus LXC_NAME line from /etc/hosts
Date: Fri, 9 Jun 2023 19:36:27 +0200 [thread overview]
Message-ID: <20230609173627.3252569-1-s.ivanov@proxmox.com> (raw)
Templates not built directly by us, but redistributed from
images.linuxcontainer.org contain the following line in /etc/hosts:
`127.0.1.1 LXC_NAME`
While it is mostly cosmetic - LXC_NAME, contains an underscore and is
not a valid DNS name.
Simply drop it for newly created containers in template_fixup.
We ship Debian, Devuan ourselves, without this line - so no need for
modification there.
Currently the nixos container-template (see [0]) also does not seem to
contain the line.
Noticed the issue with a fresh fedora container, where systemd-resolved
logs a warning upon boot.
[0] https://nixos.wiki/wiki/Proxmox_Linux_Container
Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
---
src/PVE/LXC/Setup/Alpine.pm | 2 ++
src/PVE/LXC/Setup/ArchLinux.pm | 2 ++
src/PVE/LXC/Setup/Base.pm | 11 +++++++++++
src/PVE/LXC/Setup/CentOS.pm | 2 ++
src/PVE/LXC/Setup/Fedora.pm | 2 ++
src/PVE/LXC/Setup/Gentoo.pm | 2 ++
src/PVE/LXC/Setup/SUSE.pm | 2 ++
7 files changed, 23 insertions(+)
diff --git a/src/PVE/LXC/Setup/Alpine.pm b/src/PVE/LXC/Setup/Alpine.pm
index 87d72be..8672f3c 100644
--- a/src/PVE/LXC/Setup/Alpine.pm
+++ b/src/PVE/LXC/Setup/Alpine.pm
@@ -40,6 +40,8 @@ sub template_fixup {
$self->ct_symlink('/etc/init.d/savecache', '/etc/runlevels/shutdown/savecache');
$self->setup_securetty($conf);
+
+ $self->remove_lxc_name_from_etc_hosts();
}
sub setup_init {
diff --git a/src/PVE/LXC/Setup/ArchLinux.pm b/src/PVE/LXC/Setup/ArchLinux.pm
index 60118ef..e379ea1 100644
--- a/src/PVE/LXC/Setup/ArchLinux.pm
+++ b/src/PVE/LXC/Setup/ArchLinux.pm
@@ -40,6 +40,8 @@ sub template_fixup {
# edit /etc/securetty (enable login on console)
$self->setup_securetty($conf);
+
+ $self->remove_lxc_name_from_etc_hosts();
}
sub setup_init {
diff --git a/src/PVE/LXC/Setup/Base.pm b/src/PVE/LXC/Setup/Base.pm
index 5534397..2d14599 100644
--- a/src/PVE/LXC/Setup/Base.pm
+++ b/src/PVE/LXC/Setup/Base.pm
@@ -841,4 +841,15 @@ sub remove_pve_sections {
return $data =~ s/^\h*\Q$head\E.*^\h*\Q$tail\E.*?$//rgms;
}
+# templates from images.linuxcontainers.org have a bogus LXC_NAME line in /etc/hosts
+sub remove_lxc_name_from_etc_hosts {
+ my ($self) = @_;
+ my $hosts = $self->ct_file_get_contents('/etc/hosts');
+ my @lines = grep { !/^127.0.1.1\s+LXC_NAME$/ } split(/\n/, $hosts);
+
+ $hosts = join("\n", @lines). "\n";
+
+ $self->ct_file_set_contents('/etc/hosts', $hosts);
+}
+
1;
diff --git a/src/PVE/LXC/Setup/CentOS.pm b/src/PVE/LXC/Setup/CentOS.pm
index 1d31cee..e603d6c 100644
--- a/src/PVE/LXC/Setup/CentOS.pm
+++ b/src/PVE/LXC/Setup/CentOS.pm
@@ -119,6 +119,8 @@ sub template_fixup {
# always call so root can login, if /etc/securetty doesn't exists it's a no-op
$self->setup_securetty($conf);
+
+ $self->remove_lxc_name_from_etc_hosts();
}
sub setup_init {
diff --git a/src/PVE/LXC/Setup/Fedora.pm b/src/PVE/LXC/Setup/Fedora.pm
index 17ae7da..6e54a9e 100644
--- a/src/PVE/LXC/Setup/Fedora.pm
+++ b/src/PVE/LXC/Setup/Fedora.pm
@@ -24,6 +24,8 @@ sub template_fixup {
my ($self, $conf) = @_;
$self->setup_securetty($conf);
$self->ct_unlink('/etc/systemd/system/getty@.service');
+
+ $self->remove_lxc_name_from_etc_hosts();
}
sub setup_init {
diff --git a/src/PVE/LXC/Setup/Gentoo.pm b/src/PVE/LXC/Setup/Gentoo.pm
index 6dc8e9f..501db54 100644
--- a/src/PVE/LXC/Setup/Gentoo.pm
+++ b/src/PVE/LXC/Setup/Gentoo.pm
@@ -35,6 +35,8 @@ sub devttydir {
sub template_fixup {
my ($self, $conf) = @_;
$self->setup_securetty($conf);
+
+ $self->remove_lxc_name_from_etc_hosts();
}
sub setup_init {
diff --git a/src/PVE/LXC/Setup/SUSE.pm b/src/PVE/LXC/Setup/SUSE.pm
index 7863b50..3c5fc68 100644
--- a/src/PVE/LXC/Setup/SUSE.pm
+++ b/src/PVE/LXC/Setup/SUSE.pm
@@ -52,6 +52,8 @@ sub template_fixup {
# temporary fix for systemd-firstboot
$self->ct_file_set_contents('/etc/locale.conf', "LANG=C.utf8") if !$self->ct_file_exists('/etc/locale.conf');
$self->ct_symlink('/usr/share/zoneinfo/UTC', '/etc/localtime') if !$self->ct_file_exists('/etc/localtime');
+
+ $self->remove_lxc_name_from_etc_hosts();
}
sub setup_init {
--
2.30.2
next reply other threads:[~2023-06-09 17:36 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-09 17:36 Stoiko Ivanov [this message]
2023-06-13 15:02 ` Stoiko Ivanov
2023-06-13 15:25 ` [pve-devel] applied: " Thomas Lamprecht
2023-06-13 16:46 ` [pve-devel] " Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230609173627.3252569-1-s.ivanov@proxmox.com \
--to=s.ivanov@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal