diff --git a/actions/image_partition_action.go b/actions/image_partition_action.go index bee910e..0054c34 100644 --- a/actions/image_partition_action.go +++ b/actions/image_partition_action.go @@ -459,9 +459,19 @@ func (i *ImagePartitionAction) PreNoMachine(context *debos.DebosContext) error { img.Close() - i.loopDev, err = losetup.Attach(imagePath, 0, false) + // losetup.Attach() can fail due to concurrent attaches in other processes + retries := 60 + for t := 1; t <= retries; t++ { + i.loopDev, err = losetup.Attach(imagePath, 0, false) + if err == nil { + break + } + log.Printf("Setup loop device: try %d/%d failed: %v", t, retries, err) + time.Sleep(200 * time.Millisecond) + } + if err != nil { - return fmt.Errorf("Failed to setup loop device") + return fmt.Errorf("Failed to setup loop device: %v", err) } context.Image = i.loopDev.Path() i.usingLoop = true