checkfs 3.9 KB

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