2

I created a folder using sudo mkdir /mnt/external/ and then mount an external hdd to it:

$ mount -t ext2 /dev/sdd1 /mnt/external

I have an application writing backups to that mounted drive. Then, for fail test I simply unplug the external drive but the the application still keeps writing backups to that folder.

This is a problem because /mnt/external/ folder now becomes a regular folder on the regular hard drive and the application fills up the actual hard drive which is running the OS.

How can I make sure that the application only writes to the mount point if the drive is currently mounted there?

3

With the drive unmounted,

$ sudo chmod a-rwx /mnt/external

A directory doesn't need to be readable or writable to have a filesystem mounted there. When the filesystem is mounted, the permissions of /mnt/external come from the root directory of that filesystem. When no filesystem is mounted there, they come from the filesystem containing /mnt (probably the system's root filesystem).

  • I have just tested that and confirmed that it works as you suggested. Setting the permissions a-rwx on that folder stopped the backups being written there. Thank you. – fcukinyahoo Jan 16 '14 at 21:19
  • To clarify, you should remove any existing files from /mnt/external before the chmod. Otherwise, they'll still be there, inaccessible but taking up space. – cjm Jan 16 '14 at 21:56
  • yeap i certainly did that. – fcukinyahoo Jan 17 '14 at 4:57

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.