From 1dbd2bc364061cd3d0acf89e841957b2a75137fa Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Mon, 20 Dec 2021 19:27:06 +0100 Subject: [PATCH] disk: use new alignment helper to align partitions Align partitions during their re-layout. Specifically, we align the first partition which removes the need for the hard coded magic number of 2048, which represents the proper alignment for a grain size of 1MB given a sector size of 512 (our setup). NB: Since all our partitions should sizes that are themselves aligned, i.e. evenly dividable by the default grain (1MB) this will not actually change any manifest. --- internal/disk/customizations.go | 5 ++--- internal/disk/disk.go | 10 ++++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/internal/disk/customizations.go b/internal/disk/customizations.go index 72af3c4da..9fdf10f13 100644 --- a/internal/disk/customizations.go +++ b/internal/disk/customizations.go @@ -46,9 +46,8 @@ func CreatePartitionTable( } } - // start point for all of the arches is - // 2048 sectors. - table.updatePartitionStartPointOffsets(2048, imageSize) + // Calculate partition table offsets and sizes + table.updatePartitionStartPointOffsets(imageSize) // Generate new UUIDs for filesystems and partitions table.GenerateUUIDs(rng) diff --git a/internal/disk/disk.go b/internal/disk/disk.go index 5eb669f87..f67e6fa25 100644 --- a/internal/disk/disk.go +++ b/internal/disk/disk.go @@ -330,7 +330,12 @@ func (pt *PartitionTable) GenerateUUIDs(rng *rand.Rand) { // value in `size` or to the sum of all partitions if that is lager. // Will grow the root partition if there is any empty space. // Returns the updated start point. -func (pt *PartitionTable) updatePartitionStartPointOffsets(start, size uint64) uint64 { +func (pt *PartitionTable) updatePartitionStartPointOffsets(size uint64) uint64 { + + // initial alignment + start := pt.AlignUp(0) + size = pt.SectorsToBytes(pt.AlignUp(pt.BytesToSectors(size) - 1)) + var rootIdx = -1 for i := range pt.Partitions { partition := &pt.Partitions[i] @@ -339,6 +344,7 @@ func (pt *PartitionTable) updatePartitionStartPointOffsets(start, size uint64) u continue } partition.Start = start + partition.Size = pt.AlignUp(partition.Size - 1) start += partition.Size } @@ -354,7 +360,7 @@ func (pt *PartitionTable) updatePartitionStartPointOffsets(start, size uint64) u // If the sum of all partitions is bigger then the specified size, // we use that instead. Grow the partition table size if needed. - end := root.Start + padding + root.Size + end := pt.AlignUp(root.Start + padding + root.Size - 1) if endBytes := pt.SectorsToBytes(end); endBytes > size { size = endBytes }