1 | #!/bin/sh
|
---|
2 | # Begin /etc/init.d/checkfs
|
---|
3 |
|
---|
4 | ### BEGIN INIT INFO
|
---|
5 | # Provides: checkfs
|
---|
6 | # Required-Start: udev swap $time
|
---|
7 | # Should-Start:
|
---|
8 | # Required-Stop:
|
---|
9 | # Should-Stop:
|
---|
10 | # Default-Start: S
|
---|
11 | # Default-Stop:
|
---|
12 | # Short-Description: Checks local filesystems before mounting.
|
---|
13 | # Description: Checks local filesystmes before mounting.
|
---|
14 | # X-LFS-Provided-By: LFS
|
---|
15 | ### END INIT INFO
|
---|
16 |
|
---|
17 | . /lib/lsb/init-functions
|
---|
18 |
|
---|
19 | case "${1}" in
|
---|
20 | start)
|
---|
21 | if [ -f /fastboot ]; then
|
---|
22 | echo "${INFO}/fastboot found!"
|
---|
23 | log_success_msg "Will not perform file system checks as requested."
|
---|
24 | exit 0
|
---|
25 | fi
|
---|
26 |
|
---|
27 | mount -n -o remount,ro / >/dev/null
|
---|
28 | if [ ${?} != 0 ]
|
---|
29 | then
|
---|
30 | log_failure_msg "Mounting root file system in read-only mode"
|
---|
31 | echo -e "${FAILURE}FAILURE:\n"
|
---|
32 | echo -e -n "${FAILURE}Cannot check root filesystem because it "
|
---|
33 | echo -e "${FAILURE}could not be mounted"
|
---|
34 | echo -e "${FAILURE}in read-only mode.\n\n"
|
---|
35 | echo -e -n "${FAILURE}After you press Enter, this system will be "
|
---|
36 | echo -e "${FAILURE}halted and powered off.\n"
|
---|
37 | echo -e "${INFO}Press enter to continue...${NORMAL}"
|
---|
38 | read ENTER
|
---|
39 | /etc/rc.d/init.d/halt stop
|
---|
40 | fi
|
---|
41 |
|
---|
42 | if [ -f /forcefsck ]
|
---|
43 | then
|
---|
44 | echo "${INFO}/forcefsck found!"
|
---|
45 | log_success_msg "${INFO}Forcing file system checks as requested."
|
---|
46 | options="-f"
|
---|
47 | else
|
---|
48 | options=""
|
---|
49 | fi
|
---|
50 |
|
---|
51 | # Note: -a option used to be -p; but this fails e.g.
|
---|
52 | # on fsck.minix
|
---|
53 | fsck ${options} -a -A -C -T
|
---|
54 | error_value=${?}
|
---|
55 |
|
---|
56 | if [ "${error_value}" = 0 ]
|
---|
57 | then
|
---|
58 | log_success_msg "Checking file systems..."
|
---|
59 | elif [ "${error_value}" = 1 ]
|
---|
60 | then
|
---|
61 | log_warning_msg "Checking file systems..."
|
---|
62 | echo -e "${WARNING}WARNING:\n"
|
---|
63 | echo -e "${WARNING}File system errors were found and have been"
|
---|
64 | echo -e "${WARNING}corrected. You may want to double-check that"
|
---|
65 | echo -e "${WARNING}everything was fixed properly.${NORMAL}"
|
---|
66 | elif [ "${error_value}" = 2 -o "${error_value}" = 3 ]; then
|
---|
67 | log_warning_msg "Checking file systems..."
|
---|
68 | echo -e "${WARNING}WARNING:\n"
|
---|
69 | echo -e "${WARNING}File system errors were found and have been been"
|
---|
70 | echo -e "${WARNING}corrected, but the nature of the errors require"
|
---|
71 | echo -e "${WARNING}this system to be rebooted.\n"
|
---|
72 | echo -e "After you press enter, this system will be rebooted.\n"
|
---|
73 | echo -e "${INFO}Press Enter to continue...${NORMAL}"
|
---|
74 | read ENTER
|
---|
75 | reboot -f
|
---|
76 | elif [ "${error_value}" -gt 3 -a "${error_value}" -lt 16 ]; then
|
---|
77 | log_failure_msg "Checking file systems..."
|
---|
78 | echo -e "${FAILURE}FAILURE:\n"
|
---|
79 | echo -e "${FAILURE}File system errors were encountered that could"
|
---|
80 | echo -e "${FAILURE}not be fixed automatically. This system cannot"
|
---|
81 | echo -e "${FAILURE}continue to boot and will therefore be halted"
|
---|
82 | echo -e "${FAILURE}until those errors are fixed manually by a"
|
---|
83 | echo -e "${FAILURE}System Administrator.\n"
|
---|
84 | echo -e "${FAILURE}After you press Enter, this system will be"
|
---|
85 | echo -e "${FAILURE}halted and powered off.\n"
|
---|
86 | echo -e "${INFO}Press Enter to continue...${NORMAL}"
|
---|
87 | read ENTER
|
---|
88 | /etc/rc.d/init.d/halt stop
|
---|
89 | elif [ "${error_value}" -ge 16 ]; then
|
---|
90 | log_failure_msg "Checking file systems..."
|
---|
91 | echo -e "${FAILURE}FAILURE:\n"
|
---|
92 | echo -e "${FAILURE}Unexpected Failure running fsck. Exited with error"
|
---|
93 | echo -e "${FAILURE}code: ${error_value}.${NORMAL}"
|
---|
94 | exit ${error_value}
|
---|
95 | fi
|
---|
96 | ;;
|
---|
97 | *)
|
---|
98 | echo "Usage: ${0} {start}"
|
---|
99 | exit 1
|
---|
100 | ;;
|
---|
101 | esac
|
---|
102 |
|
---|
103 | # End /etc/init.d/checkfs
|
---|