diff --git a/internal/exec/stages/disks/partitions.go b/internal/exec/stages/disks/partitions.go index 4e143d0301..af54fccd45 100644 --- a/internal/exec/stages/disks/partitions.go +++ b/internal/exec/stages/disks/partitions.go @@ -339,6 +339,7 @@ func (s stage) partitionDisk(dev types.Disk, devAlias string) error { } matches := exists && matchErr == nil wipeEntry := part.WipePartitionEntry != nil && *part.WipePartitionEntry + resize := part.ResizePartition != nil && *part.ResizePartition // This is a translation of the matrix in the operator notes. switch { @@ -353,7 +354,17 @@ func (s stage) partitionDisk(dev types.Disk, devAlias string) error { case exists && shouldExist && matches: s.Logger.Info("partition %d found with correct specifications", part.Number) case exists && shouldExist && !wipeEntry && !matches: - return fmt.Errorf("Partition %d didn't match: %v", part.Number, matchErr) + if resize { + s.Logger.Info("partition %d found with resizePartition option, wiping partition entry and recreating", part.Number) + var ids []string + ids = append(ids, info.GUID, info.TypeGUID) + // need to preserve the partition ids for resizing + op.PreservePartitionIDs(ids) + op.DeletePartition(part.Number) + op.CreatePartition(part) + } else { + return fmt.Errorf("Partition %d didn't match: %v", part.Number, matchErr) + } case exists && shouldExist && wipeEntry && !matches: s.Logger.Info("partition %d did not meet specifications, wiping partition entry and recreating", part.Number) op.DeletePartition(part.Number) diff --git a/internal/sgdisk/sgdisk.go b/internal/sgdisk/sgdisk.go index 0697af4c65..0963a15848 100644 --- a/internal/sgdisk/sgdisk.go +++ b/internal/sgdisk/sgdisk.go @@ -25,12 +25,13 @@ import ( ) type Operation struct { - logger *log.Logger - dev string - wipe bool - parts []Partition - deletions []int - infos []int + logger *log.Logger + dev string + wipe bool + partitionIDs []string + parts []Partition + deletions []int + infos []int } // We ignore types.Partition.StartMiB/SizeMiB in favor of @@ -59,6 +60,11 @@ func (op *Operation) DeletePartition(num int) { op.deletions = append(op.deletions, num) } +// PreservePartitionIDs preserves the GUID and TypeGUID for a given partition. +func (op *Operation) PreservePartitionIDs(ids []string) { + op.partitionIDs = append(op.partitionIDs, ids...) +} + func (op *Operation) Info(num int) { op.infos = append(op.infos, num) } @@ -137,6 +143,10 @@ func (op Operation) buildOptions() []string { } for _, p := range op.parts { + if len(op.partitionIDs) > 0 { + p.GUID = &op.partitionIDs[0] + p.TypeGUID = &op.partitionIDs[1] + } opts = append(opts, fmt.Sprintf("--new=%d:%s:+%s", p.Number, partitionGetStart(p), partitionGetSize(p))) if p.Label != nil { opts = append(opts, fmt.Sprintf("--change-name=%d:%s", p.Number, *p.Label))