Does "mount -o remount,ro" flush filesystem buffers?
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()
.