#1129567 mmdebstrap: call tar with --sparse (workaround https://github.com/systemd/systemd/issues/36370)

Package:
mmdebstrap
Source:
mmdebstrap
Submitter:
Trent W. Buck
Date:
2026-03-03 01:27:02 UTC
Severity:
normal
Tags:
#1129567#5
Date:
2026-03-03 01:25:10 UTC
From:
To:
systemd-repart can construct a new disk image with
an EFI ESP partition and a root partition.
I am experimentally running systemd-repart inside mmdebstrap.

As at v257, systemd-repart often creates a <500MB disk image with >200MB empty space.
Whether this is preventable is out-of-scope for mmdebstrap.
In the meantime, mmdebstrap can handle these files more efficiently if
it calls tar with --sparse.

I can think of at least three ways to get the disk image out of mmdebstrap:

1. mmdebstrap trixie - ⋯ | tar --sparse -x disk.img
   This uses tar.

2. mmdebstrap trixie /dev/null ⋯ --customize-hook='copy-out disk.img .'
   This uses tar.
   I think this is the method I will actually use.

3. mmdebstrap trixie /dev/null ⋯ --customize-hook='download disk.img disk.img'
   This uses cat.
   I won't try to fix this.


I added four --sparse calls to mmdebstrap's tar invocations.
I'm not sure if it's appropriate to have all four.
I did not try to undertand --sparse-format= and its interaction with --format=pax.
A patch (and the patched file) is attached.

A test script and its output is attached.
It is intentionally a minimal viable test, so it shows only a ~11MB saving.
In real-world use I expect about ~240MB saving.

When I run this test script on tmpfs, I see an improvement.
When I run this test script on ZFS with transparent compression,
both BEFORE and AFTER appear to already be fixed (fallocate reports 0 bytes).
I think this probably makes sense, but it confused me at first.