1#!/bin/sh 2# 3# SPDX-License-Identifier: GPL-2.0-only 4# 5 6### BEGIN INIT INFO 7# Provides: checkroot 8# Required-Start: udev 9# Required-Stop: 10# Default-Start: S 11# Default-Stop: 12# Short-Description: Check to root file system. 13### END INIT INFO 14 15. /etc/default/rcS 16 17# 18# Set SULOGIN in /etc/default/rcS to yes if you want a sulogin to be spawned 19# from this script *before anything else* with a timeout, like SCO does. 20# 21test "$SULOGIN" = yes && sulogin -t 30 $CONSOLE 22 23# 24# Read /etc/fstab. 25# 26exec 9< /etc/fstab 27rootmode=rw 28rootopts=rw 29rootcheck=$ENABLE_ROOTFS_FSCK 30swap_on_md=no 31devfs= 32while read fs mnt type opts dump pass junk <&9 33do 34 case "$fs" in 35 ""|\#*) 36 continue; 37 ;; 38 /dev/md*) 39 # Swap on md device. 40 test "$type" = swap && swap_on_md=yes 41 ;; 42 /dev/*) 43 ;; 44 *) 45 # Might be a swapfile. 46 test "$type" = swap && swap_on_md=yes 47 ;; 48 esac 49 test "$type" = devfs && devfs="$fs" 50 test "$mnt" != / && continue 51 rootopts="$opts" 52 test "$pass" = 0 -o "$pass" = "" && rootcheck=no 53 case "$opts" in 54 ro|ro,*|*,ro|*,ro,*) 55 rootmode=ro 56 ;; 57 esac 58done 59exec 0>&9 9>&- 60 61# Check for conflicting configurations 62if [ "$rootmode" = "ro" -a "$ROOTFS_READ_ONLY" = "no" ] || \ 63 [ "$rootmode" = "rw" -a "$ROOTFS_READ_ONLY" = "yes" ]; then 64 echo "" 65 echo "WARN: conflicting configurations in /etc/fstab and /etc/default/rcS" 66 echo " regarding the writability of rootfs. Please fix one of them." 67 echo "" 68fi 69 70 71# 72# Activate the swap device(s) in /etc/fstab. This needs to be done 73# before fsck, since fsck can be quite memory-hungry. 74# 75test "$VERBOSE" != no && echo "Activating swap" 76[ -x /sbin/swapon ] && swapon -a 77 78# 79# Check the root filesystem. 80# 81if test -f /fastboot || test "$rootcheck" = "no" 82then 83 test $rootcheck = yes && echo "Fast boot, no filesystem check" 84else 85 # 86 # Ensure that root is quiescent and read-only before fsck'ing. 87 # 88 mount -n -o remount,ro / 89 if test $? = 0 90 then 91 if test -f /forcefsck 92 then 93 force="-f" 94 else 95 force="" 96 fi 97 if test "$FSCKFIX" = yes 98 then 99 fix="-y" 100 else 101 fix="-a" 102 fi 103 spinner="-C" 104 case "$TERM" in 105 dumb|network|unknown|"") spinner="" ;; 106 esac 107 test `uname -m` = s390 && spinner="" # This should go away 108 test "$VERBOSE" != no && echo "Checking root filesystem..." 109 fsck $spinner $force $fix / 110 # 111 # If there was a failure, drop into single-user mode. 112 # 113 # NOTE: "failure" is defined as exiting with a return code of 114 # 2 or larger. A return code of 1 indicates that filesystem 115 # errors were corrected but that the boot may proceed. 116 # 117 if test "$?" -gt 1 118 then 119 # Surprise! Re-directing from a HERE document (as in 120 # "cat << EOF") won't work, because the root is read-only. 121 echo 122 echo "fsck failed. Please repair manually and reboot. Please note" 123 echo "that the root filesystem is currently mounted read-only. To" 124 echo "remount it read-write:" 125 echo 126 echo " # mount -n -o remount,rw /" 127 echo 128 echo "CONTROL-D will exit from this shell and REBOOT the system." 129 echo 130 # Start a single user shell on the console 131 /sbin/sulogin $CONSOLE 132 reboot -f 133 fi 134 else 135 echo "*** ERROR! Cannot fsck root fs because it is not mounted read-only!" 136 echo 137 fi 138fi 139 140# 141# If the root filesystem was not marked as read-only in /etc/fstab, 142# remount the rootfs rw but do not try to change mtab because it 143# is on a ro fs until the remount succeeded. Then clean up old mtabs 144# and finally write the new mtab. 145# 146mount -n -o remount,$rootmode / 147if test "$rootmode" = rw 148then 149 ln -sf /proc/mounts /dev/mtab 150fi 151 152: exit 0 153