Skip to content

Add SparseOutput= setting to convert disk images to Android sparse format#4271

Open
craftyguy wants to merge 1 commit into
systemd:mainfrom
craftyguy:sparse-image-support
Open

Add SparseOutput= setting to convert disk images to Android sparse format#4271
craftyguy wants to merge 1 commit into
systemd:mainfrom
craftyguy:sparse-image-support

Conversation

@craftyguy
Copy link
Copy Markdown
Contributor

This uses img2simg on the raw disk image after partition splitting but before compression, so split partition artifacts remain usable and the sparse image can still be compressed with CompressOutput=. This is useful for producing images that can be flashed via fastboot. Requires img2simg from android-tools.

I decided to use a new separate option for toggling this, rather than using Format=, because the build pipeline is identical to Format=disk and adding a new format would require updating every OutputFormat.disk check across the codebase. It's also not a CompressOutput= value since sparse is a format conversion, not compression, and users may want to compress the sparse image afterwards.

@craftyguy
Copy link
Copy Markdown
Contributor Author

I'll fix the ruff format failure in CI, but first I'd like feedback on this approach :)

@craftyguy craftyguy force-pushed the sparse-image-support branch from 5ea2639 to 4fb26ab Compare April 11, 2026 00:20
@behrmann
Copy link
Copy Markdown
Contributor

I'll fix the ruff format failure in CI, but first I'd like feedback on this approach :)

I'll talked to @daandemeyer, since I figured that's something that would usually go into repart, but he thinks it's too invasive to reimplement.

Personally, I also think it's somewhat niche as in "it targets something very specific" (notwithstanding, that these are probably by orders of magnitudes the most-widely deployed devices), but I also think it's a good idea to have this be built in, since it's small enough and makes it self-contained to built pmOS images without having to always carry a script around to fix the image up after the fact.

@craftyguy
Copy link
Copy Markdown
Contributor Author

craftyguy commented Apr 15, 2026

@behrmann Thanks for the feedback.

If I could have implemented this in a mkosi script, I totally would have... the problem was that there was no mkosi script that fit exactly where this would need to run. It has to happen after mkosi.finalize (so the image is "complete"), but before mkosi.postoutput so that things like Compression= can be used on it. Basically it falls between steps 30 and 31 (from the manpage):

  30. Generate final output format

  31. Run post‐output scripts (mkosi.postoutput)

I guess I could use a postoutput scrit and extract-->img2simg-->compress again but that's not ideal :(

@behrmann
Copy link
Copy Markdown
Contributor

Sorry if my post was a bit obtuse: I agree that it would be better to have it in mkosi and Daan at least mentioned that he thought it was too invasive for repart.

@craftyguy
Copy link
Copy Markdown
Contributor Author

@behrmann Ohhh ok, ya I misunderstood 😅 Is there anything I should change about this approach?

…rmat

This uses img2simg on the raw disk image after partition splitting but
before compression, so split partition artifacts remain usable and the
sparse image can still be compressed with CompressOutput=. This is
useful for producing images that can be flashed via fastboot. Requires
img2simg from android-tools.

I decided to use a new separate option for toggling this, rather than
using Format=, because the build pipeline is identical to Format=disk
and adding a new format would require updating every OutputFormat.disk
check across the codebase. It's also not a CompressOutput= value since
sparse is a format conversion, not compression, and users may want to
compress the sparse image afterwards.
@craftyguy craftyguy force-pushed the sparse-image-support branch from 4fb26ab to 66a9055 Compare April 21, 2026 22:00
@behrmann
Copy link
Copy Markdown
Contributor

I think the approach looks reasonable.

Would be nice if we had tests for it, but it would be nice if we had pmOS tests in the first place :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants