1

I have raspberry pi and have microsd with raspbian from which the system is loading and the HDD on which I write logs. I encountered such a problem that sometimes the disk falls off and the logs begin to be written to the microsd in the same directory where the HDD was mounted. How can I prohibit writing logs to a USB flash drive, and write only when the drive is mounted? I write logs very often and there is no possibility to check whether a disk is mounted at each iteration.

New contributor
JaneKapovsky is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
0

If the logging isn't performed by root, it would be sufficient to make the mount point read only, for that use chmod -R 0444 /mountpoint. However, root would still be able to write into that directory, so in that case you might need to use chattr -i /mountpoint, which would make it completely unwritable.

These attributes won't carry over after mounting, since the permissions are inherited from the parameters set in the fstab.

Keep in mind that by restricting writing into the mount point directory when nothing's mounted there would present a different problem: how would your logging tools handle denied write permissions?

Your Answer

JaneKapovsky is a new contributor. Be nice, and check out our Code of Conduct.

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.