Skip to content

Add --preserve-numbers to keep partition numbers#11

Draft
eriknordmark wants to merge 1 commit into
diskfs:mainfrom
eriknordmark:preserve-partition-numbers
Draft

Add --preserve-numbers to keep partition numbers#11
eriknordmark wants to merge 1 commit into
diskfs:mainfrom
eriknordmark:preserve-partition-numbers

Conversation

@eriknordmark
Copy link
Copy Markdown

Problem

Growing a partition relocates it into free space and assigns it a new slot, so its partition number changes (e.g. IMGA moves from /dev/sda2 to /dev/sda5). Boot loaders and other consumers that reference a partition by number (e.g. GRUB (hd0,gpt2)) rather than by label or UUID then fail to find it.

Change

Adds an optional --preserve-numbers flag (threaded through Runresize). After the data has been copied and the original identity swapped onto the relocated partition, the new renumberPartitions step drops the vacated original slot and reassigns the relocated partition's GPT index back to the original number, in a single table write. In-place shrinks already preserve their number, so only the grow/relocate path is affected.

resizer --grow-partition label:IMGA:2G --preserve-numbers /dev/sda

Trade-off

The renumbered partition keeps its new on-disk offset, so the GPT entries are no longer in disk-offset order. This is permitted by the GPT specification and is invisible to consumers that locate a partition by number; only tools that expect offset-sorted entries (e.g. gdisk) will note it.

Tests

  • New TestRenumberPartitions unit test covers the renumber/drop logic directly (passes).
  • TestRun is now table-driven over {preserveNumbers: false, true}, asserting every label keeps its original number when the flag is on.

Note: two tests fail on this go-diskfs pin independently of this change (confirmed on a clean main): TestCreatePartitions (a getAlternateLabel assertion mismatch) and TestRun (go-diskfs ext4 journal init: "cannot allocate more than 65535 blocks in a single extent", which aborts before any remove/renumber step). The latter prevents the end-to-end preserve-numbers assertion from exercising on this pin; the direct unit test covers the logic.

When a partition is grown it is relocated into free space and given a
new slot, so its partition number changes (e.g. IMGA moves from
/dev/sda2 to /dev/sda5). Boot loaders and other consumers that hard-code
a partition number rather than locating it by label or UUID then fail to
find it.

Add an optional --preserve-numbers mode. After the data has been copied
and the original identity swapped onto the relocated partition, the new
renumberPartitions step drops the vacated original slot and reassigns the
relocated partition's GPT index back to the original number, in a single
table write. The partition keeps its new on-disk offset, so the GPT
entries are no longer in disk-offset order; this is permitted by the GPT
spec and is invisible to consumers that reference a partition by number.
In-place shrinks already preserve their number, so only the grow/relocate
path is affected.

Signed-off-by: eriknordmark <erik@zededa.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

1 participant