1
0

checkfs 4.3 KB

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