1
0

checkfs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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="/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. if is_true "$VERBOSE_FSCK"; then
  75. fsck ${options} -a -A -C -T
  76. else
  77. fsck ${options} -a -A -C -T >/dev/null
  78. fi
  79. error_value=${?}
  80. if [ "${error_value}" = 0 ]; then
  81. log_success_msg2
  82. fi
  83. if [ "${error_value}" = 1 ]; then
  84. msg="\nWARNING:\n\nFile system errors "
  85. msg="${msg}were found and have been corrected.\n"
  86. msg="${msg} You may want to double-check that "
  87. msg="${msg}everything was fixed properly."
  88. log_warning_msg "$msg"
  89. fi
  90. if [ "${error_value}" = 2 -o "${error_value}" = 3 ]; then
  91. msg="\nWARNING:\n\nFile system errors "
  92. msg="${msg}were found and have been been "
  93. msg="${msg}corrected, but the nature of the "
  94. msg="${msg}errors require this system to be rebooted.\n\n"
  95. msg="${msg}After you press enter, "
  96. msg="${msg}this system will be rebooted\n\n"
  97. log_failure_msg "$msg"
  98. log_info_msg "Press Enter to continue..."
  99. wait_for_user
  100. reboot -f
  101. fi
  102. if [ "${error_value}" -gt 3 -a "${error_value}" -lt 16 ]; then
  103. msg="\nFAILURE:\n\nFile system errors "
  104. msg="${msg}were encountered that could not be "
  105. msg="${msg}fixed automatically.\nThis system "
  106. msg="${msg}cannot continue to boot and will "
  107. msg="${msg}therefore be halted until those "
  108. msg="${msg}errors are fixed manually by a "
  109. msg="${msg}System Administrator.\n\n"
  110. msg="${msg}After you press Enter, this system will be "
  111. msg="${msg}halted and powered off.\n\n"
  112. log_failure_msg "$msg"
  113. log_info_msg "Press Enter to continue..."
  114. wait_for_user
  115. /etc/rc.d/init.d/halt stop
  116. fi
  117. if [ "${error_value}" -ge 16 ]; then
  118. msg="FAILURE:\n\nUnexpected failure "
  119. msg="${msg}running fsck. Exited with error "
  120. msg="${msg} code: ${error_value}.\n"
  121. log_info_msg $msg
  122. exit ${error_value}
  123. fi
  124. exit 0
  125. ;;
  126. *)
  127. echo "Usage: ${0} {start}"
  128. exit 1
  129. ;;
  130. esac
  131. # End checkfs