My OS is Slackware 13.1(2.6.33.4-smp).

I'm running losetup -d $dev in my custom script as the last line to free some loop device created in it. However, it not always works saying that the device is busy though nothing in my script works with it anymore. This script is being invoked many times one right after another. Sometimes the device is freed, sometimes not. But if I put a "sleep 2" before losetup -d $dev then no problem ever occurs. It seems that "losetup" needs some time or smth... (can't show you the output of losetup -a now, not at work right now)

Is there a way to force deletion of some loop device? Do you have any ideas?

link|improve this question
feedback

1 Answer

It's possible that access to the device is asynchronous, so data of your mount/dd/whatever-you-did-to-the-loop-device still resides in the cache and is about to be flushed. In that case, sync should help (but might slow down the entire system to a crawl if other IO-heavy operations are going on).

Depending on your use case and environment, a simple while loop (while ! losetup -d $dev; do sleep 2; done) might be preferrable (though you should add an exit condition after a couple of attempts).

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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