On Linux, does mount -o remount,ro
flush filesystem buffers/cache, or should I also run sync
to achieve that?
2 Answers
It should flush the cache, yes.
Arguably there is some fragility in this code path. It is not implemented in one place; it is implemented in each individual filesystem. E.g. ext2_remount() must call sync_filesystem().
Also in all the use cases that I know of, it is used together with the sync()
system call. So if you rely on this, and the kernel gets it wrong, you might have the "privilege" of being the first to notice a problem.
If you want to be extra-careful, you could use sync -f /my/mounted/filesystem/
. It is preferable to sync
because it avoids interference with any other filesystem. It uses the Linux system call syncfs()
.

- 50,249
From Wikipedia
Buffers are also flushed when filesystems are unmounted or remounted read-only, for example prior to system shutdown.

- 3,068
-
2
-
This quote is currently marked [citation needed]. The quote is also wrong, because it is not true for some non-Linux systems. "According to the standard specification (e.g., POSIX.1-2001), sync() schedules the writes, but may return before the actual writing is done." http://man7.org/linux/man-pages/man2/sync.2.html This was a problem on historical UNIX: https://unix.stackexchange.com/a/416466/29483 – sourcejedi Mar 03 '19 at 17:55
remount
is combined with abind
. – Stéphane Chazelas Jul 24 '14 at 12:50