On Linux, does mount -o remount,ro flush filesystem buffers/cache, or should I also run sync to achieve that?

  • 2
    Yes, unless the remount is combined with a bind. – Stéphane Chazelas Jul 24 '14 at 12:50

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().

| improve this answer | |

From Wikipedia

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

| improve this answer | |
  • 1
    Thank you, but can you quote a better source than Wikipedia? – Totor Sep 3 '14 at 15:23
  • 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." man7.org/linux/man-pages/man2/sync.2.html This was a problem on historical UNIX: unix.stackexchange.com/a/416466/29483 – sourcejedi Mar 3 '19 at 17:55

Your Answer

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.