I'm writing a makefile that at some point builds image files. I'm using
losetup -f in the file to find a free loop device when building out each image. Since the images are independent of each other, I'd like to be able to
make -j in parallel. Unfortunately, when I do this,
losetup -f returns the same device to all images since the command is executed at nearly the same time for each image. Does anyone know of a way I can get around this?
I run into the same problem as you and found the following bug report in the chromium bug tracker that also describes how to fix it: https://code.google.com/p/chromium/issues/detail?id=201150
Basically it's sufficient to not just print the next free device but also use it and just print the name so it can be deleted afterwards.
find the first unused loop device. If a file argument is present,
use this device. Otherwise, print its name
print device name if the -f option and a file argument are present.
This means that
losetup -f --show /foo/bar will print
/dev/loop1, for example, and also associates the loop the device with the file