Skip to content

rootio: fix GPT partition index and sector alignment in Partition() - #216

Open
shcherbak wants to merge 1 commit into
tinkerbell:mainfrom
shcherbak:main
Open

rootio: fix GPT partition index and sector alignment in Partition()#216
shcherbak wants to merge 1 commit into
tinkerbell:mainfrom
shcherbak:main

Conversation

@shcherbak

@shcherbak shcherbak commented Aug 22, 2026

Copy link
Copy Markdown

Two related bugs in rootio/storage/partition.go's Partition() (GPT path) that together make rootio partition silently produce a broken or misaligned partition table:

  1. gpt.Partition.Index is never set. go-diskfs's gpt.Partition requires a 1-based Index into its 128-entry
    GPT array (see table.toBytes() in go-diskfs). Fix: set Index: d.Partitions[x].Number when building each gpt.Partition.
  2. Partition starts are not aligned to a sector/erase-block boundary. The loop computed the next partition's start as sectorEnd + 1, i.e. the very next 512-byte sector after the previous partition's end, with no regard for the underlying physical/logical sector size. On disks with 4Kn or 512e physical sectors (e.g. many enterprise/RAID controllers such as PERC/megaraid, which is what we hit this on) this produces partitions that don't start on a physical sector boundary, which fdisk/parted flag (Partition N does not start on physical sector boundary) and which can hurt performance or, on some controllers, cause issues with subsequent tooling that assumes conventional alignment. Fix: add an alignUp() helper that rounds a sector number up to the next 2048-sector (1MiB) boundary

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