I have a FUSE mount located in /media/writable, however, sometimes this FUSE mount disconnects, but some programs will still attempt to write to /media/writable.

When I restart the FUSE mount service, it will fail to mount because the directory is non-empty.

How can I use rm's --one-file-system argument to ensure that when I rm /media/writable, it will only delete files located on the local filesystem, as opposed to the fuse mounted filesystem? There are other folders located in /media/ so I am unable to run rm in the parent folder.

Am I better off moving the folder one layer down (eg. /media/writable/mount) so I can rm the parent folder, or is there a way of selecting which filesystem I wish to delete from?

I'm running Ubuntu 18.04.1 LTS with coreutils 8.28.

Edit: My current method is this, but I'd like to see if there's a better way to do it: ExecStartPre=-/bin/mountpoint /media/writable/ || /usr/bin/stat /media/writable/MOUNTED || /bin/rm/ --one-file-system -rf /media/writable/*

  • 3
    I'd check out steeldriver's mountpoint answer – Jeff Schaller Mar 9 at 13:39
  • @JeffSchaller Ooh, that's an interesting one. I'll take a look, thanks! – Connor Bell Mar 9 at 13:40
  • ExecStartPre= should not work like that? I think you need to wrap your shell command like /bin/sh -c " command1 || command2 || command3 " – sourcejedi Mar 9 at 18:50
  • @sourcejedi Ah, I didn't realise that wouldn't work, I was just testing with it. I guess I was wrong saying that it was my current method, but it was the one I'd worked out that I thought would work. Thanks for the heads up! – Connor Bell Mar 9 at 18:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.