[7125722] | 1 | #!/bin/sh
|
---|
| 2 | ########################################################################
|
---|
| 3 | # Begin $rc_base/init.d/checkfs
|
---|
| 4 | #
|
---|
| 5 | # Description : File System Check
|
---|
| 6 | #
|
---|
| 7 | # Authors : Gerard Beekmans - gerard@linuxfromscratch.org
|
---|
| 8 | # A. Luebke - luebke@users.sourceforge.net
|
---|
| 9 | #
|
---|
| 10 | # Version : 00.00
|
---|
| 11 | #
|
---|
| 12 | # Notes :
|
---|
| 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 |
|
---|
| 28 | . /etc/sysconfig/rc
|
---|
| 29 | . ${rc_functions}
|
---|
| 30 |
|
---|
| 31 | case "${1}" in
|
---|
| 32 | start)
|
---|
| 33 | if [ -f /fastboot ]; then
|
---|
| 34 | boot_mesg -n "/fastboot found, will not perform" ${INFO}
|
---|
| 35 | boot_mesg " file system checks as requested."
|
---|
| 36 | echo_ok
|
---|
| 37 | exit 0
|
---|
| 38 | fi
|
---|
| 39 |
|
---|
| 40 | boot_mesg "Mounting root file system in read-only mode..."
|
---|
| 41 | mount -n -o remount,ro / >/dev/null
|
---|
| 42 | evaluate_retval
|
---|
| 43 |
|
---|
| 44 | if [ ${?} != 0 ]; then
|
---|
| 45 | echo_failure
|
---|
| 46 | boot_mesg -n "FAILURE:\n\nCannot check root" ${FAILURE}
|
---|
| 47 | boot_mesg -n " filesystem because it could not be mounted"
|
---|
| 48 | boot_mesg -n " in read-only mode.\n\nAfter you"
|
---|
| 49 | boot_mesg -n " press Enter, this system will be"
|
---|
| 50 | boot_mesg -n " halted and powered off."
|
---|
| 51 | boot_mesg -n "\n\nPress enter to continue..." ${INFO}
|
---|
| 52 | boot_mesg "" ${NORMAL}
|
---|
| 53 | read ENTER
|
---|
| 54 | ${rc_base}/init.d/halt stop
|
---|
| 55 | fi
|
---|
| 56 |
|
---|
| 57 | if [ -f /forcefsck ]; then
|
---|
| 58 | boot_mesg -n "/forcefsck found, forcing file" ${INFO}
|
---|
| 59 | boot_mesg " system checks as requested."
|
---|
| 60 | echo_ok
|
---|
| 61 | options="-f"
|
---|
| 62 | else
|
---|
| 63 | options=""
|
---|
| 64 | fi
|
---|
| 65 |
|
---|
| 66 | boot_mesg "Checking file systems..."
|
---|
| 67 | # Note: -a option used to be -p; but this fails e.g.
|
---|
| 68 | # on fsck.minix
|
---|
| 69 | fsck ${options} -a -A -C -T 2>/dev/null
|
---|
| 70 | error_value=${?}
|
---|
| 71 |
|
---|
| 72 | if [ "${error_value}" = 0 ]; then
|
---|
| 73 | echo_ok
|
---|
| 74 | fi
|
---|
| 75 |
|
---|
| 76 | if [ "${error_value}" = 1 ]; then
|
---|
| 77 | echo_warning
|
---|
| 78 | boot_mesg -n "WARNING:\n\nFile system errors" ${WARNING}
|
---|
| 79 | boot_mesg -n " were found and have been corrected."
|
---|
| 80 | boot_mesg -n " You may want to double-check that"
|
---|
| 81 | boot_mesg -n " everything was fixed properly."
|
---|
| 82 | boot_mesg "" ${NORMAL}
|
---|
| 83 | fi
|
---|
| 84 |
|
---|
| 85 | if [ "${error_value}" = 2 -o "${error_value}" = 3 ]; then
|
---|
| 86 | echo_warning
|
---|
| 87 | boot_mesg -n "WARNING:\n\nFile system errors" ${WARNING}
|
---|
| 88 | boot_mesg -n " were found and have been been"
|
---|
| 89 | boot_mesg -n " corrected, but the nature of the"
|
---|
| 90 | boot_mesg -n " errors require this system to be"
|
---|
| 91 | boot_mesg -n " rebooted.\n\nAfter you press enter,"
|
---|
| 92 | boot_mesg -n " this system will be rebooted"
|
---|
| 93 | boot_mesg -n "\n\nPress Enter to continue..." ${INFO}
|
---|
| 94 | boot_mesg "" ${NORMAL}
|
---|
| 95 | read ENTER
|
---|
| 96 | reboot -f
|
---|
| 97 | fi
|
---|
| 98 |
|
---|
| 99 | if [ "${error_value}" -gt 3 -a "${error_value}" -lt 16 ]; then
|
---|
| 100 | echo_failure
|
---|
| 101 | boot_mesg -n "FAILURE:\n\nFile system errors" ${FAILURE}
|
---|
| 102 | boot_mesg -n " were encountered that could not be"
|
---|
| 103 | boot_mesg -n " fixed automatically. This system"
|
---|
| 104 | boot_mesg -n " cannot continue to boot and will"
|
---|
| 105 | boot_mesg -n " therefore be halted until those"
|
---|
| 106 | boot_mesg -n " errors are fixed manually by a"
|
---|
| 107 | boot_mesg -n " System Administrator.\n\nAfter you"
|
---|
| 108 | boot_mesg -n " press Enter, this system will be"
|
---|
| 109 | boot_mesg -n " halted and powered off."
|
---|
| 110 | boot_mesg -n "\n\nPress Enter to continue..." ${INFO}
|
---|
| 111 | boot_mesg "" ${NORMAL}
|
---|
| 112 | read ENTER
|
---|
| 113 | ${rc_base}/init.d/halt stop
|
---|
| 114 | fi
|
---|
| 115 |
|
---|
| 116 | if [ "${error_value}" -ge 16 ]; then
|
---|
| 117 | echo_failure
|
---|
| 118 | boot_mesg -n "FAILURE:\n\nUnexpected Failure" ${FAILURE}
|
---|
| 119 | boot_mesg -n " running fsck. Exited with error"
|
---|
| 120 | boot_mesg -n " code: ${error_value}."
|
---|
| 121 | boot_mesg "" ${NORMAL}
|
---|
| 122 | exit ${error_value}
|
---|
| 123 | fi
|
---|
| 124 | ;;
|
---|
| 125 | *)
|
---|
| 126 | echo "Usage: ${0} {start}"
|
---|
| 127 | exit 1
|
---|
| 128 | ;;
|
---|
| 129 | esac
|
---|
| 130 |
|
---|
| 131 | # End $rc_base/init.d/checkfs
|
---|