Linux umount a device from a script running in the device itself

流过昼夜 提交于 2019-12-21 21:55:02

问题


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


回答1:


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.)




回答2:


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.



来源:https://stackoverflow.com/questions/20000547/linux-umount-a-device-from-a-script-running-in-the-device-itself

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!