Skip to content

repack-variant improvements#680

Merged
jpculp merged 3 commits into
bottlerocket-os:developfrom
jpculp:repack-variant-improvements
Jul 8, 2026
Merged

repack-variant improvements#680
jpculp merged 3 commits into
bottlerocket-os:developfrom
jpculp:repack-variant-improvements

Conversation

@jpculp

@jpculp jpculp commented Jun 26, 2026

Copy link
Copy Markdown
Member

Description of changes:

Hardens the img2img repack script by:

  • Replacing bare dd calls with a write_partition() helper that adds fsync and sha256 read-back comparison to catch silent corruption or truncation.
  • Consolidating scattered inline debugfs heredoc blocks into a debugfs_replace() helper that verifies each file write and SELinux label immediately rather than batching error checks.
  • Documenting the repack-variant workflow in the design doc.

Tradeoffs:

  • Adds ~10-15s of repack time for hash verification across partition writes.

Testing done:

  • repack-variant on a secure-boot variant (exercises all debugfs_replace and write_partition paths including EFI resign)

Terms of contribution:

By submitting this pull request, I agree that this contribution is dual-licensed under the terms of both the Apache License, version 2.0, and the MIT license.

Add a write_partition helper that hashes the source image before
writing, flushes with fsync, reads back from the target offset, and
compares. This catches truncated writes, filesystem corruption, or
Docker storage driver issues that the previous bare dd calls could
not detect.

Signed-off-by: Patrick J.P. Culp <jpculp@amazon.com>
Comment thread twoliter/embedded/img2img
EOF

local unexpected
unexpected="$(grep -Ev '^debugfs [0-9]+\.[0-9]+\.[0-9]+ \([^)]+\)$' "${errlog}" || true)"

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.

The new filter ^debugfs [0-9]+.[0-9]+.[0-9]+ ([^)]+)$ matches today's e2fsprogs banner (debugfs 1.47.0 (5-Feb-2023)) but is tighter than the previous ^debugfs filter. A future SDK bump that produces any of these would silently break every repack-variant with a misleading "debugfs produced unexpected output" error:
• 4-component versions (1.47.0.1)
• RC/WIP suffixes (1.47.1-WIP)
• Extra startup lines

Not sure though if we should be concerned by any of these corner cases though

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Actually that is the intended behavior. If there is any deviation in debugfs we need it to fail so that we can validate that things still work as we expect. I suspect this will result in mild annoyances in the future, but it's a small price to pay given the risk of debugfs doing something unexpected.

Comment thread twoliter/embedded/img2img Outdated
Comment thread docs/design/README.md
This will allow maintainers to audit which kit each package was taken from.
The rest of the variant image creation steps proceed the same way that they do now.

## Twoliter Repack

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.

Two small improvements:

  1. Add a one-liner distinguishing when to use fetch-variant vs. build-variant as the repack input.
  2. Enumerate the replaceable artifacts (CA bundle, root.json, Secure Boot keys, grub.cfg) — they're already mentioned generically in the intro.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

  1. Sure thing.
  2. I was hesitant to enumerate just because I'd hate for the doc to fall out of date if more customization are added down the line.

jpculp added 2 commits June 26, 2026 13:39
Extract `debugfs_write` which handles the rm/write/ea_set pattern,
stderr validation, file existence verification, and SELinux label
verification in one place. This removes duplicated heredoc logic
across root, kernel, and grub writes, and ensures each write is
individually verified.

Signed-off-by: Patrick J.P. Culp <jpculp@amazon.com>
Signed-off-by: Patrick J.P. Culp <jpculp@amazon.com>
@jpculp jpculp force-pushed the repack-variant-improvements branch from ecff0e4 to 130810d Compare June 26, 2026 21:27
@jpculp jpculp merged commit dcb5c67 into bottlerocket-os:develop Jul 8, 2026
3 checks passed
@jpculp jpculp deleted the repack-variant-improvements branch July 8, 2026 00:01
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