Skip to content

Commit

Permalink
Fix shrink partitions race condition. (#26)
Browse files Browse the repository at this point in the history
After changes to a partition table has been made, including resizing a
partition, all the disk's partition nodes under /dev are removed and
then recreated. We need to ensure we wait for this to complete before
trying to shrink the next partition.

Also, remove the call to `partprobe` since calls to `parted` do this
automatically. So, the `partprobe` call is redundant.
  • Loading branch information
cwize1 authored Dec 11, 2024
1 parent 873d3e5 commit 8f51eac
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions toolkit/tools/pkg/imagecustomizerlib/shrinkfilesystems.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,11 @@ func shrinkFilesystems(imageLoopDevice string, verity []imagecustomizerapi.Verit
return fmt.Errorf("failed to resizepart %s with parted (and flock):\n%v", partitionLoopDevice, stderr)
}

// Re-read the partition table
err = refreshPartitions(imageLoopDevice)
// Changes to the partition table causes all of the disk's parition /dev nodes to be deleted and then
// recreated. So, wait for that to finish.
err = diskutils.WaitForDevicesToSettle()
if err != nil {
return err
return fmt.Errorf("failed to list disk (%s) partitions:\n%w", partitionLoopDevice, err)
}
}
return nil
Expand Down

0 comments on commit 8f51eac

Please sign in to comment.