The book How Linux Works says the general shutdown procedure (independent of init system) is something like this:init asks every process to shut down cleanly.If a process doesnt respond after a while, init kills it, first trying a TERM signal.If the TERM signal doesnt work, init uses the KILL signal on any stragglers.The system locks system files into place and makes other preparations for shutdown.The system unmounts all filesystems other than the root.The system remounts the root filesystem read-only.The system writes all buffered data out to the filesystem with the sync program.The final step is to tell the kernel to reboot or stop with the reboot(2) system call. This can be done by init or an auxiliary program such as reboot, halt, or poweroff.How can sync write its buffers if the filesystem is read-only?
Shutdown procedure clarification
systemd;shutdown;init;sysvinit
You're right to be surprised: that order doesn't make sense. If a book presents it that way, it's sloppy and misleading.Unmounting a filesystem, or mounting it read-only, writes all the data to the disk. When the umount command or mount -o remount,ro returns, all the data is written to the disk and sync has nothing left to do. It's pointless to call sync before (the data will be written by the umount operation anyway) and pointless to call it after (it won't do anything).I think this wasn't true in some ancient Unix systems, where you had to call sync before unmounting. Calling it after was still pointless.If you look beyond filesystems, there may be cases where sync does something. For example, I think that on Linux sync ensures that the metadata of RAID arrays are written to the disk. This is useful even in the absence of any filesystem mounted read-write.