Skip to content

Commit 49c865c

Browse files
authored
Image Customizer: Fix partition creation on Ubuntu build hosts. (#10897)
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.
1 parent f6aa123 commit 49c865c

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

toolkit/tools/pkg/imagecustomizerlib/imageutils.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,12 @@ func createImageBoilerplate(imageConnection *ImageConnection, filename string, b
183183
return nil, "", fmt.Errorf("failed to create partitions on disk (%s):\n%w", imageConnection.Loopback().DevicePath(), err)
184184
}
185185

186+
// Refresh partition entries under /dev.
187+
err = refreshPartitions(imageConnection.Loopback().DevicePath())
188+
if err != nil {
189+
return nil, "", err
190+
}
191+
186192
// Read the disk partitions.
187193
diskPartitions, err := diskutils.GetDiskPartitions(imageConnection.Loopback().DevicePath())
188194
if err != nil {

toolkit/tools/pkg/imagecustomizerlib/partitionutils.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/microsoft/azurelinux/toolkit/tools/internal/logger"
1919
"github.com/microsoft/azurelinux/toolkit/tools/internal/safechroot"
2020
"github.com/microsoft/azurelinux/toolkit/tools/internal/safemount"
21+
"github.com/microsoft/azurelinux/toolkit/tools/internal/shell"
2122
"github.com/microsoft/azurelinux/toolkit/tools/internal/sliceutils"
2223
)
2324

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

461462
return num, nil
462463
}
464+
465+
func refreshPartitions(diskDevPath string) error {
466+
err := shell.ExecuteLiveWithErr(1 /*stderrLines*/, "flock", "--timeout", "5", diskDevPath,
467+
"partprobe", "-s", diskDevPath)
468+
if err != nil {
469+
return fmt.Errorf("partprobe failed:\n%w", err)
470+
}
471+
472+
return nil
473+
}

toolkit/tools/pkg/imagecustomizerlib/shrinkfilesystems.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ func shrinkFilesystems(imageLoopDevice string, verity []imagecustomizerapi.Verit
108108
}
109109

110110
// Re-read the partition table
111-
err = shell.ExecuteLive(true, "flock", "--timeout", "5", imageLoopDevice, "partprobe", "-s", imageLoopDevice)
111+
err = refreshPartitions(imageLoopDevice)
112112
if err != nil {
113-
return fmt.Errorf("partprobe failed:\n%w", err)
113+
return err
114114
}
115115
}
116116
return nil

0 commit comments

Comments
 (0)