remove an old note for file
[linux_from_scratch.git] / BOOK / bootscripts / lfs / init.d / checkfs
blob061d136e5cd9ddf64fa4e97d6b0b9b5a68a3ea89
1 #!/bin/sh
2 ########################################################################
3 # Begin checkfs
5 # Description : File System Check
7 # Authors : Gerard Beekmans - gerard@linuxfromscratch.org
8 # A. Luebke - luebke@users.sourceforge.net
9 # DJ Lucas - dj@linuxfromscratch.org
10 # Update : Bruce Dubbs - bdubbs@linuxfromscratch.org
12 # Version : LFS 7.0
14 # Based on checkfs script from LFS-3.1 and earlier.
16 # From man fsck
17 # 0 - No errors
18 # 1 - File system errors corrected
19 # 2 - System should be rebooted
20 # 4 - File system errors left uncorrected
21 # 8 - Operational error
22 # 16 - Usage or syntax error
23 # 32 - Fsck canceled by user request
24 # 128 - Shared library error
26 #########################################################################
28 ### BEGIN INIT INFO
29 # Provides: checkfs
30 # Required-Start: udev swap
31 # Should-Start:
32 # Required-Stop:
33 # Should-Stop:
34 # Default-Start: S
35 # Default-Stop:
36 # Short-Description: Checks local filesystems before mounting.
37 # Description: Checks local filesystmes before mounting.
38 # X-LFS-Provided-By: LFS
39 ### END INIT INFO
41 . /lib/lsb/init-functions
43 case "${1}" in
44 start)
45 if [ -f /fastboot ]; then
46 msg="/fastboot found, will omit "
47 msg="${msg} file system checks as requested.\n"
48 log_info_msg "${msg}"
49 exit 0
52 log_info_msg "Mounting root file system in read-only mode... "
53 mount -n -o remount,ro / >/dev/null
55 if [ ${?} != 0 ]; then
56 log_failure_msg2
57 msg="\n\nCannot check root "
58 msg="${msg}filesystem because it could not be mounted "
59 msg="${msg}in read-only mode.\n\n"
60 msg="${msg}After you press Enter, this system will be "
61 msg="${msg}halted and powered off.\n\n"
62 log_failure_msg "${msg}"
64 log_info_msg "Press Enter to continue..."
65 wait_for_user
66 /etc/rc.d/init.d/halt stop
67 else
68 log_success_msg2
71 if [ -f /forcefsck ]; then
72 msg="/forcefsck found, forcing file"
73 msg="${msg} system checks as requested."
74 log_success_msg "$msg"
75 options="-f"
76 else
77 options=""
80 log_info_msg "Checking file systems..."
81 # Note: -a option used to be -p; but this fails e.g. on fsck.minix
82 if is_true "$VERBOSE_FSCK"; then
83 fsck ${options} -a -A -C -T
84 else
85 fsck ${options} -a -A -C -T >/dev/null
88 error_value=${?}
90 if [ "${error_value}" = 0 ]; then
91 log_success_msg2
94 if [ "${error_value}" = 1 ]; then
95 msg="\nWARNING:\n\nFile system errors "
96 msg="${msg}were found and have been corrected.\n"
97 msg="${msg} You may want to double-check that "
98 msg="${msg}everything was fixed properly."
99 log_warning_msg "$msg"
102 if [ "${error_value}" = 2 -o "${error_value}" = 3 ]; then
103 msg="\nWARNING:\n\nFile system errors "
104 msg="${msg}were found and have been been "
105 msg="${msg}corrected, but the nature of the "
106 msg="${msg}errors require this system to be rebooted.\n\n"
107 msg="${msg}After you press enter, "
108 msg="${msg}this system will be rebooted\n\n"
109 log_failure_msg "$msg"
111 log_info_msg "Press Enter to continue..."
112 wait_for_user
113 reboot -f
116 if [ "${error_value}" -gt 3 -a "${error_value}" -lt 16 ]; then
117 msg="\nFAILURE:\n\nFile system errors "
118 msg="${msg}were encountered that could not be "
119 msg="${msg}fixed automatically.\nThis system "
120 msg="${msg}cannot continue to boot and will "
121 msg="${msg}therefore be halted until those "
122 msg="${msg}errors are fixed manually by a "
123 msg="${msg}System Administrator.\n\n"
124 msg="${msg}After you press Enter, this system will be "
125 msg="${msg}halted and powered off.\n\n"
126 log_failure_msg "$msg"
128 log_info_msg "Press Enter to continue..."
129 wait_for_user
130 /etc/rc.d/init.d/halt stop
133 if [ "${error_value}" -ge 16 ]; then
134 msg="FAILURE:\n\nUnexpected failure "
135 msg="${msg}running fsck. Exited with error "
136 msg="${msg} code: ${error_value}.\n"
137 log_info_msg $msg
138 exit ${error_value}
141 exit 0
144 echo "Usage: ${0} {start}"
145 exit 1
147 esac
149 # End checkfs