public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH container] fix #3443: setup: clear /etc/machine-id in post-create hook
@ 2021-05-25 13:17 Oguz Bektas
  2021-05-25 13:45 ` Thomas Lamprecht
  0 siblings, 1 reply; 7+ messages in thread
From: Oguz Bektas @ 2021-05-25 13:17 UTC (permalink / raw)
  To: pve-devel

this way when new containers are created the will have a unique
/etc/machine-id

note that post_create_hook doesn't run for cloned containers so that
will need to be handled separately


Signed-off-by: Oguz Bektas <o.bektas@proxmox.com>
---
 src/PVE/LXC/Setup/Base.pm | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/src/PVE/LXC/Setup/Base.pm b/src/PVE/LXC/Setup/Base.pm
index be41874..75a7f74 100644
--- a/src/PVE/LXC/Setup/Base.pm
+++ b/src/PVE/LXC/Setup/Base.pm
@@ -476,6 +476,18 @@ sub set_timezone {
     }
 }
 
+sub clear_machine_id {
+    my ($self, $conf) = @_;
+
+    my $dbus_machine_id_path = "/var/lib/dbus/machine-id";
+    my $machine_id_path = "/etc/machine-id";
+    if ($self->ct_file_exists($dbus_machine_id_path)) {
+        $self->ct_unlink($dbus_machine_id_path);
+    }
+    $self->ct_unlink($machine_id_path);
+    $self->ct_file_set_contents($machine_id_path, "uninitialized\n");
+}
+
 sub pre_start_hook {
     my ($self, $conf) = @_;
 
@@ -491,6 +503,7 @@ sub pre_start_hook {
 sub post_create_hook {
     my ($self, $conf, $root_password, $ssh_keys) = @_;
 
+    $self->clear_machine_id($conf);
     $self->template_fixup($conf);
 
     $self->randomize_crontab($conf);
-- 
2.20.1




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-05-26 10:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-25 13:17 [pve-devel] [PATCH container] fix #3443: setup: clear /etc/machine-id in post-create hook Oguz Bektas
2021-05-25 13:45 ` Thomas Lamprecht
2021-05-26  9:40   ` Oguz Bektas
2021-05-26  9:46     ` Oguz Bektas
2021-05-26 10:00     ` Thomas Lamprecht
2021-05-26 10:03       ` Oguz Bektas
2021-05-26 10:07         ` Thomas Lamprecht

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal