2

I have a file server set up to share an external drive over samba and netatalk (AFP). I have an fstab entry to automatically mount the drive at /mnt/external, which then gets shared automatically by the various daemons.

The problem is if the drive doesn't mount properly (e.g. if I forgot to turn it on, or if I took it to work that day). In this case the mountpoint gets shared without the corresponding drive attached, resulting in various meta files getting written to my mount point rather than a clean failure. This prevents the drive from mounting properly the next time I attach it (non-empty directory), and could lead to data loss if someone used the share in the mean time.

Is there any way to cause the shares to fail in the case that the drive is unmounted?

3
  • 1
    I would mount the disk in a script called by /etc/rc.local (and by hand afterward) so that I can create the directory on mount and remove it on umount. That should lead to a clean failure of the sharing daemons...
    – Rmano
    Mar 11, 2015 at 9:02
  • Quantum7: If the above comment doesn't mean anything to you, leave a comment below... @RMano: you want to do the honours if OP replies?
    – Fabby
    Mar 14, 2015 at 18:23
  • Thats a good idea, Rmano. If you flesh it out into an answer I'll accept it.
    – Quantum7
    Mar 17, 2015 at 19:34

1 Answer 1

1

You can set your original mount folder attributes to make it immutable:

chattr +i /mnt/external

The folder is now locked and any operation on it is forbidden (you can unlock it using -i). However mount or fstab still work properly.


Make sure the drive is not mounted before running chattr. If you get the error "Inappropriate ioctl for device While reading flags", maybe your are working on a filesystem that doesn't support attributes on folders. In fact some Linux distributions mount the main partition using overlayfs filesystem instead of ext. So you have to mount it manually elsewhere in order to get chattr working on folders (i.e. mount /dev/mmcblk0p3 /mnt/temp then chattr +i /mnt/temp/root/mnt/external).

2
  • 1
    An answer after 6 years! There should be a badge for that! This would have been better than what I ended up going with, which was to add a single top-level directory inside the mount (e.g. /mnt/external/work/). As long as I used that path consistently I would get errors writing files rather than silent file creations.
    – Quantum7
    Jan 27, 2021 at 20:59
  • 1
    @Quantum7 Thanks! ;) Well only the few people trying to make a time machine themselves get to your question I guess. Your solution was great as well, hadn't thought about it.
    – Motla
    Jan 28, 2021 at 7:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .