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