1 | #!/bin/sh
|
---|
2 | ########################################################################
|
---|
3 | # Begin checkfs
|
---|
4 | #
|
---|
5 | # Description : File System Check
|
---|
6 | #
|
---|
7 | # Authors : Gerard Beekmans - gerard@linuxfromscratch.org
|
---|
8 | # A. Luebke - luebke@users.sourceforge.net
|
---|
9 | # Update : Bruce Dubbs - bdubbs@linuxfromscratch.org
|
---|
10 | #
|
---|
11 | # Version : LFS 7.0
|
---|
12 | #
|
---|
13 | # Based on checkfs script from LFS-3.1 and earlier.
|
---|
14 | #
|
---|
15 | # From man fsck
|
---|
16 | # 0 - No errors
|
---|
17 | # 1 - File system errors corrected
|
---|
18 | # 2 - System should be rebooted
|
---|
19 | # 4 - File system errors left uncorrected
|
---|
20 | # 8 - Operational error
|
---|
21 | # 16 - Usage or syntax error
|
---|
22 | # 32 - Fsck canceled by user request
|
---|
23 | # 128 - Shared library error
|
---|
24 | #
|
---|
25 | #########################################################################
|
---|
26 |
|
---|
27 | ### BEGIN INIT INFO
|
---|
28 | # Provides: checkfs
|
---|
29 | # Required-Start: udev swap $time
|
---|
30 | # Should-Start:
|
---|
31 | # Required-Stop:
|
---|
32 | # Should-Stop:
|
---|
33 | # Default-Start: S
|
---|
34 | # Default-Stop:
|
---|
35 | # Short-Description: Checks local filesystems before mounting.
|
---|
36 | # Description: Checks local filesystmes before mounting.
|
---|
37 | # X-LFS-Provided-By: LFS
|
---|
38 | ### END INIT INFO
|
---|
39 |
|
---|
40 | . /lib/boot/functions
|
---|
41 |
|
---|
42 | case "${1}" in
|
---|
43 | start)
|
---|
44 | if [ -f /fastboot ]; then
|
---|
45 | boot_mesg -n "/fastboot found, will not perform" ${INFO}
|
---|
46 | boot_mesg " file system checks as requested."
|
---|
47 | echo_ok
|
---|
48 | exit 0
|
---|
49 | fi
|
---|
50 |
|
---|
51 | boot_mesg "Mounting root file system in read-only mode..."
|
---|
52 | mount -n -o remount,ro / >/dev/null
|
---|
53 | evaluate_retval
|
---|
54 |
|
---|
55 | if [ ${?} != 0 ]; then
|
---|
56 | echo_failure
|
---|
57 | boot_mesg -n "FAILURE:\n\nCannot check root" ${FAILURE}
|
---|
58 | boot_mesg -n " filesystem because it could not be mounted"
|
---|
59 | boot_mesg -n " in read-only mode.\n\nAfter you"
|
---|
60 | boot_mesg -n " press Enter, this system will be"
|
---|
61 | boot_mesg -n " halted and powered off."
|
---|
62 | boot_mesg -n "\n\nPress enter to continue..." ${INFO}
|
---|
63 | boot_mesg "" ${NORMAL}
|
---|
64 | wait_for_user
|
---|
65 | /etc/rc.d/init.d/halt stop
|
---|
66 | fi
|
---|
67 |
|
---|
68 | if [ -f /forcefsck ]; then
|
---|
69 | boot_mesg -n "/forcefsck found, forcing file" ${INFO}
|
---|
70 | boot_mesg " system checks as requested."
|
---|
71 | echo_ok
|
---|
72 | options="-f"
|
---|
73 | else
|
---|
74 | options=""
|
---|
75 | fi
|
---|
76 |
|
---|
77 | boot_mesg "Checking file systems..."
|
---|
78 | # Note: -a option used to be -p; but this fails e.g.
|
---|
79 | # on fsck.minix
|
---|
80 | fsck ${options} -a -A -C -T
|
---|
81 | error_value=${?}
|
---|
82 |
|
---|
83 | if [ "${error_value}" = 0 ]; then
|
---|
84 | echo_ok
|
---|
85 | fi
|
---|
86 |
|
---|
87 | if [ "${error_value}" = 1 ]; then
|
---|
88 | echo_warning
|
---|
89 | boot_mesg -n "WARNING:\n\nFile system errors" ${WARNING}
|
---|
90 | boot_mesg -n " were found and have been corrected. "
|
---|
91 | boot_mesg -n " You may want to double-check that"
|
---|
92 | boot_mesg -n " everything was fixed properly."
|
---|
93 | boot_mesg "" ${NORMAL}
|
---|
94 | fi
|
---|
95 |
|
---|
96 | if [ "${error_value}" = 2 -o "${error_value}" = 3 ]; then
|
---|
97 | echo_warning
|
---|
98 | boot_mesg -n "WARNING:\n\nFile system errors" ${WARNING}
|
---|
99 | boot_mesg -n " were found and have been been"
|
---|
100 | boot_mesg -n " corrected, but the nature of the"
|
---|
101 | boot_mesg -n " errors require this system to be"
|
---|
102 | boot_mesg -n " rebooted.\n\nAfter you press enter,"
|
---|
103 | boot_mesg -n " this system will be rebooted"
|
---|
104 | boot_mesg -n "\n\nPress Enter to continue..." ${INFO}
|
---|
105 | boot_mesg "" ${NORMAL}
|
---|
106 | wait_for_user
|
---|
107 | reboot -f
|
---|
108 | fi
|
---|
109 |
|
---|
110 | if [ "${error_value}" -gt 3 -a "${error_value}" -lt 16 ]; then
|
---|
111 | echo_failure
|
---|
112 | boot_mesg -n "FAILURE:\n\nFile system errors" ${FAILURE}
|
---|
113 | boot_mesg -n " were encountered that could not be"
|
---|
114 | boot_mesg -n " fixed automatically. This system"
|
---|
115 | boot_mesg -n " cannot continue to boot and will"
|
---|
116 | boot_mesg -n " therefore be halted until those"
|
---|
117 | boot_mesg -n " errors are fixed manually by a"
|
---|
118 | boot_mesg -n " System Administrator.\n\nAfter you"
|
---|
119 | boot_mesg -n " press Enter, this system will be"
|
---|
120 | boot_mesg -n " halted and powered off."
|
---|
121 | boot_mesg -n "\n\nPress Enter to continue..." ${INFO}
|
---|
122 | boot_mesg "" ${NORMAL}
|
---|
123 | wait_for_user
|
---|
124 | /etc/rc.d/init.d/halt stop
|
---|
125 | fi
|
---|
126 |
|
---|
127 | if [ "${error_value}" -ge 16 ]; then
|
---|
128 | echo_failure
|
---|
129 | boot_mesg -n "FAILURE:\n\nUnexpected Failure" ${FAILURE}
|
---|
130 | boot_mesg -n " running fsck. Exited with error"
|
---|
131 | boot_mesg -n " code: ${error_value}."
|
---|
132 | boot_mesg "" ${NORMAL}
|
---|
133 | exit ${error_value}
|
---|
134 | fi
|
---|
135 | ;;
|
---|
136 | *)
|
---|
137 | echo "Usage: ${0} {start}"
|
---|
138 | exit 1
|
---|
139 | ;;
|
---|
140 | esac
|
---|
141 |
|
---|
142 | # End checkfs
|
---|