I've a script
pre-condition: lsof /dir1 clear
#/bin/bash
...
fusermount -u /dir1/dir2 # unbind dir2
umount /dir1 # sporadically fails with 'Target is Busy'
...
- Why do I get sporadically a 'Target is Busy' error?
- Given I need to know the filesystem has unmounted before closing a VPN connection, what can I reasonably do about it?
syncbefore trying to umount and also make sure there are no more read/write operations onto target device. – paladin Sep 04 '23 at 08:25syncing is not necessary. – participant Sep 04 '23 at 09:17/dir1? If the answer is "nothing" then you could useumount -l /dir1quite safely. If you want to wait until the filesystem is unused because it's on a removable device (for example), you probably want a busy loop to wait for all open file descriptors on the filesystem to go away. Or useunmount -lanyway and wait for the unmount to action – Chris Davies Sep 04 '23 at 12:07umount. So I guess,umount -l ...is not an option. – participant Sep 04 '23 at 12:09lsof -f | grep ' [/]dir1'would go some way towards finding the processes still using/dir1in some way (including the/dir1/dir2mount) – Chris Davies Sep 04 '23 at 13:04mount; bindfsfollowed byfusermount; umount. 4 out of 5 tries it works fine and in one case there is this "Target is Busy". Shouldn'tfusermount -ube finished beforeumountis started? – participant Sep 04 '23 at 13:25lsof | grepyou should see what's holding the mount open. Armed with that information you (or we) can look at creating a solution to resolve the issue. It might simply be that you need to pause a little longer after thefusermounthas supposedly finished, for example. – Chris Davies Sep 04 '23 at 13:29man fuser lsof. Usesudo lsof +D /dir1. – waltinator Sep 04 '23 at 16:16lsofadded to the script. – participant Sep 04 '23 at 21:04fusermountand theumountto allow things to settle down. (I'd prefer a quantitative answer such as "wait until all relevant processes have ended" to a qualitative one such assleep 2, mind.) – Chris Davies Sep 04 '23 at 21:18