]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
mkosi: add "burn" verb 🔥🔥🔥
authorLennart Poettering <lennart@poettering.net>
Fri, 10 Nov 2023 09:00:19 +0000 (10:00 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 13 Nov 2023 12:25:16 +0000 (13:25 +0100)
This simply dd's the resulting image to a block device. (Doesn't
actually dd though, uses systemd-repart --copy-from)

i.e. run "mkosi -f burn /dev/sda"

mkosi/__init__.py
mkosi/burn.py [new file with mode: 0644]
mkosi/config.py
mkosi/resources/mkosi.md

index 6343595a07ddec90a125cb4d5e587b3905410c9e..6900d453be7d2106c2d7d42f13bd3e6155f40b86 100644 (file)
@@ -23,6 +23,7 @@ from typing import Optional, TextIO, Union
 
 from mkosi.architecture import Architecture
 from mkosi.archive import extract_tar, make_cpio, make_tar
+from mkosi.burn import run_burn
 from mkosi.config import (
     BiosBootloader,
     Bootloader,
@@ -2868,3 +2869,6 @@ def run_verb(args: MkosiArgs, images: Sequence[MkosiConfig]) -> None:
 
             if args.verb == Verb.coredumpctl:
                 run_coredumpctl(args, last)
+
+            if args.verb == Verb.burn:
+                run_burn(args, last)
diff --git a/mkosi/burn.py b/mkosi/burn.py
new file mode 100644 (file)
index 0000000..08908e9
--- /dev/null
@@ -0,0 +1,40 @@
+# SPDX-License-Identifier: LGPL-2.1+
+
+import os
+import sys
+
+from mkosi.config import MkosiArgs, MkosiConfig, OutputFormat
+from mkosi.log import complete_step, die
+from mkosi.run import run
+
+
+def run_burn(args: MkosiArgs, config: MkosiConfig) -> None:
+    if config.output_format not in (OutputFormat.disk, OutputFormat.esp):
+        die(f"{config.output_format} images cannot be burned to disk")
+
+    fname = config.output_dir_or_cwd() / config.output
+
+    if len(args.cmdline) != 1:
+        die("Expected device argument.");
+
+    device = args.cmdline[0]
+
+    cmd = [
+        "systemd-repart",
+        "--no-pager",
+        "--pretty=no",
+        "--offline=yes",
+        "--empty=force",
+        "--dry-run=no",
+        f"--copy-from={fname}",
+        device,
+    ]
+
+    with complete_step("Burning ðŸ”¥ðŸ”¥ðŸ”¥ to medium…", "Burnt. ðŸ”¥ðŸ”¥ðŸ”¥"):
+        run(
+            cmd,
+            stdin=sys.stdin,
+            stdout=sys.stdout,
+            env=os.environ,
+            log=False,
+        )
index 2da446fb2374b5415a0a52e02cb6190079398488..482fba8bef51640357466e7e4f571818797bd3a8 100644 (file)
@@ -58,15 +58,16 @@ class Verb(StrEnum):
     documentation = enum.auto()
     journalctl    = enum.auto()
     coredumpctl   = enum.auto()
+    burn          = enum.auto()
 
     def supports_cmdline(self) -> bool:
-        return self in (Verb.build, Verb.shell, Verb.boot, Verb.qemu, Verb.ssh, Verb.journalctl, Verb.coredumpctl)
+        return self in (Verb.build, Verb.shell, Verb.boot, Verb.qemu, Verb.ssh, Verb.journalctl, Verb.coredumpctl, Verb.burn)
 
     def needs_build(self) -> bool:
-        return self in (Verb.build, Verb.shell, Verb.boot, Verb.qemu, Verb.serve, Verb.journalctl, Verb.coredumpctl)
+        return self in (Verb.build, Verb.shell, Verb.boot, Verb.qemu, Verb.serve, Verb.journalctl, Verb.coredumpctl, Verb.burn)
 
     def needs_root(self) -> bool:
-        return self in (Verb.shell, Verb.boot)
+        return self in (Verb.shell, Verb.boot, Verb.burn)
 
 
 class ConfigFeature(StrEnum):
index 6bfeb37a7bb4f8f7013f41a403e8f20520d426a2..46e5d8b2e486b77c10db25693b283084aa1b617a 100644 (file)
@@ -28,6 +28,8 @@ mkosi â€” Build Bespoke OS Images
 
 `mkosi [options…] serve`
 
+`mkosi [options…] burn <device>`
+
 `mkosi [options…] bump`
 
 `mkosi [options…] genkey`
@@ -125,6 +127,13 @@ The following command line verbs are known:
   OS images, for example via `machinectl pull-raw â€¦` and `machinectl
   pull-tar â€¦`.
 
+`burn <device>`
+
+: This builds the image if it is not built yet, and then writes it to the
+  specified block device. The partition contents are written as-is, but the GPT
+  partition table is corrected to match sector and disk size of the specified
+  medium.
+
 `bump`
 
 : Bumps the image version from `mkosi.version` and writes the resulting