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