Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions mkosi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2779,6 +2779,9 @@ def check_inputs(config: Config) -> None:
),
)

if config.sparse_output and config.output_format != OutputFormat.disk:
die("SparseOutput=yes can only be used with Format=disk")

if config.is_incremental() and config.cacheonly == Cacheonly.never:
die("Incremental=yes cannot be used with CacheOnly=never")

Expand Down Expand Up @@ -4186,6 +4189,24 @@ def build_image(context: Context) -> None:
f"Can't change the output size because the image is already larger ({format_bytes(current_size)}) than requested" # noqa: E501
)

if context.config.sparse_output:
if not context.config.find_binary("img2simg"):
die("SparseOutput=yes was requested but img2simg was not found")

output = context.staging / context.config.output_with_format

with complete_step("Converting disk image to Android sparse image…"):
tmp = output.parent / f"{output.name}.tmp"
run(
["img2simg", workdir(output), workdir(tmp)],
sandbox=context.sandbox(
options=[
"--bind", context.staging, workdir(context.staging),
],
),
)
tmp.rename(output)

if context.config.output_format.use_outer_compression():
maybe_compress(
context,
Expand Down Expand Up @@ -4305,6 +4326,8 @@ def run_shell(args: Args, config: Config) -> None:
die(f"Cannot {opname} {config.output_format} images with systemd-nspawn")
if config.output_format.use_outer_compression() and config.compress_output:
die(f"Cannot {opname} compressed {config.output_format} images with systemd-nspawn")
if config.sparse_output:
die(f"Cannot {opname} sparse images with systemd-nspawn")

cmdline: list[PathString] = ["systemd-nspawn", "--quiet", "--link-journal=no", "--suppress-sync=yes"]

Expand Down
9 changes: 9 additions & 0 deletions mkosi/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2101,6 +2101,7 @@ class Config:
sysupdate_dir: Optional[Path]
sector_size: Optional[int]
overlay: bool
sparse_output: bool
seed: uuid.UUID
el_torito: ConfigFeature
el_torito_system: Optional[str]
Expand Down Expand Up @@ -3031,6 +3032,13 @@ def parse_kernel_module_filter_regexp(p: str) -> str:
parse=config_parse_boolean,
help="Only output the additions on top of the given base trees",
),
ConfigSetting(
dest="sparse_output",
metavar="BOOL",
section="Output",
parse=config_parse_boolean,
help="Convert the disk image to Android sparse format",
),
ConfigSetting(
dest="seed",
metavar="UUID",
Expand Down Expand Up @@ -5808,6 +5816,7 @@ def summary(config: Config) -> str:
Repart Directories: {line_join_list(config.repart_dirs)}
Sector Size: {none_to_default(config.sector_size)}
Overlay: {yes_no(config.overlay)}
Sparse Output: {yes_no(config.sparse_output)}
Seed: {none_to_random(config.seed)}
El Torito: {config.el_torito}
El Torito System: {none_to_none(config.el_torito_system)}
Expand Down
2 changes: 2 additions & 0 deletions mkosi/qemu.py
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,8 @@ def run_qemu(args: Args, config: Config) -> None:
OutputFormat.directory,
):
die(f"{config.output_format} images cannot be booted in qemu")
if config.sparse_output:
die("Sparse images cannot be booted in qemu")

if (
config.output_format in (OutputFormat.cpio, OutputFormat.uki, OutputFormat.esp)
Expand Down
6 changes: 6 additions & 0 deletions mkosi/resources/man/mkosi.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,12 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`,

This option may be used to create [systemd *system extensions*](https://uapi-group.org/specifications/specs/extension_image).

`SparseOutput=`, `--sparse-output=`
: Takes a boolean value. If enabled, the output disk image is converted
to Android sparse format using **img2simg**. This is useful for flashing
images via **fastboot**. Can only be used with `Format=disk`. Defaults
to `no`.

`Seed=`, `--seed=`
: Takes a UUID as argument or the special value `random`.
Overrides the seed that **systemd-repart**
Expand Down
2 changes: 2 additions & 0 deletions mkosi/vmspawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def run_vmspawn(args: Args, config: Config) -> None:
OutputFormat.uki,
):
die(f"{config.output_format} images cannot be booted in systemd-vmspawn")
if config.sparse_output:
die("Sparse images cannot be booted in systemd-vmspawn")

kernel = config.expand_linux_specifiers() if config.linux else None
firmware = finalize_firmware(config, kernel)
Expand Down
Loading