Skip to content

Commit 29d2973

Browse files
authored
Add ignoreOverlays param to skip overlay for COSI (#373)
<!-- Description: Please provide a summary of the changes and the motivation behind them. --> For COSI generation, connectToExistingImage is called after customization is done, so when there is overlay in the config, fstabEntriesToMountPoints() encounters an overlay entry with source "overlay", isn't in the fstab source types. And overlay should be excluded from partition metadata so this PR addresses this bug by adding ignoreOverlays param --- ### **Checklist** - [ ] Tests added/updated - [ ] Documentation updated (if needed) - [ ] Code conforms to style guidelines Signed-off-by: Elaine Zhao <[email protected]>
1 parent 60d0d55 commit 29d2973

File tree

7 files changed

+15
-11
lines changed

7 files changed

+15
-11
lines changed

toolkit/tools/pkg/imagecustomizerlib/artifactsinputoutput.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ func prepareImageConversionData(ctx context.Context, rawImageFile string, buildD
387387
[]OsPackage, [randomization.UuidSize]byte, string, *CosiBootloader, error,
388388
) {
389389
imageConnection, partUuidToFstabEntry, baseImageVerityMetadata, _, err := connectToExistingImage(ctx,
390-
rawImageFile, buildDir, chrootDir, true, true, false)
390+
rawImageFile, buildDir, chrootDir, true, true, false, false)
391391
if err != nil {
392392
return nil, nil, "", nil, [randomization.UuidSize]byte{}, "", nil, fmt.Errorf("%w:\n%w", ErrArtifactImageConnectionForExtraction, err)
393393
}

toolkit/tools/pkg/imagecustomizerlib/customizepartitionsfilecopy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func customizePartitionsUsingFileCopy(ctx context.Context, buildDir string, base
2525
buildImageFile string, newBuildImageFile string,
2626
) (map[string]string, error) {
2727
existingImageConnection, _, _, _, err := connectToExistingImage(ctx, buildImageFile, buildDir, "imageroot", false,
28-
true, false)
28+
true, false, false)
2929
if err != nil {
3030
return nil, err
3131
}

toolkit/tools/pkg/imagecustomizerlib/imagecreator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func CustomizeImageHelperImageCreator(ctx context.Context, buildDir string, base
3131
defer toolsChroot.Close(false)
3232

3333
imageConnection, partUuidToFstabEntry, _, _, err := connectToExistingImage(ctx, rawImageFile, toolsChrootDir,
34-
toolsRootImageDir, true, false, false)
34+
toolsRootImageDir, true, false, false, false)
3535
if err != nil {
3636
return nil, "", err
3737
}

toolkit/tools/pkg/imagecustomizerlib/imagecustomizer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ func customizeImageHelper(ctx context.Context, buildDir string, baseConfigPath s
10591059
readOnlyVerity := config.Storage.ReinitializeVerity != imagecustomizerapi.ReinitializeVerityTypeAll
10601060

10611061
imageConnection, partUuidToFstabEntry, baseImageVerityMetadata, readonlyPartUuids, err := connectToExistingImage(
1062-
ctx, rawImageFile, buildDir, "imageroot", true, false, readOnlyVerity)
1062+
ctx, rawImageFile, buildDir, "imageroot", true, false, readOnlyVerity, false)
10631063
if err != nil {
10641064
return nil, nil, nil, "", err
10651065
}
@@ -1105,7 +1105,7 @@ func customizeImageHelper(ctx context.Context, buildDir string, baseConfigPath s
11051105
func collectOSInfo(ctx context.Context, buildDir string, rawImageFile string,
11061106
) ([]OsPackage, *CosiBootloader, error) {
11071107
var err error
1108-
imageConnection, _, _, _, err := connectToExistingImage(ctx, rawImageFile, buildDir, "imageroot", true, true, false)
1108+
imageConnection, _, _, _, err := connectToExistingImage(ctx, rawImageFile, buildDir, "imageroot", true, true, false, true)
11091109
if err != nil {
11101110
return nil, nil, err
11111111
}

toolkit/tools/pkg/imagecustomizerlib/imageutils.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ import (
2424
type installOSFunc func(imageChroot *safechroot.Chroot) error
2525

2626
func connectToExistingImage(ctx context.Context, imageFilePath string, buildDir string, chrootDirName string,
27-
includeDefaultMounts bool, readonly bool, readOnlyVerity bool,
27+
includeDefaultMounts bool, readonly bool, readOnlyVerity bool, ignoreOverlays bool,
2828
) (*imageconnection.ImageConnection, map[string]diskutils.FstabEntry, []verityDeviceMetadata, []string, error) {
2929
_, span := otel.GetTracerProvider().Tracer(OtelTracerName).Start(ctx, "connect_to_existing_image")
3030
defer span.End()
3131
imageConnection := imageconnection.NewImageConnection()
3232

3333
partUuidToMountPath, verityMetadata, readonlyPartUuids, err := connectToExistingImageHelper(imageConnection,
34-
imageFilePath, buildDir, chrootDirName, includeDefaultMounts, readonly, readOnlyVerity)
34+
imageFilePath, buildDir, chrootDirName, includeDefaultMounts, readonly, readOnlyVerity, ignoreOverlays)
3535
if err != nil {
3636
imageConnection.Close()
3737
return nil, nil, nil, nil, err
@@ -42,6 +42,7 @@ func connectToExistingImage(ctx context.Context, imageFilePath string, buildDir
4242

4343
func connectToExistingImageHelper(imageConnection *imageconnection.ImageConnection, imageFilePath string,
4444
buildDir string, chrootDirName string, includeDefaultMounts bool, readonly bool, readOnlyVerity bool,
45+
ignoreOverlays bool,
4546
) (map[string]diskutils.FstabEntry, []verityDeviceMetadata, []string, error) {
4647
// Connect to image file using loopback device.
4748
err := imageConnection.ConnectLoopback(imageFilePath)
@@ -65,7 +66,7 @@ func connectToExistingImageHelper(imageConnection *imageconnection.ImageConnecti
6566
}
6667

6768
mountPoints, partUuidToFstabEntry, verityMetadata, readonlyPartUuids, err := fstabEntriesToMountPoints(fstabEntries,
68-
partitions, buildDir, readonly, readOnlyVerity)
69+
partitions, buildDir, readonly, readOnlyVerity, ignoreOverlays)
6970
if err != nil {
7071
return nil, nil, nil, fmt.Errorf("failed to find mount info for fstab file entries:\n%w", err)
7172
}
@@ -259,7 +260,7 @@ func createImageBoilerplate(targetOs targetos.TargetOs, imageConnection *imageco
259260
return nil, "", err
260261
}
261262

262-
mountPoints, _, _, _, err := fstabEntriesToMountPoints(fstabEntries, diskPartitions, buildDir, false, false)
263+
mountPoints, _, _, _, err := fstabEntriesToMountPoints(fstabEntries, diskPartitions, buildDir, false, false, false)
263264
if err != nil {
264265
return nil, "", fmt.Errorf("failed to find mount info for fstab file entries:\n%w", err)
265266
}

toolkit/tools/pkg/imagecustomizerlib/liveosisobuilder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ func createLiveOSFromRawHelper(ctx context.Context, buildDir, baseConfigPath str
198198

199199
logger.Log.Debugf("Connecting to raw image (%s)", rawImageFile)
200200
rawImageConnection, _, _, _, err := connectToExistingImage(ctx, rawImageFile, isoBuildDir, "readonly-rootfs-mount",
201-
false /*includeDefaultMounts*/, false /*readonly*/, false /*readonlyVerity*/)
201+
false /*includeDefaultMounts*/, false /*readonly*/, false /*readonlyVerity*/, false /*ignoreOverlays*/)
202202
if err != nil {
203203
return err
204204
}

toolkit/tools/pkg/imagecustomizerlib/partitionutils.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func readFstabEntriesFromRootfs(rootfsPartition *diskutils.PartitionInfo, diskPa
199199
}
200200

201201
func fstabEntriesToMountPoints(fstabEntries []diskutils.FstabEntry, diskPartitions []diskutils.PartitionInfo,
202-
buildDir string, readonly bool, readOnlyVerity bool,
202+
buildDir string, readonly bool, readOnlyVerity bool, ignoreOverlays bool,
203203
) ([]*safechroot.MountPoint, map[string]diskutils.FstabEntry, []verityDeviceMetadata, []string, error) {
204204
filteredFstabEntries := filterOutSpecialPartitions(fstabEntries)
205205

@@ -210,6 +210,9 @@ func fstabEntriesToMountPoints(fstabEntries []diskutils.FstabEntry, diskPartitio
210210
verityMetadataList := []verityDeviceMetadata(nil)
211211
readonlyPartUuids := []string(nil)
212212
for _, fstabEntry := range filteredFstabEntries {
213+
if ignoreOverlays && strings.ToLower(fstabEntry.FsType) == "overlay" {
214+
continue // Skip overlay entries when requested
215+
}
213216
_, partition, _, verityMetadata, err := findSourcePartition(fstabEntry.Source, diskPartitions, buildDir)
214217
if err != nil {
215218
return nil, nil, nil, nil, err

0 commit comments

Comments
 (0)