@@ -21,41 +21,49 @@ import (
21
21
type installOSFunc func (imageChroot * safechroot.Chroot ) error
22
22
23
23
func connectToExistingImage (imageFilePath string , buildDir string , chrootDirName string , includeDefaultMounts bool ,
24
- ) (* ImageConnection , error ) {
24
+ ) (* ImageConnection , map [ string ] string , error ) {
25
25
imageConnection := NewImageConnection ()
26
26
27
- err := connectToExistingImageHelper (imageConnection , imageFilePath , buildDir , chrootDirName , includeDefaultMounts )
27
+ partUuidToMountPath , err := connectToExistingImageHelper (imageConnection , imageFilePath , buildDir , chrootDirName , includeDefaultMounts )
28
28
if err != nil {
29
29
imageConnection .Close ()
30
- return nil , err
30
+ return nil , nil , err
31
31
}
32
- return imageConnection , nil
32
+ return imageConnection , partUuidToMountPath , nil
33
33
}
34
34
35
35
func connectToExistingImageHelper (imageConnection * ImageConnection , imageFilePath string ,
36
36
buildDir string , chrootDirName string , includeDefaultMounts bool ,
37
- ) error {
37
+ ) ( map [ string ] string , error ) {
38
38
// Connect to image file using loopback device.
39
39
err := imageConnection .ConnectLoopback (imageFilePath )
40
40
if err != nil {
41
- return err
41
+ return nil , err
42
+ }
43
+
44
+ partitions , err := diskutils .GetDiskPartitions (imageConnection .Loopback ().DevicePath ())
45
+ if err != nil {
46
+ return nil , err
42
47
}
43
48
44
49
// Look for all the partitions on the image.
45
- mountPoints , err := findPartitions (buildDir , imageConnection . Loopback (). DevicePath () )
50
+ mountPoints , err := findPartitions (buildDir , partitions )
46
51
if err != nil {
47
- return fmt .Errorf ("failed to find disk partitions:\n %w" , err )
52
+ return nil , fmt .Errorf ("failed to find disk partitions:\n %w" , err )
48
53
}
49
54
55
+ // Create mapping from partition UUID to mount path
56
+ partUuidToMountPath := createPartUuidToMountPathMap (partitions , mountPoints )
57
+
50
58
// Create chroot environment.
51
59
imageChrootDir := filepath .Join (buildDir , chrootDirName )
52
60
53
61
err = imageConnection .ConnectChroot (imageChrootDir , false , []string (nil ), mountPoints , includeDefaultMounts )
54
62
if err != nil {
55
- return err
63
+ return nil , err
56
64
}
57
65
58
- return nil
66
+ return partUuidToMountPath , nil
59
67
}
60
68
61
69
func createNewImage (targetOs targetos.TargetOs , filename string , diskConfig imagecustomizerapi.Disk ,
@@ -265,3 +273,17 @@ func createPartIdToPartUuidMap(partIDToDevPathMap map[string]string, diskPartiti
265
273
266
274
return partIdToPartUuid , nil
267
275
}
276
+
277
+ func createPartUuidToMountPathMap (partitions []diskutils.PartitionInfo , mountPoints []* safechroot.MountPoint ,
278
+ ) map [string ]string {
279
+ partUuidToMountPath := make (map [string ]string )
280
+ for _ , mountPoint := range mountPoints {
281
+ for _ , partition := range partitions {
282
+ if partition .Path == mountPoint .GetSource () {
283
+ partUuidToMountPath [partition .PartUuid ] = mountPoint .GetTarget ()
284
+ break
285
+ }
286
+ }
287
+ }
288
+ return partUuidToMountPath
289
+ }
0 commit comments