Home | History | Annotate | Line # | Download | only in rc.d
fsck_root revision 1.2
      1 #!/bin/sh
      2 #
      3 # $NetBSD: fsck_root,v 1.2 2009/04/28 13:08:51 apb Exp $
      4 #
      5 
      6 # PROVIDE: fsck_root
      7 
      8 $_rc_subr_loaded . /etc/rc.subr
      9 
     10 name="fsck_root"
     11 start_cmd="fsck_root_start"
     12 stop_cmd=":"
     13 fstab_file=/etc/fstab
     14 
     15 fsck_root_start()
     16 {
     17 	if [ -e /fastboot ]; then
     18 		echo "Fast boot: skipping disk checks."
     19 		return
     20 	fi
     21 	trap : 2 		# Ignore SIGINT, SIGQUIT, so we
     22 	trap : 3		# enter single-user mode on failure.
     23 
     24 	# Do nothing if root file system has fs_passno=0 in /etc/fstab.
     25 	while read fs_spec fs_file fs_vfstype fs_mntops fs_freq fs_passno
     26 	do
     27 		case "${fs_spec}:${fs_file}:${fs_passno}" in
     28 		\#*|'':*)
     29 			continue # skip comment or blank line
     30 			;;
     31 		*:/:0)
     32 			echo "Not checking /: fs_passno = 0 in ${fstab_file}"
     33 			return
     34 			;;
     35 		*:/:*)	break
     36 			;;
     37 		esac
     38 	done <"${fstab_file}"
     39 
     40 	echo "Starting root file system check:"
     41 	fsck $fsck_flags /
     42 	local fsck_error="$?"
     43 	case $fsck_error in
     44 	0)	# OK
     45 		return
     46 		;;
     47 	2)	# Needs re-run, still fs errors
     48 		echo "file system still has errors; re-run fsck manually!"
     49 		;;
     50 	4)	# Root modified
     51 		echo "Root filesystem was modified, rebooting ..."
     52 		reboot
     53 		echo "Reboot failed; help!"
     54 		;;
     55 	8)	# Check failed
     56 		echo "Automatic file system check failed; help!"
     57 		;;
     58 	12)	# Got signal
     59 		echo "Boot interrupted."
     60 		;;
     61 	*)
     62 		echo "Unknown error $fsck_error; help!"
     63 		;;
     64 	esac
     65 	stop_boot
     66 }
     67 
     68 load_rc_config $name
     69 run_rc_command "$1"
     70