2

I've a mounted iso image in the path:

/mnt/iso

Inside this iso I've an install script install.sh I run the installation script from the iso and at the end the script ask to the user if he want to umount the iso itself. If the user press "y" the script execute the following code:

cd /
umount /mnt/iso
echo "Installation completed!"

Unfortunately when the script tries to execute the umount there's an error

umount: /mnt/iso: device is busy

I suppose it's due to the fact that the virtual device is busy from the script itself. How can make it work? Tnx

user2572526
  • 1,093
  • 2
  • 16
  • 34
  • Do you run install.sh from inside `/mnt/iso`? What if you try running it from outside? My hypothesis is that the the problem is not the install script (because it does `cd /`) but is that the calling shell is inside `/mnt/iso`. – rand Nov 15 '13 at 12:00
  • There must be some files being used. Check it with `lsof`. – fedorqui 'SO stop harming' Nov 15 '13 at 12:07

2 Answers2

3

Use the -l or --lazy switch to umount which will do a lazy umount, where it is only fully unmounted once it is no longer in use. The full description in the manual page (this is a linux specific option) is:

Lazy unmount. Detach the filesystem from the filesystem hierarchy now, and cleanup all references to the filesystem as soon as it is not busy anymore. (Requires kernel 2.4.11 or later.)

TomH
  • 8,112
  • 1
  • 28
  • 28
  • 1
    Hi, there's a problem that I noticed only now. When I use the lazy umount the iso is correctly unmounted but if I try to execute losetup -a I see that the loop devices remain. /dev/loop0: [0801]:773311 (/myIso.iso) /dev/loop1: [0801]:773311 (/myIso.iso) /dev/loop2: [0801]:773311 (/myIso.iso) /dev/loop3: [0801]:769575 (/myIso.iso) How can I avoid this behavior? – user2572526 Dec 09 '13 at 11:33
0

TomH's solution will resolve the issue if you are using the latest. Otherwise the comment by Simone Palazzo is your best bet. You are unmounting something through a script located in the area you are unmounting. If you run the script from the root directory it will be successful.

KSdev
  • 611
  • 3
  • 11