]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Disable orphan_file automatically if not supported
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 31 Mar 2025 10:43:50 +0000 (12:43 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 31 Mar 2025 11:47:24 +0000 (13:47 +0200)
Let's automatically detect if the orphan_file ext4 feature needs to
be disabled if it's not supported by the target distribution official
kernel.

mkosi/__init__.py

index 39dd99fcaf8dfd0e9864e3b69ae0851698519f31..f8c28ff5d057953e438f57d40eb52b04253f1135 100644 (file)
@@ -3386,6 +3386,25 @@ def make_image(
         cmdline += ["--definitions", workdir(d)]
         opts += ["--ro-bind", d, workdir(d)]
 
+    def can_orphan_file(distribution: Optional[Distribution], release: Optional[str]) -> bool:
+        if distribution is None:
+            return True
+
+        return not (
+            (distribution == Distribution.centos and release and GenericVersion(release) == 9)
+            or (distribution == Distribution.ubuntu and release == "jammy")
+        )
+
+    # Make sure the ext4 orphan_file feature is disabled if the target distribution official kernel does not
+    # support it.
+    env = {}
+    if (
+        not can_orphan_file(context.config.distribution, context.config.release)
+        and can_orphan_file(*detect_distribution(context.config.tools()))
+        and "SYSTEMD_REPART_MKFS_EXT4_OPTIONS" not in context.config.environment
+    ):
+        env["SYSTEMD_REPART_MKFS_EXT4_OPTIONS"] = "-O ^orphan_file"
+
     with complete_step(msg):
         output = json.loads(
             run_systemd_sign_tool(
@@ -3398,6 +3417,7 @@ def make_image(
                 certificate_source=context.config.verity_certificate_source,
                 key=context.config.verity_key if verity in (Verity.auto, Verity.signed) else None,
                 key_source=context.config.verity_key_source,
+                env=env,
                 stdout=subprocess.PIPE,
                 devices=not context.config.repart_offline,
             ).stdout