Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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:

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

    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

Your Answer


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.