checkfs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 any LVM based partitions are on the system, ensure they
  43. # are activated so they can be checked/used.
  44. if [ -x /sbin/vgchange ]; then
  45. /sbin/vgchange -a y >/dev/null
  46. fi
  47. if [ -f /fastboot ]; then
  48. msg="/fastboot found, will omit "
  49. msg="${msg} file system checks as requested.\n"
  50. log_info_msg "${msg}"
  51. exit 0
  52. fi
  53. log_info_msg "Mounting root file system in read-only mode... "
  54. mount -n -o remount,ro / >/dev/null
  55. if [ ${?} != 0 ]; then
  56. log_failure_msg2
  57. msg="\n\nCannot check root "
  58. msg="${msg}filesystem because it could not be mounted "
  59. msg="${msg}in read-only mode.\n\n"
  60. msg="${msg}After you press Enter, this system will be "
  61. msg="${msg}halted and powered off.\n\n"
  62. log_failure_msg "${msg}"
  63. log_info_msg "Press Enter to continue..."
  64. wait_for_user
  65. /etc/rc.d/init.d/halt stop
  66. else
  67. log_success_msg2
  68. fi
  69. if [ -f /forcefsck ]; then
  70. msg="\n/forcefsck found, forcing file"
  71. msg="${msg} system checks as requested."
  72. log_success_msg "$msg"
  73. options="-f"
  74. else
  75. options=""
  76. fi
  77. log_info_msg "Checking file systems..."
  78. # Note: -a option used to be -p; but this fails e.g. on fsck.minix
  79. fsck ${options} -a -A -C -T >/dev/null
  80. error_value=${?}
  81. if [ "${error_value}" = 0 ]; then
  82. log_success_msg2
  83. fi
  84. if [ "${error_value}" = 1 ]; then
  85. msg="\nWARNING:\n\nFile system errors "
  86. msg="${msg}were found and have been corrected.\n"
  87. msg="${msg}You may want to double-check that "
  88. msg="${msg}everything was fixed properly."
  89. log_warning_msg "$msg"
  90. fi
  91. if [ "${error_value}" = 2 -o "${error_value}" = 3 ]; then
  92. msg="\nWARNING:\n\nFile system errors "
  93. msg="${msg}were found and have been been "
  94. msg="${msg}corrected, but the nature of the "
  95. msg="${msg}errors require this system to be rebooted.\n\n"
  96. msg="${msg}After you press enter, "
  97. msg="${msg}this system will be rebooted\n\n"
  98. log_failure_msg "$msg"
  99. log_info_msg "Press Enter to continue..."
  100. wait_for_user
  101. reboot -f
  102. fi
  103. if [ "${error_value}" -gt 3 -a "${error_value}" -lt 16 ]; then
  104. msg="\nFAILURE:\n\nFile system errors "
  105. msg="${msg}were encountered that could not be "
  106. msg="${msg}fixed automatically. This system "
  107. msg="${msg}cannot continue to boot and will "
  108. msg="${msg}therefore be halted until those "
  109. msg="${msg}errors are fixed manually by a "
  110. msg="${msg}System Administrator.\n\n"
  111. msg="${msg}After you press Enter, this system will be "
  112. msg="${msg}halted and powered off.\n\n"
  113. log_failure_msg "$msg"
  114. log_info_msg "Press Enter to continue..."
  115. wait_for_user
  116. /etc/rc.d/init.d/halt stop
  117. fi
  118. if [ "${error_value}" -ge 16 ]; then
  119. msg="\nFAILURE:\n\nUnexpected Failure "
  120. msg="${msg}running fsck. Exited with error "
  121. msg="${msg} code: ${error_value}."
  122. log_failure_msg $msg
  123. exit ${error_value}
  124. fi
  125. exit 0
  126. ;;
  127. *)
  128. echo "Usage: ${0} {start}"
  129. exit 1
  130. ;;
  131. esac
  132. # End checkfs