unlawfulbooger,

You can also do the following to prevent unwanted writes when something is not mounted at /mnt/thatdrive:


<span style="font-style:italic;color:#969896;"># make sure it is not mounted, fails if not mounted which is fine
</span><span style="color:#323232;">umount /mnt/thatdrive
</span><span style="color:#323232;">
</span><span style="font-style:italic;color:#969896;"># make sure the mountpoint exists
</span><span style="color:#323232;">mkdir -p /mnt/thatdrive
</span><span style="color:#323232;">
</span><span style="font-style:italic;color:#969896;"># make the directory immutable, which disallows writing to it (i.e. creating files inside it)
</span><span style="color:#323232;">chattr +i /mnt/thatdrive
</span><span style="color:#323232;">
</span><span style="font-style:italic;color:#969896;"># test write to unmounted dir (should fail)
</span><span style="color:#323232;">touch /mnt/thatdrive/myfile
</span><span style="color:#323232;">
</span><span style="font-style:italic;color:#969896;"># remount the drive (assumes it’s already listed in fstab)
</span><span style="color:#323232;">mount /mnt/thatdrive
</span><span style="color:#323232;">
</span><span style="font-style:italic;color:#969896;"># test write to mounted dir (should succeed)
</span><span style="color:#323232;">touch /mnt/thatdrive/myfile
</span><span style="color:#323232;">
</span><span style="font-style:italic;color:#969896;"># cleanup
</span><span style="color:#323232;">rm /mnt/thatdrive/myfile
</span>

From man 1 chattr:

A file with the ‘i’ attribute cannot be modified: it cannot be deleted or renamed, no link can be created to this file, most of the file’s metadata can not be modified, and the file can not be opened in write mode.
Only the superuser or a process possessing the CAP_LINUX_IMMUTABLE capability can set or clear this attribute.

I do this to prevent exactly the situation you’ve encountered. Hope this helps!

  • All
  • Subscribed
  • Moderated
  • Favorites
  • linux@lemmy.ml
  • fightinggames
  • All magazines