diff --git a/pkg/disk/partition.go b/pkg/disk/partition.go index b550ea78d9..6549585532 100644 --- a/pkg/disk/partition.go +++ b/pkg/disk/partition.go @@ -59,6 +59,19 @@ func (p *Partition) GetChild(n uint) Entity { return p.Payload } +// fitTo resizes a partition to be either the given the size or the size of its +// payload if that is larger. The payload can be larger if it is a container +// with sized children. +func (p *Partition) fitTo(size uint64) { + payload, isVC := p.Payload.(VolumeContainer) + if isVC { + if payloadMinSize := payload.minSize(size); payloadMinSize > size { + size = payloadMinSize + } + } + p.Size = size +} + func (p *Partition) GetSize() uint64 { return p.Size } diff --git a/pkg/disk/partition_table.go b/pkg/disk/partition_table.go index 563bbc8877..4764d4e4e6 100644 --- a/pkg/disk/partition_table.go +++ b/pkg/disk/partition_table.go @@ -423,6 +423,7 @@ func (pt *PartitionTable) relayout(size uint64) uint64 { continue } partition.Start = start + partition.fitTo(partition.Size) partition.Size = pt.AlignUp(partition.Size) start += partition.Size } @@ -433,6 +434,7 @@ func (pt *PartitionTable) relayout(size uint64) uint64 { root := &pt.Partitions[rootIdx] root.Start = start + root.fitTo(root.Size) // add the extra padding specified in the partition table footer += pt.ExtraPadding