As a side note, we seem to miss call to "dmsetup remove /dev/mapper/loopXpY" in order to get a clean status at the end.
If we don't do that, we keep dangling "partitions" in /dev/mapper, and the /dev/loopX is still binded to the /image0.raw - this may explain some of the issues. Note that this apparently happens only upon a build failure.
As a side note, we seem to miss call to "dmsetup remove /dev/mapper/ loopXpY" in order to get a clean status at the end.
If we don't do that, we keep dangling "partitions" in /dev/mapper, and the /dev/loopX is still binded to the /image0.raw - this may explain some of the issues. Note that this apparently happens only upon a build failure.