Skip to content

Commit

Permalink
fix: align first GPT partition entry to 1024 sectors
Browse files Browse the repository at this point in the history
With 512 sector size, first usable LBA is aligned to 2048 already, but
with 4096 sector size, the calculation would end up with 256.

To provide better compatibility with some firmware, make it start at
sector 1024 minimum.

See siderolabs/talos#10097

Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
  • Loading branch information
smira committed Jan 9, 2025
1 parent 7af9654 commit a047647
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions partitioning/gpt/gpt.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,11 @@ func (t *Table) init(lastLBA uint64) {
ioSize = t.sectorSize
}

alignmentSize := max(ioSize, 2048*512)
t.alignment = uint64((alignmentSize + t.sectorSize - 1) / t.sectorSize)
alignmentSize := max(ioSize, 1048576) // align to 1Mib minimum
t.alignment = uint64((alignmentSize + t.sectorSize - 1) / t.sectorSize) // 2048 with 512 sector size, 256 with 4096 sector size

t.firstUsableLBA = (t.firstUsableLBA + t.alignment - 1) / t.alignment * t.alignment
t.firstUsableLBA = (t.firstUsableLBA + t.alignment - 1) / t.alignment * t.alignment // 2048 with 512 sector size, 256 with 4096 sector size
t.firstUsableLBA = max(t.firstUsableLBA, 1024) // make first usable LBA at least 1024 to avoid issues with some BIOSes
}

// Clear the partition table.
Expand Down

0 comments on commit a047647

Please sign in to comment.