Skip to content

Commit

Permalink
stages/disks: add logic to resize an existing partition
Browse files Browse the repository at this point in the history
Fixes coreos#924
This fix will allow users to resize an existing partition without wiping
out an entry from the partition table.
  • Loading branch information
sohankunkerkar committed Sep 11, 2020
1 parent 6cfc2c7 commit 4a33767
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion internal/exec/stages/disks/partitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.Resize != nil && *part.Resize

// This is a translation of the matrix in the operator notes.
switch {
Expand All @@ -353,7 +354,23 @@ 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)
number := part.Number == info.Number
label := part.Label == nil || *part.Label == info.Label
start := part.StartSector == nil || *part.StartSector == info.StartSector
guid := part.GUID == nil || *part.GUID == "" || strings.ToLower(*part.GUID) == strings.ToLower(info.GUID)
typeGUID := part.TypeGUID == nil || *part.TypeGUID == "" || strings.ToLower(*part.TypeGUID) == strings.ToLower(info.TypeGUID)
if resize && number && label && start && guid && typeGUID {
s.Logger.Info("partition %d found with resize option, resizing partition", part.Number)
op.DeletePartition(part.Number)
part.Number = info.Number
part.GUID = &info.GUID
part.TypeGUID = &info.TypeGUID
part.Label = &info.Label
part.StartSector = &info.StartSector
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)
Expand Down

0 comments on commit 4a33767

Please sign in to comment.