diff --git a/src/etc/rc b/src/etc/rc index e82a5ba..970fa9c 100755 --- a/src/etc/rc +++ b/src/etc/rc @@ -54,7 +54,7 @@ fi if [ -e /root/force_fsck ]; then echo "Forcing filesystem(s) check..." - /sbin/fsck -y -F -t ufs + /sbin/fsck -y fi if [ "${PLATFORM}" != "cdrom" ]; then @@ -77,18 +77,37 @@ if [ "${PLATFORM}" != "cdrom" ]; then if [ ${FSCK_ACTION_NEEDED} = 1 ]; then echo "WARNING: Trying to recover filesystem from inconsistency..." - /sbin/fsck -yF + ntries=0 + fsck_rc=1 + until [ $ntries -ge 3 -o $fsck_rc -eq 0 ]; do + /sbin/fsck -y + fsck_rc=$? + ntries=$((ntries+1)) + echo "DEBUG: Run #${ntries} - rc = ${fsck_rc}" + sleep 1 + + # Sometimes first call returns 0 but filesystem is still broken + # Run fsck in preen mode again just to be sure + /sbin/fsck -p -F + fsck_rc=$? + echo "DEBUG: (-p) #${ntries} - rc = ${fsck_rc}" + sleep 1 + done + + if [ $fsck_rc -ne 0 ]; then + echo "Automatic filesystem recovery failed. Starting recovery shell!" + tcsh + reboot + fi fi /sbin/mount -a 2>/dev/null - mount_rc=$? - attempts=0 - while [ ${mount_rc} -ne 0 -a ${attempts} -lt 3 ]; do - /sbin/fsck -yF - /sbin/mount -a 2>/dev/null - mount_rc=$? - attempts=$((attempts+1)) - done + + if [ $? -ne 0 ]; then + echo "Filesystems could not be mounted. Starting recovery shell!" + tcsh + reboot + fi if [ "${PLATFORM}" = "nanobsd" ]; then # XXX This script does need all filesystems rw!!!!