Add --preserve-numbers to keep partition numbers#11
Draft
eriknordmark wants to merge 1 commit into
Draft
Conversation
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>
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.
Problem
Growing a partition relocates it into free space and assigns it a new slot, so its partition number changes (e.g.
IMGAmoves from/dev/sda2to/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-numbersflag (threaded throughRun→resize). After the data has been copied and the original identity swapped onto the relocated partition, the newrenumberPartitionsstep 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.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
TestRenumberPartitionsunit test covers the renumber/drop logic directly (passes).TestRunis 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(agetAlternateLabelassertion mismatch) andTestRun(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.