]> git.proxmox.com Git - pve-container.git/blobdiff - src/PVE/LXC/Setup/Fedora.pm
enable systemd-networkd per preset in fedora 37+
[pve-container.git] / src / PVE / LXC / Setup / Fedora.pm
index 2da9c30bf5da72c022e5201aec3b1a1d20964b3f..021a44ac926e0397216cb61971b0ee50a4d46507 100644 (file)
@@ -11,7 +11,7 @@ sub new {
     my ($class, $conf, $rootdir, $os_release) = @_;
 
     my $version = $os_release->{VERSION_ID};
-    die "unsupported fedora release\n" if !($version >= 22 && $version <= 27);
+    die "unsupported Fedora release '$version'\n" if !($version >= 22 && $version <= 38);
 
     my $self = { conf => $conf, rootdir => $rootdir, version => $version };
 
@@ -29,6 +29,38 @@ sub template_fixup {
 sub setup_init {
     my ($self, $conf) = @_;
     $self->setup_container_getty_service($conf);
+
+    my $version = $self->{version};
+
+    if ($version >= 37) {
+       # systemd-networkd is disabled by the preset in >=37, reenable it
+       # this only affects the first-boot (if no /etc/machien-id exists).
+       $self->ct_mkdir('/etc/systemd/system-preset', 0755);
+       $self->ct_file_set_contents(
+           '/etc/systemd/system-preset/00-pve.preset',
+           "enable systemd-networkd.service\n",
+       );
+    }
 }
 
+sub setup_network {
+    my ($self, $conf) = @_;
+
+    # systemd-networkd is default in fedora-templates from upstream since
+    # 25, however quite a few workarounds were posted in the forum, recommending
+    # to start the (legacy) network.service via /etc/rc.local for fedora > 25.
+    # /etc/sysconfig/network is not present in the templates for fedora > 25.
+    # use its presence to decide, whether to configure the legacy config
+    # additionally for 25, 26, 27.
+
+    my $sysconfig_used = $self->ct_file_exists("/etc/sysconfig/network");
+
+    my $version = $self->{version};
+
+    my $setup_sysconfig = ($version <= 24 || ($version <= 27 && $sysconfig_used));
+    my $setup_systemd = ($version >= 25);
+
+    $self->SUPER::setup_network($conf) if $setup_sysconfig;
+    $self->SUPER::setup_systemd_networkd($conf) if $setup_systemd;
+}
 1;