[1c48007] | 1 | #!/bin/sh
|
---|
| 2 | ########################################################################
|
---|
[0cda898] | 3 | # Begin checkfs
|
---|
[1c48007] | 4 | #
|
---|
| 5 | # Description : File System Check
|
---|
| 6 | #
|
---|
| 7 | # Authors : Gerard Beekmans - gerard@linuxfromscratch.org
|
---|
[77e2988] | 8 | # A. Luebke - luebke@users.sourceforge.net
|
---|
[f874424] | 9 | # DJ Lucas - dj@linuxfromscratch.org
|
---|
[0cda898] | 10 | # Update : Bruce Dubbs - bdubbs@linuxfromscratch.org
|
---|
[1c48007] | 11 | #
|
---|
[0cda898] | 12 | # Version : LFS 7.0
|
---|
[1c48007] | 13 | #
|
---|
| 14 | # Based on checkfs script from LFS-3.1 and earlier.
|
---|
| 15 | #
|
---|
| 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
|
---|
| 25 | #
|
---|
| 26 | #########################################################################
|
---|
| 27 |
|
---|
[0cda898] | 28 | ### BEGIN INIT INFO
|
---|
| 29 | # Provides: checkfs
|
---|
| 30 | # Required-Start: udev swap $time
|
---|
| 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
|
---|
| 40 |
|
---|
[f874424] | 41 | . /lib/lsb/init-functions
|
---|
[1c48007] | 42 |
|
---|
| 43 | case "${1}" in
|
---|
[0cda898] | 44 | start)
|
---|
| 45 | if [ -f /fastboot ]; then
|
---|
[f874424] | 46 | msg="/fastboot found, will omit "
|
---|
| 47 | msg="${msg} file system checks as requested.\n"
|
---|
| 48 | log_info_msg "${msg}"
|
---|
[0cda898] | 49 | exit 0
|
---|
| 50 | fi
|
---|
[1c48007] | 51 |
|
---|
[f874424] | 52 | log_info_msg "Mounting root file system in read-only mode... "
|
---|
[0cda898] | 53 | mount -n -o remount,ro / >/dev/null
|
---|
[1c48007] | 54 |
|
---|
[0cda898] | 55 | if [ ${?} != 0 ]; then
|
---|
[f874424] | 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}"
|
---|
| 63 |
|
---|
| 64 | log_info_msg "Press Enter to continue..."
|
---|
[0cda898] | 65 | wait_for_user
|
---|
| 66 | /etc/rc.d/init.d/halt stop
|
---|
[f874424] | 67 | else
|
---|
| 68 | log_success_msg2
|
---|
[0cda898] | 69 | fi
|
---|
[1c48007] | 70 |
|
---|
[0cda898] | 71 | if [ -f /forcefsck ]; then
|
---|
[f874424] | 72 | msg="\n/forcefsck found, forcing file"
|
---|
| 73 | msg="${msg} system checks as requested."
|
---|
| 74 | log_success_msg "$msg"
|
---|
[0cda898] | 75 | options="-f"
|
---|
| 76 | else
|
---|
| 77 | options=""
|
---|
| 78 | fi
|
---|
[1c48007] | 79 |
|
---|
[f874424] | 80 | log_info_msg "Checking file systems..."
|
---|
| 81 | # Note: -a option used to be -p; but this fails e.g. on fsck.minix
|
---|
[9813d5e3] | 82 | fsck ${options} -a -A -C -T >/dev/null
|
---|
[0cda898] | 83 | error_value=${?}
|
---|
[1c48007] | 84 |
|
---|
[0cda898] | 85 | if [ "${error_value}" = 0 ]; then
|
---|
[f874424] | 86 | log_success_msg2
|
---|
[0cda898] | 87 | fi
|
---|
[1c48007] | 88 |
|
---|
[0cda898] | 89 | if [ "${error_value}" = 1 ]; then
|
---|
[f874424] | 90 | msg="\nWARNING:\n\nFile system errors "
|
---|
| 91 | msg="${msg}were found and have been corrected.\n"
|
---|
| 92 | msg="${msg}You may want to double-check that "
|
---|
| 93 | msg="${msg}everything was fixed properly."
|
---|
| 94 | log_warning_msg "$msg"
|
---|
[0cda898] | 95 | fi
|
---|
[1c48007] | 96 |
|
---|
[0cda898] | 97 | if [ "${error_value}" = 2 -o "${error_value}" = 3 ]; then
|
---|
[f874424] | 98 | msg="\nWARNING:\n\nFile system errors "
|
---|
| 99 | msg="${msg}were found and have been been "
|
---|
| 100 | msg="${msg}corrected, but the nature of the "
|
---|
| 101 | msg="${msg}errors require this system to be rebooted.\n\n"
|
---|
| 102 | msg="${msg}After you press enter, "
|
---|
| 103 | msg="${msg}this system will be rebooted\n\n"
|
---|
| 104 | log_failure_msg "$msg"
|
---|
| 105 |
|
---|
| 106 | log_info_msg "Press Enter to continue..."
|
---|
[0cda898] | 107 | wait_for_user
|
---|
| 108 | reboot -f
|
---|
| 109 | fi
|
---|
[1c48007] | 110 |
|
---|
[0cda898] | 111 | if [ "${error_value}" -gt 3 -a "${error_value}" -lt 16 ]; then
|
---|
[f874424] | 112 | msg="\nFAILURE:\n\nFile system errors "
|
---|
| 113 | msg="${msg}were encountered that could not be "
|
---|
| 114 | msg="${msg}fixed automatically. This system "
|
---|
| 115 | msg="${msg}cannot continue to boot and will "
|
---|
| 116 | msg="${msg}therefore be halted until those "
|
---|
| 117 | msg="${msg}errors are fixed manually by a "
|
---|
| 118 | msg="${msg}System Administrator.\n\n"
|
---|
| 119 | msg="${msg}After you press Enter, this system will be "
|
---|
| 120 | msg="${msg}halted and powered off.\n\n"
|
---|
| 121 | log_failure_msg "$msg"
|
---|
| 122 |
|
---|
| 123 | log_info_msg "Press Enter to continue..."
|
---|
[0cda898] | 124 | wait_for_user
|
---|
[f874424] | 125 | /etc/rc.d/init.d/halt stop
|
---|
[0cda898] | 126 | fi
|
---|
[1c48007] | 127 |
|
---|
[0cda898] | 128 | if [ "${error_value}" -ge 16 ]; then
|
---|
[f874424] | 129 | msg="\nFAILURE:\n\nUnexpected Failure "
|
---|
| 130 | msg="${msg}running fsck. Exited with error "
|
---|
| 131 | msg="${msg} code: ${error_value}."
|
---|
| 132 | log_failure_msg $msg
|
---|
[0cda898] | 133 | exit ${error_value}
|
---|
| 134 | fi
|
---|
[f874424] | 135 |
|
---|
| 136 | exit 0
|
---|
[0cda898] | 137 | ;;
|
---|
| 138 | *)
|
---|
| 139 | echo "Usage: ${0} {start}"
|
---|
| 140 | exit 1
|
---|
| 141 | ;;
|
---|
[1c48007] | 142 | esac
|
---|
| 143 |
|
---|
[0cda898] | 144 | # End checkfs
|
---|