I though I'll share a problem which I ran into while using the LinuxBootImageFileGenerator.py. The workaround I implemented is attached in the code below.
In function __createLoopbackDevice the error "losetup failed to set up loop device: Resource temporarily unavailable" gets thrown, resulting in Exception("Failed to get a loopback device")
I changed the __createLoopbackDevice to retry if it's fails to create dev loop, as the attached code below displays.
def __createLoopbackDevice(self, diagnosticOutput = True,size =0, offset_bytes = 0):
self.__print(diagnosticOutput,'--> Create loopback device')
# Calculate offset from sectors to byte
retries = 0
success = False
while (not success):
try:
if offset_bytes != 0:
loop_dev = self.__runCmdInShell(diagnosticOutput,
["sudo","losetup", "--show", "-f", "-o "+str(offset_bytes),
"--sizelimit",str(size), self.__imageFilepath])
success = True
else:
os.system('sudo losetup --show -f --sizelimit '+str(size)+' '+\
self.__imageFilepath)
loop_dev = self.__runCmdInShell(diagnosticOutput,
["sudo","losetup","--show", "-f",
"--sizelimit", str(size), self.__imageFilepath])
success = True
except subprocess.CalledProcessError:
retries += 1
time.sleep(0.001)
if retries > 1000:
self.__unmountDeleteLoopbacks(diagnosticOutput)
raise Exception("Failed to get a loopback device")
# convert the loop device name as string
loop_dev_str = str(loop_dev)
Running on Ubuntu 18.04.5 LTS.