Skip to content

Commit caa9f81

Browse files
committed
updates
1 parent 676aad9 commit caa9f81

7 files changed

+98
-69
lines changed

toolkit/tools/pkg/imagecustomizerlib/cosicommon.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ func convertToCosi(ic *ImageCustomizerParameters) error {
3636
}
3737
defer imageLoopback.Close()
3838

39-
partitionMetadataOutput, err := extractPartitions(imageLoopback.DevicePath(), outputDir, ic.outputImageBase, "raw-zst", ic.imageUuid)
39+
partitionMetadataOutput, err := extractPartitions(imageLoopback.DevicePath(), outputDir, ic.outputImageBase,
40+
"raw-zst", ic.imageUuid)
4041
if err != nil {
4142
return err
4243
}
4344

44-
err = buildCosiFile(outputDir, ic.outputImageFile, partitionMetadataOutput, ic.verityMetadata, ic.imageUuidStr)
45+
err = buildCosiFile(outputDir, ic.outputImageFile, partitionMetadataOutput, ic.verityMetadata, ic.partUuidToMountPath,
46+
ic.imageUuidStr)
4547
if err != nil {
4648
return fmt.Errorf("failed to build COSI file:\n%w", err)
4749
}
@@ -56,8 +58,8 @@ func convertToCosi(ic *ImageCustomizerParameters) error {
5658
return nil
5759
}
5860

