0

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?
Chris Davies
  • 116,213
  • 16
  • 160
  • 287
  • Use sync before trying to umount and also make sure there are no more read/write operations onto target device. – paladin Sep 04 '23 at 08:25
  • @paladin As of this post syncing is not necessary. – participant Sep 04 '23 at 09:17
  • What do you intend to do once you've unmounted /dir1? If the answer is "nothing" then you could use umount -l /dir1 quite 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 use unmount -l anyway and wait for the unmount to action – Chris Davies Sep 04 '23 at 12:07
  • @roaima Actually, I want to close a vpn-tunnel after the umount. So I guess, umount -l ... is not an option. – participant Sep 04 '23 at 12:09
  • lsof -f | grep ' [/]dir1' would go some way towards finding the processes still using /dir1 in some way (including the /dir1/dir2 mount) – Chris Davies Sep 04 '23 at 13:04
  • @roaima For testing, I repeatedly run the script mount; bindfs followed by fusermount; umount. 4 out of 5 tries it works fine and in one case there is this "Target is Busy". Shouldn't fusermount -u be finished before umount is started? – participant Sep 04 '23 at 13:25
  • I don't know for certain. However, if you run the lsof | grep you 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 the fusermount has supposedly finished, for example. – Chris Davies Sep 04 '23 at 13:29
  • Read man fuser lsof. Use sudo lsof +D /dir1. – waltinator Sep 04 '23 at 16:16
  • @roaima, @waltinator Strange enough, right now I'm unable to reproduce the behavior neither with nor without the lsof added to the script. – participant Sep 04 '23 at 21:04
  • 1
    To me that sounds like you simply need a "short pause" between the fusermount and the umount to 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 as sleep 2, mind.) – Chris Davies Sep 04 '23 at 21:18

0 Answers0