Skip to content

disk: systemd-repart compatibility#2510

Merged
supakeen merged 3 commits into
osbuild:mainfrom
supakeen:repart-compatibility
Jul 15, 2026
Merged

disk: systemd-repart compatibility#2510
supakeen merged 3 commits into
osbuild:mainfrom
supakeen:repart-compatibility

Conversation

@supakeen

@supakeen supakeen commented Jul 11, 2026

Copy link
Copy Markdown
Member

A few commits that make our partition tables compatible with what systemd-repart expects. The important commit here is the 'align footer' one.

Currently gated behind flags (which could be dropped if we consider the behavior safe); can be changed and each commit can land independently.

I had closed this PR accidentally when removing my fork during the rename.

supakeen added 3 commits July 11, 2026 07:34
We had a hardcoded default grain size of 1 MiB. This was based on the
default grain size in `sfdisk` (2048 sectors, 512 bytes for the first
LBA).

Other partitioning tooling such as `systemd-repart` uses a different
grain size by default leading to potential mismatches when rounding
partitions or padding up or down to grain sizes.

Let's allow this value to be configured through the image definitions
YAML.

Signed-off-by: Simon de Vlieger <cmdr@supakeen.com>
Some partitioning tools (`systemd-repart`) round down the usable end of
the disk to the grain boundary (made configurable in the previous
commit). This ensures that the *end* of the last partition on disk is
grain aligned.

`images` instead grows the last partition to take up all remaining size
on the disk. When the footer is not aligned to sector size that means
that the last partitions gets slightly larger than one would expect it
to be.

To figure out the size for the last partition we subtract the raw
non-aligned header size (16,896 bytes) from the total disk size and then
grow the last partition to that. This means that the last partition
gains 3,584 bytes (with a 4096 byte grain size).

Aligning the footer size to the grain size has the end result that the
last partition becomes exactly the requested size.

This new behavior is gated behind an `AlignFooter` flag in the partition
table as it's new behavior and it would change all pre-existing
partition tables.

Signed-off-by: Simon de Vlieger <cmdr@supakeen.com>
Some partitioning tools (`systemd-repart`) use the convention that the
first usable sector is the first LBA. The convention for this is sector
2048 (1 MiB). This is then rounded up to the grain size.

`images` computes the start as `AlignUp(header + StartOffset)`. With the
previous default grain size of 1 MiB this means that the first partition
always started at 1 MiB when no `StartOffset` was provided.

When the grain is configured to be smaller (4096 bytes) it instead
produces sector 40 (20,480 bytes) which falls inside the reserved range
`sfdisk` claims which then makes `sfdisk` reject the partition table
because we don't pass `--first-lba` in the stage (and we probably don't
want to either).

Adding an `AbsoluteStartOffset` toggle allows us to set the offset to 1
MiB exactly; mimicking `systemd-repart`'s behavior.

Signed-off-by: Simon de Vlieger <cmdr@supakeen.com>
@supakeen
supakeen requested review from a team and achilleas-k as code owners July 11, 2026 05:36

@brlane-rht brlane-rht left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@avitova avitova left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool, I learned new things! TY!

@supakeen
supakeen added this pull request to the merge queue Jul 15, 2026
Merged via the queue into osbuild:main with commit 696f1d5 Jul 15, 2026
52 checks passed
@supakeen
supakeen deleted the repart-compatibility branch July 15, 2026 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants