0

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?

user3518295
  • 77
  • 2
  • 9

1 Answers1

0

Typically you can't unmount the root filesystem, because at least one currently-running process that is using the filesystem - init or systemd. Remounting the root filesystem read-only flushes all dirty data and prevents it from being modified again, so that the filesystem is consistent. Typically at that point the kernel reboots without having actually unmounted the root filesystem.

LustreOne
  • 309
  • 2
  • 8