merge of '07a342693675fe2b1daacf0eb62302579d9fade3'
[org.openembedded.dev.git] / packages / initscripts / initscripts-1.0 / mtx-2 / checkroot.sh
blobe8ae039650f26e06d433a41c73b2bf0c3644ee34
2 # checkroot.sh Check to root filesystem.
4 # Version: @(#)checkroot.sh 2.84 25-Jan-2002 miquels@cistron.nl
7 . /etc/default/rcS
10 # Set SULOGIN in /etc/default/rcS to yes if you want a sulogin to be spawned
11 # from this script *before anything else* with a timeout, like SCO does.
13 test "$SULOGIN" = yes && sulogin -t 30 $CONSOLE
16 # Ensure that bdflush (update) is running before any major I/O is
17 # performed (the following fsck is a good example of such activity :).
19 test -x /sbin/update && update
22 # Read /etc/fstab.
24 exec 9>&0 </etc/fstab
25 rootmode=rw
26 rootopts=rw
27 rootcheck=no
28 swap_on_md=no
29 devfs=
30 while read fs mnt type opts dump pass junk
32 case "$fs" in
33 ""|\#*)
34 continue;
36 /dev/md*)
37 # Swap on md device.
38 test "$type" = swap && swap_on_md=yes
40 /dev/*)
43 # Might be a swapfile.
44 test "$type" = swap && swap_on_md=yes
46 esac
47 test "$type" = devfs && devfs="$fs"
48 test "$mnt" != / && continue
49 rootopts="$opts"
50 test "$pass" = 0 -o "$pass" = "" && rootcheck=no
51 case "$opts" in
52 ro|ro,*|*,ro|*,ro,*)
53 rootmode=ro
55 esac
56 done
57 exec 0>&9 9>&-
60 # Activate the swap device(s) in /etc/fstab. This needs to be done
61 # before fsck, since fsck can be quite memory-hungry.
63 doswap=no
64 test -d /proc/1 || mount -n /proc
65 case "`uname -r`" in
66 2.[0123].*)
67 if test $swap_on_md = yes && grep -qs resync /proc/mdstat
68 then
69 test "$VERBOSE" != no && echo "Not activating swap - RAID array resyncing"
70 else
71 doswap=yes
75 doswap=yes
77 esac
78 if test $doswap = yes
79 then
80 test "$VERBOSE" != no && echo "Activating swap"
81 swapon -a 2> /dev/null
85 # Check the root filesystem.
87 if test -f /fastboot || test $rootcheck = no
88 then
89 test $rootcheck = yes && echo "Fast boot, no filesystem check"
90 else
92 # Ensure that root is quiescent and read-only before fsck'ing.
94 mount -n -o remount,ro /
95 if test $? = 0
96 then
97 if test -f /forcefsck
98 then
99 force="-f"
100 else
101 force=""
103 if test "$FSCKFIX" = yes
104 then
105 fix="-y"
106 else
107 fix="-a"
109 spinner="-C"
110 case "$TERM" in
111 dumb|network|unknown|"") spinner="" ;;
112 esac
113 test `uname -m` = s390 && spinner="" # This should go away
114 test "$VERBOSE" != no && echo "Checking root filesystem..."
115 fsck $spinner $force $fix /
117 # If there was a failure, drop into single-user mode.
119 # NOTE: "failure" is defined as exiting with a return code of
120 # 2 or larger. A return code of 1 indicates that filesystem
121 # errors were corrected but that the boot may proceed.
123 if test "$?" -gt 1
124 then
125 # Surprise! Re-directing from a HERE document (as in
126 # "cat << EOF") won't work, because the root is read-only.
127 echo
128 echo "fsck failed. Please repair manually and reboot. Please note"
129 echo "that the root filesystem is currently mounted read-only. To"
130 echo "remount it read-write:"
131 echo
132 echo " # mount -n -o remount,rw /"
133 echo
134 echo "CONTROL-D will exit from this shell and REBOOT the system."
135 echo
136 # Start a single user shell on the console
137 /sbin/sulogin $CONSOLE
138 reboot -f
140 else
141 echo "*** ERROR! Cannot fsck root fs because it is not mounted read-only!"
142 echo
147 # If the root filesystem was not marked as read-only in /etc/fstab,
148 # remount the rootfs rw but do not try to change mtab because it
149 # is on a ro fs until the remount succeeded. Then clean up old mtabs
150 # and finally write the new mtab.
151 # This part is only needed if the rootfs was mounted ro.
153 echo "Remounting root file system..."
154 mount -n -o remount,$rootmode /
155 if test "$rootmode" = rw
156 then
157 if test ! -L /etc/mtab
158 then
159 rm -f /etc/mtab~ /etc/nologin
160 : > /etc/mtab
162 mount -f -o remount /
163 mount -f /proc
164 test "$devfs" && grep -q '^devfs /dev' /proc/mounts && mount -f "$devfs"
167 : exit 0