diff --git a/internal/statemachine/state_machine.go b/internal/statemachine/state_machine.go index 9d7a5286..e3cf8903 100644 --- a/internal/statemachine/state_machine.go +++ b/internal/statemachine/state_machine.go @@ -124,6 +124,9 @@ type StateMachine struct { // names of images for each volume VolumeNames map[string]string + // name of the "main volume" + MainVolumeName string + Packages []string Snaps []string } @@ -395,10 +398,14 @@ func fixMissingContent(volume *gadget.Volume, structure *gadget.VolumeStructure, // Since so far we have no knowledge of the rootfs contents, the // size is set to 0, and will be calculated later func (stateMachine *StateMachine) fixMissingSystemData(lastVolumeName string, farthestOffset quantity.Offset, farthestOffsetUnknown bool, rootfsSeen bool) { - // For now we consider the main volume to be the last one + // For now we consider the main volume to be the last one unless it was previously found volume := stateMachine.GadgetInfo.Volumes[lastVolumeName] - if !farthestOffsetUnknown || !rootfsSeen || len(stateMachine.GadgetInfo.Volumes) == 1 { + if len(stateMachine.MainVolumeName) != 0 { + volume = stateMachine.GadgetInfo.Volumes[stateMachine.MainVolumeName] + } + + if !farthestOffsetUnknown || !rootfsSeen || len(stateMachine.GadgetInfo.Volumes) != 1 { return } rootfsStructure := gadget.VolumeStructure{ @@ -470,6 +477,7 @@ func (stateMachine *StateMachine) loadState(partialStateMachine *StateMachine) e stateMachine.ImageSizes = partialStateMachine.ImageSizes stateMachine.VolumeOrder = partialStateMachine.VolumeOrder stateMachine.VolumeNames = partialStateMachine.VolumeNames + stateMachine.MainVolumeName = partialStateMachine.MainVolumeName stateMachine.Packages = partialStateMachine.Packages stateMachine.Snaps = partialStateMachine.Snaps diff --git a/internal/statemachine/testdata/metadata/reference_successful_write.json b/internal/statemachine/testdata/metadata/reference_successful_write.json index 3801cd2f..6d026035 100644 --- a/internal/statemachine/testdata/metadata/reference_successful_write.json +++ b/internal/statemachine/testdata/metadata/reference_successful_write.json @@ -1 +1 @@ -{"CurrentStep":"","StepsTaken":2,"ConfDefPath":"","YamlFilePath":"/tmp/ubuntu-image-2329554237/unpack/gadget/meta/gadget.yaml","IsSeeded":true,"RootfsVolName":"","RootfsPartNum":0,"SectorSize":512,"RootfsSize":775915520,"GadgetInfo":{"Volumes":{"pc":{"schema":"gpt","bootloader":"grub","id":"","structure":[{"name":"mbr","filesystem-label":"","offset":0,"offset-write":null,"min-size":440,"size":440,"type":"mbr","role":"mbr","id":"","filesystem":"","content":[{"source":"","target":"","image":"pc-boot.img","offset":null,"size":0,"unpack":false}],"update":{"edition":1,"preserve":null}}]}},"Defaults":null,"Connections":null,"KernelCmdline":{"Allow":null,"Append":null,"Remove":null}},"ImageSizes":{"pc":3155165184},"VolumeOrder":["pc"],"VolumeNames":{"pc":"pc.img"},"Packages":null,"Snaps":null} \ No newline at end of file +{"CurrentStep":"","StepsTaken":2,"ConfDefPath":"","YamlFilePath":"/tmp/ubuntu-image-2329554237/unpack/gadget/meta/gadget.yaml","IsSeeded":true,"RootfsVolName":"","RootfsPartNum":0,"SectorSize":512,"RootfsSize":775915520,"GadgetInfo":{"Volumes":{"pc":{"schema":"gpt","bootloader":"grub","id":"","structure":[{"name":"mbr","filesystem-label":"","offset":0,"offset-write":null,"min-size":440,"size":440,"type":"mbr","role":"mbr","id":"","filesystem":"","content":[{"source":"","target":"","image":"pc-boot.img","offset":null,"size":0,"unpack":false}],"update":{"edition":1,"preserve":null}}]}},"Defaults":null,"Connections":null,"KernelCmdline":{"Allow":null,"Append":null,"Remove":null}},"ImageSizes":{"pc":3155165184},"VolumeOrder":["pc"],"VolumeNames":{"pc":"pc.img"},"MainVolumeName":"","Packages":null,"Snaps":null} \ No newline at end of file