findmnt --raw --noheadings --output options --target SOME_DIRECTORY | grep -qE '(^|,)ro($|,)'
findmnt
is a handy alternative tomount
when 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 ro
would also match options likeerrors=remount-ro
, so we make sure to only match the singlero
option. It must be delimited by commas or the start/end of the option string.