checkfs 3.8 KB

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