On embedded Linux distribution with ext4, I have the following umountfs script:
#!/bin/sh
### BEGIN INIT INFO
# Provides: umountfs
# Required-Start:
# Required-Stop:
# Default-Start:
# Default-Stop: 0 6
# Short-Description: Turn off swap and unmount all local file systems.
# Description:
### END INIT INFO
PATH=/sbin:/bin:/usr/sbin:/usr/bin
echo "Deactivating swap..."
[ -x /sbin/swapoff ] && swapoff -a
# We leave /proc mounted.
echo "Unmounting local filesystems..."
grep -q /mnt/ram /proc/mounts && mount -o remount,ro /mnt/ram
mount -o remount,ro /
umount -f -a -r > /dev/null 2>&1
: exit 0
I have a question about the following lines:
mount -o remount,ro /
umount -f -a -r > /dev/null 2>&1
The question is: why we need to remount rootfs to read-only before umount?
I saw some explanation, as though we need to remount the rootfs to ro
in order to force all pending write requests to be flashed on the disk. But this does not satisfy me, because the flashing of the pending write requests is the part of umount command.
So the question: does somebody understand, why we need to remount rootfs to ro
before unmounting it?