59-
func buildCosiFile(sourceDir string, outputFile string, partitions []outputPartitionMetadata, verityMetadata []verityDeviceMetadata, imageUuidStr string) error {
60-
61+
func buildCosiFile(sourceDir string, outputFile string, partitions []outputPartitionMetadata, verityMetadata []verityDeviceMetadata,
62+
partUuidToMountPath map[string]string, imageUuidStr string) error {
6163
// Pre-compute a map for quick lookup of partition metadata by UUID
6264
partUuidToMetadata := make(map[string]outputPartitionMetadata)
6365
for _, partition := range partitions {

toolkit/tools/pkg/imagecustomizerlib/customizepartitions.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
func customizePartitions(buildDir string, baseConfigPath string, config *imagecustomizerapi.Config,
1414
buildImageFile string,
15-
) (bool, string, map[string]string, error) {
15+
) (bool, string, map[string]string, map[string]string, error) {
1616
switch {
1717
case config.CustomizePartitions():
1818
logger.Log.Infof("Customizing partitions")
@@ -21,25 +21,25 @@ func customizePartitions(buildDir string, baseConfigPath string, config *imagecu
2121

2222
// If there is no known way to create the new partition layout from the old one,
2323
// then fallback to creating the new partitions from scratch and doing a file copy.
24-
partIdToPartUuid, err := customizePartitionsUsingFileCopy(buildDir, baseConfigPath, config,
24+
partIdToPartUuid, partUuidToMountPath, err := customizePartitionsUsingFileCopy(buildDir, baseConfigPath, config,
2525
buildImageFile, newBuildImageFile)
2626
if err != nil {
27-
return false, "", nil, err
27+
return false, "", nil, nil, err
2828
}
2929

30-
return true, newBuildImageFile, partIdToPartUuid, nil
30+
return true, newBuildImageFile, partIdToPartUuid, partUuidToMountPath, nil
3131

3232
case config.Storage.ResetPartitionsUuidsType != imagecustomizerapi.ResetPartitionsUuidsTypeDefault:
3333
err := resetPartitionsUuids(buildImageFile, buildDir)
3434
if err != nil {
35-
return false, "", nil, err
35+
return false, "", nil, nil, err
3636
}
3737

38-
return true, buildImageFile, nil, nil
38+
return true, buildImageFile, nil, nil, nil
3939

4040
default:
4141
// No changes to make to the partitions.
4242
// So, just use the original disk.
43-
return false, buildImageFile, nil, nil
43+
return false, buildImageFile, nil, nil, nil
4444
}
4545
}

toolkit/tools/pkg/imagecustomizerlib/customizepartitionsfilecopy.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ import (
1515

1616
func customizePartitionsUsingFileCopy(buildDir string, baseConfigPath string, config *imagecustomizerapi.Config,
1717
buildImageFile string, newBuildImageFile string,
18-
) (map[string]string, error) {
19-
existingImageConnection, err := connectToExistingImage(buildImageFile, buildDir, "imageroot", false)
18+
) (map[string]string, map[string]string, error) {
19+
existingImageConnection, _, err := connectToExistingImage(buildImageFile, buildDir, "imageroot", false)
2020
if err != nil {
21-
return nil, err
21+
return nil, nil, err
2222
}
2323
defer existingImageConnection.Close()
2424

2525
targetOs, err := targetos.GetInstalledTargetOs(existingImageConnection.Chroot().RootDir())
2626
if err != nil {
27-
return nil, fmt.Errorf("failed to determine target OS of base image:\n%w", err)
27+
return nil, nil, fmt.Errorf("failed to determine target OS of base image:\n%w", err)
2828
}
2929

3030
diskConfig := config.Storage.Disks[0]
@@ -33,18 +33,18 @@ func customizePartitionsUsingFileCopy(buildDir string, baseConfigPath string, co
3333
return copyFilesIntoNewDisk(existingImageConnection.Chroot(), imageChroot)
3434
}
3535

36-
partIdToPartUuid, err := createNewImage(targetOs, newBuildImageFile, diskConfig, config.Storage.FileSystems,
36+
partIdToPartUuid, partUuidToMountPath, err := createNewImage(targetOs, newBuildImageFile, diskConfig, config.Storage.FileSystems,
3737
buildDir, "newimageroot", installOSFunc)
3838
if err != nil {
39-
return nil, err
39+
return nil, nil, err
4040
}
4141

4242
err = existingImageConnection.CleanClose()
4343
if err != nil {
44-
return nil, err
44+
return nil, nil, err
4545
}
4646

47-
return partIdToPartUuid, nil
47+
return partIdToPartUuid, partUuidToMountPath, nil
4848
}
4949

5050
func copyFilesIntoNewDisk(existingImageChroot *safechroot.Chroot, newImageChroot *safechroot.Chroot) error {

toolkit/tools/pkg/imagecustomizerlib/imagecustomizer.go

+13-8
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ type ImageCustomizerParameters struct {
8484
imageUuidStr string
8585

8686
verityMetadata []verityDeviceMetadata
87+
88+
partUuidToMountPath map[string]string
8789
}
8890

8991
type verityDeviceMetadata struct {
@@ -380,20 +382,23 @@ func customizeOSContents(ic *ImageCustomizerParameters) error {
380382
}
381383

382384
// Customize the partitions.
383-
partitionsCustomized, newRawImageFile, partIdToPartUuid, err := customizePartitions(ic.buildDirAbs,
385+
partitionsCustomized, newRawImageFile, partIdToPartUuid, partUuidToMountPath, err := customizePartitions(ic.buildDirAbs,
384386
ic.configPath, ic.config, ic.rawImageFile)
385387
if err != nil {
386388
return err
387389
}
388390
ic.rawImageFile = newRawImageFile
391+
ic.partUuidToMountPath = partUuidToMountPath
389392

390393
// Customize the raw image file.
391-
err = customizeImageHelper(ic.buildDirAbs, ic.configPath, ic.config, ic.rawImageFile, ic.rpmsSources,
394+
partUuidToMountPath, err = customizeImageHelper(ic.buildDirAbs, ic.configPath, ic.config, ic.rawImageFile, ic.rpmsSources,
392395
ic.useBaseImageRpmRepos, partitionsCustomized, ic.imageUuidStr)
393396
if err != nil {
394397
return err
395398
}
396399

400+
ic.partUuidToMountPath = partUuidToMountPath
401+
397402
// Shrink the filesystems.
398403
if ic.enableShrinkFilesystems {
399404
err = shrinkFilesystemsHelper(ic.rawImageFile, ic.config.Storage.Verity, partIdToPartUuid)
@@ -713,12 +718,12 @@ func validatePackageLists(baseConfigPath string, config *imagecustomizerapi.OS,
713718
func customizeImageHelper(buildDir string, baseConfigPath string, config *imagecustomizerapi.Config,
714719
rawImageFile string, rpmsSources []string, useBaseImageRpmRepos bool, partitionsCustomized bool,
715720
imageUuidStr string,
716-
) error {
721+
) (map[string]string, error) {
717722
logger.Log.Debugf("Customizing OS")
718723

719-
imageConnection, err := connectToExistingImage(rawImageFile, buildDir, "imageroot", true)
724+
imageConnection, partUuidToMountPath, err := connectToExistingImage(rawImageFile, buildDir, "imageroot", true)
720725
if err != nil {
721-
return err
726+
return nil, err
722727
}
723728
defer imageConnection.Close()
724729

@@ -738,15 +743,15 @@ func customizeImageHelper(buildDir string, baseConfigPath string, config *imagec
738743
warnOnLowFreeSpace(buildDir, imageConnection)
739744

740745
if err != nil {
741-
return err
746+
return nil, err
742747
}
743748

744749
err = imageConnection.CleanClose()
745750
if err != nil {
746-
return err
751+
return nil, err
747752
}
748753

749-
return nil
754+
return partUuidToMountPath, nil
750755
}
751756

752757
func extractPartitionsHelper(rawImageFile string, outputDir string, outputBasename string, outputSplitPartitionsFormat string, imageUuid [UuidSize]byte) error {

0 commit comments

Comments
 (0)