xref: /freebsd/libexec/rc/rc.d/fsck (revision 81ad6265)
1#!/bin/sh
2#
3# $FreeBSD$
4#
5
6# PROVIDE: fsck
7# REQUIRE: swap
8# KEYWORD: nojail
9
10. /etc/rc.subr
11
12name="fsck"
13desc="Run file system checks"
14start_cmd="fsck_start"
15stop_cmd=":"
16
17fsck_start()
18{
19	if [ "$autoboot" = no ]; then
20		echo "Fast boot: skipping disk checks."
21	elif [ ! -r /etc/fstab ]; then
22		echo "Warning! No /etc/fstab: skipping disk checks."
23	elif [ "$autoboot" = yes ]; then
24		# During fsck ignore SIGQUIT
25		trap : 3
26
27		startmsg "Starting file system checks:"
28		# Background fsck can only be run with -p
29		if checkyesno background_fsck; then
30			fsck -F -p
31		else
32			fsck ${fsck_flags}
33		fi
34
35		err=$?
36		if [ ${err} -eq 3 ]; then
37			echo "Warning! Some of the devices might not be" \
38			    "available; retrying"
39			root_hold_wait
40			startmsg "Restarting file system checks:"
41			# Background fsck can only be run with -p
42			if checkyesno background_fsck; then
43				fsck -F -p
44			else
45				fsck ${fsck_flags}
46			fi
47			err=$?
48		fi
49
50		case ${err} in
51		0)
52			;;
53		2)
54			stop_boot
55			;;
56		4)
57			echo "Rebooting..."
58			reboot
59			echo "Reboot failed; help!"
60			stop_boot
61			;;
62		8|16)
63			if checkyesno fsck_y_enable; then
64				echo "File system preen failed, trying fsck -y ${fsck_y_flags}"
65				fsck -y ${fsck_y_flags}
66				case $? in
67				0)
68					;;
69				*)
70				echo "Automatic file system check failed; help!"
71					stop_boot
72					;;
73				esac
74			else
75				echo "Automatic file system check failed; help!"
76				stop_boot
77			fi
78			;;
79		12)
80			echo "Boot interrupted."
81			stop_boot
82			;;
83		130)
84			stop_boot
85			;;
86		*)
87			echo "Unknown error ${err}; help!"
88			stop_boot
89			;;
90		esac
91	fi
92}
93
94load_rc_config $name
95run_rc_command "$1"
96