disk: systemd-repart compatibility#2510
Merged
Merged
Conversation
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>
avitova
approved these changes
Jul 15, 2026
avitova
left a comment
Contributor
There was a problem hiding this comment.
Very cool, I learned new things! TY!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A few commits that make our partition tables compatible with what
systemd-repartexpects. 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.