summaryrefslogtreecommitdiffstats
path: root/init.d/checkroot.sh
diff options
context:
space:
mode:
Diffstat (limited to 'init.d/checkroot.sh')
-rwxr-xr-xinit.d/checkroot.sh46
1 files changed, 46 insertions, 0 deletions
diff --git a/init.d/checkroot.sh b/init.d/checkroot.sh
new file mode 100755
index 0000000..94fc7ff
--- /dev/null
+++ b/init.d/checkroot.sh
@@ -0,0 +1,46 @@
+#!/bin/sh
+
+rootmode=rw
+rootopts=rw
+rootcheck=yes
+udevfs=
+
+# read the fstab
+sed 's/#.*//' /etc/fstab | while read fs mnt type opts dump pass junk
+do
+ [ "$type" = udevfs ] && udefs="$fs"
+ [ "$mnt" != / ] && continue
+ rootopts="$opts"
+ [ "$pass" = 0 -o "$pass" = "" ] && rootcheck=no
+ case "$opts" in
+ ro|ro,*|*,ro|*,ro,*)
+ rootmode=ro
+ ;;
+ esac
+done
+
+if [ "$rootcheck" = yes ] ; then
+ if grep "^$fs" /proc/mounts ; then
+ echo "$fs is mounted. Something is wrong. Please fix and reboot."
+ echo "sorry newbies..."
+ echo
+ echo "CONTROL-D will exit from this shell and reboot the system."
+ echo
+ /sbin/sulogin $CONSOLE
+ reboot -f
+ elif ! fsck -C "$fs" ; then
+ echo "fsck failed. Please repair manually and reboot. Please note"
+ echo "that the root file system is currently mounted read-only. To"
+ echo "remount it read-write:"
+ echo
+ echo " # mount -n -o remount,rw /"
+ echo
+ echo "CONTROL-D will exit from this shell and REBOOT the system."
+ echo
+ /sbin/sulogin $CONSOLE
+ reboot -f
+ fi
+fi
+
+mount -o remount,$rootmode /
+