Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer 1

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.

From losetup(8):

-f, --find
    find the first  unused  loop  device.  If  a  file  argument  is present,
    use this device. Otherwise, print its name

--show
    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 /foo/bar.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.