]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Add "network" initrd profile
authorAntonio Alvarez Feijoo <antonio.feijoo@suse.com>
Thu, 10 Jul 2025 12:48:42 +0000 (14:48 +0200)
committerAntonio Alvarez Feijoo <antonio.feijoo@suse.com>
Thu, 10 Jul 2025 12:48:42 +0000 (14:48 +0200)
This profile provides networking in the initrd using systemd-networkd.

mkosi/config.py
mkosi/initrd.py
mkosi/resources/man/mkosi-initrd.1.md
mkosi/resources/man/mkosi.1.md
mkosi/resources/mkosi-initrd/mkosi.profiles/network/mkosi.conf.d/systemd-networkd.conf [new file with mode: 0644]
mkosi/resources/mkosi-initrd/mkosi.profiles/network/mkosi.conf.d/systemd-resolved.conf [new file with mode: 0644]

index c966260a86b129b11c11be0f7ea317fb2e8dbb81..25585a8bb652759625d4192b36cfa5106fd80ae0 100644 (file)
@@ -636,6 +636,7 @@ class ToolsTreeProfile(StrEnum):
 
 class InitrdProfile(StrEnum):
     lvm = enum.auto()
+    network = enum.auto()
     pkcs11 = enum.auto()
     plymouth = enum.auto()
     raid = enum.auto()
index 42e00546eba9b81f447660d0dfd59ee1bddc2fa8..3c61eec6a5e3d7da77972575159a28c15f473611 100644 (file)
@@ -196,6 +196,20 @@ def process_crypttab(staging_dir: Path) -> list[str]:
     return cmdline
 
 
+def network_config() -> list[str]:
+    return [
+        f"--extra-tree={f}:{f}"
+        for f in (
+            "/etc/systemd/network",
+            "/etc/systemd/networkd.conf",
+            "/etc/systemd/networkd.conf.d",
+            "/etc/systemd/resolved.conf",
+            "/etc/systemd/resolved.conf.d",
+        )
+        if Path(f).exists()
+    ]
+
+
 def raid_config() -> list[str]:
     return [
         f"--extra-tree={f}:{f}"
@@ -333,7 +347,9 @@ def main() -> None:
 
         for p in args.profile:
             cmdline += ["--profile", p]
-            if p == "raid":
+            if p == "network":
+                cmdline += network_config()
+            elif p == "raid":
                 cmdline += raid_config()
 
         if args.kernel_image:
index 5131c31025e4d2e48869efcfe2ddec6e66961a5b..232085ce33f1972f82a1e77a3a4a7267e562293a 100644 (file)
@@ -45,6 +45,7 @@ initrds and Unified Kernel Images for the current running system.
     disabled.
 
     The `lvm` profile enables support for LVM.
+    The `network` profile enables support for network via **systemd-networkd**.
     The `pkcs11` profile enables support for PKCS#11.
     The `plymouth` profile provides a graphical interface at boot (animation and
     password prompt).
index feea867a98d026522aef4ef68364621280ff43db..f9fca65c872f98981b601c29d3526e3a401af408 100644 (file)
@@ -1053,6 +1053,7 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`,
     disabled.
 
     The `lvm` profile enables support for LVM.
+    The `network` profile enables support for network via **systemd-networkd**.
     The `pkcs11` profile enables support for PKCS#11.
     The `plymouth` profile provides a graphical interface at boot (animation and
     password prompt).
diff --git a/mkosi/resources/mkosi-initrd/mkosi.profiles/network/mkosi.conf.d/systemd-networkd.conf b/mkosi/resources/mkosi-initrd/mkosi.profiles/network/mkosi.conf.d/systemd-networkd.conf
new file mode 100644 (file)
index 0000000..b81de46
--- /dev/null
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+[Match]
+Distribution=|fedora
+Distribution=|opensuse
+
+[Content]
+Packages=systemd-networkd
diff --git a/mkosi/resources/mkosi-initrd/mkosi.profiles/network/mkosi.conf.d/systemd-resolved.conf b/mkosi/resources/mkosi-initrd/mkosi.profiles/network/mkosi.conf.d/systemd-resolved.conf
new file mode 100644 (file)
index 0000000..4ecc6e5
--- /dev/null
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+[Match]
+Distribution=!arch
+
+[Content]
+Packages=systemd-resolved