findmnt --raw --noheadings --output options --target SOME_DIRECTORY | grep -qE '(^|,)ro($|,)'
findmntis a handy alternative to
mountwhen writing scripts
- SOME_DIRECTORY does not have to correspond to a mountpoint. If it doesn't, findmnt will traverse its parent directories until it finds the corresponding filesystem / mountpoint.
- a simple
grep rowould also match options like
errors=remount-ro, so we make sure to only match the single
rooption. It must be delimited by commas or the start/end of the option string.