Skip to content

Commit

Permalink
Image Customizer: Fix partition creation on Ubuntu build hosts. (#10902)
Browse files Browse the repository at this point in the history
The change #10804 (Toolkit: Add missing flock calls) seems to have caused a problem where on Ubuntu 22.04 build hosts, the partition info isn't populated quickly enough after partition creation and formatting. So, the `lsblk` call might return missing information. Adding a `partprobe` call before the `lsblk` call seems to fix the problem.
  • Loading branch information
cwize1 authored Oct 31, 2024
1 parent 1f7349b commit 6836510
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
6 changes: 6 additions & 0 deletions toolkit/tools/pkg/imagecustomizerlib/imageutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ func createImageBoilerplate(imageConnection *ImageConnection, filename string, b
return nil, "", fmt.Errorf("failed to create partitions on disk (%s):\n%w", imageConnection.Loopback().DevicePath(), err)
}

// Refresh partition entries under /dev.
err = refreshPartitions(imageConnection.Loopback().DevicePath())
if err != nil {
return nil, "", err
}

// Read the disk partitions.
diskPartitions, err := diskutils.GetDiskPartitions(imageConnection.Loopback().DevicePath())
if err != nil {
Expand Down
11 changes: 11 additions & 0 deletions toolkit/tools/pkg/imagecustomizerlib/partitionutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/microsoft/azurelinux/toolkit/tools/internal/logger"
"github.com/microsoft/azurelinux/toolkit/tools/internal/safechroot"
"github.com/microsoft/azurelinux/toolkit/tools/internal/safemount"
"github.com/microsoft/azurelinux/toolkit/tools/internal/shell"
"github.com/microsoft/azurelinux/toolkit/tools/internal/sliceutils"
)

Expand Down Expand Up @@ -460,3 +461,13 @@ func getPartitionNum(partitionLoopDevice string) (int, error) {

return num, nil
}

func refreshPartitions(diskDevPath string) error {
err := shell.ExecuteLiveWithErr(1 /*stderrLines*/, "flock", "--timeout", "5", diskDevPath,
"partprobe", "-s", diskDevPath)
if err != nil {
return fmt.Errorf("partprobe failed:\n%w", err)
}

return nil
}
4 changes: 2 additions & 2 deletions toolkit/tools/pkg/imagecustomizerlib/shrinkfilesystems.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ func shrinkFilesystems(imageLoopDevice string, verity []imagecustomizerapi.Verit
}

// Re-read the partition table
err = shell.ExecuteLive(true, "flock", "--timeout", "5", imageLoopDevice, "partprobe", "-s", imageLoopDevice)
err = refreshPartitions(imageLoopDevice)
if err != nil {
return fmt.Errorf("partprobe failed:\n%w", err)
return err
}
}
return nil
Expand Down

0 comments on commit 6836510

Please sign in to comment.