checkfs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. # Update : Bruce Dubbs - bdubbs@linuxfromscratch.org
  10. #
  11. # Version : LFS 7.0
  12. #
  13. # Based on checkfs script from LFS-3.1 and earlier.
  14. #
  15. # From man fsck
  16. # 0 - No errors
  17. # 1 - File system errors corrected
  18. # 2 - System should be rebooted
  19. # 4 - File system errors left uncorrected
  20. # 8 - Operational error
  21. # 16 - Usage or syntax error
  22. # 32 - Fsck canceled by user request
  23. # 128 - Shared library error
  24. #
  25. #########################################################################
  26. ### BEGIN INIT INFO
  27. # Provides: checkfs
  28. # Required-Start: udev swap $time
  29. # Should-Start:
  30. # Required-Stop:
  31. # Should-Stop:
  32. # Default-Start: S
  33. # Default-Stop:
  34. # Short-Description: Checks local filesystems before mounting.
  35. # Description: Checks local filesystmes before mounting.
  36. # X-LFS-Provided-By: LFS
  37. ### END INIT INFO
  38. . /lib/boot/functions
  39. case "${1}" in
  40. start)
  41. if [ -f /fastboot ]; then
  42. boot_mesg -n "/fastboot found, will not perform" ${INFO}
  43. boot_mesg " file system checks as requested."
  44. echo_ok
  45. exit 0
  46. fi
  47. boot_mesg "Mounting root file system in read-only mode..."
  48. mount -n -o remount,ro / >/dev/null
  49. evaluate_retval
  50. if [ ${?} != 0 ]; then
  51. echo_failure
  52. boot_mesg -n "FAILURE:\n\nCannot check root" ${FAILURE}
  53. boot_mesg -n " filesystem because it could not be mounted"
  54. boot_mesg -n " in read-only mode.\n\nAfter you"
  55. boot_mesg -n " press Enter, this system will be"
  56. boot_mesg -n " halted and powered off."
  57. boot_mesg -n "\n\nPress enter to continue..." ${INFO}
  58. boot_mesg "" ${NORMAL}
  59. wait_for_user
  60. /etc/rc.d/init.d/halt stop
  61. fi
  62. if [ -f /forcefsck ]; then
  63. boot_mesg -n "/forcefsck found, forcing file" ${INFO}
  64. boot_mesg " system checks as requested."
  65. echo_ok
  66. options="-f"
  67. else
  68. options=""
  69. fi
  70. boot_mesg "Checking file systems..."
  71. # Note: -a option used to be -p; but this fails e.g.
  72. # on fsck.minix
  73. fsck ${options} -a -A -C -T
  74. error_value=${?}
  75. if [ "${error_value}" = 0 ]; then
  76. echo_ok
  77. fi
  78. if [ "${error_value}" = 1 ]; then
  79. echo_warning
  80. boot_mesg -n "WARNING:\n\nFile system errors" ${WARNING}
  81. boot_mesg -n " were found and have been corrected. "
  82. boot_mesg -n " You may want to double-check that"
  83. boot_mesg -n " everything was fixed properly."
  84. boot_mesg "" ${NORMAL}
  85. fi
  86. if [ "${error_value}" = 2 -o "${error_value}" = 3 ]; then
  87. echo_warning
  88. boot_mesg -n "WARNING:\n\nFile system errors" ${WARNING}
  89. boot_mesg -n " were found and have been been"
  90. boot_mesg -n " corrected, but the nature of the"
  91. boot_mesg -n " errors require this system to be"
  92. boot_mesg -n " rebooted.\n\nAfter you press enter,"
  93. boot_mesg -n " this system will be rebooted"
  94. boot_mesg -n "\n\nPress Enter to continue..." ${INFO}
  95. boot_mesg "" ${NORMAL}
  96. wait_for_user
  97. reboot -f
  98. fi
  99. if [ "${error_value}" -gt 3 -a "${error_value}" -lt 16 ]; then
  100. echo_failure
  101. boot_mesg -n "FAILURE:\n\nFile system errors" ${FAILURE}
  102. boot_mesg -n " were encountered that could not be"
  103. boot_mesg -n " fixed automatically. This system"
  104. boot_mesg -n " cannot continue to boot and will"
  105. boot_mesg -n " therefore be halted until those"
  106. boot_mesg -n " errors are fixed manually by a"
  107. boot_mesg -n " System Administrator.\n\nAfter you"
  108. boot_mesg -n " press Enter, this system will be"
  109. boot_mesg -n " halted and powered off."
  110. boot_mesg -n "\n\nPress Enter to continue..." ${INFO}
  111. boot_mesg "" ${NORMAL}
  112. wait_for_user
  113. /etc/rc.d/init.d/halt stop
  114. fi
  115. if [ "${error_value}" -ge 16 ]; then
  116. echo_failure
  117. boot_mesg -n "FAILURE:\n\nUnexpected Failure" ${FAILURE}
  118. boot_mesg -n " running fsck. Exited with error"
  119. boot_mesg -n " code: ${error_value}."
  120. boot_mesg "" ${NORMAL}
  121. exit ${error_value}
  122. fi
  123. ;;
  124. *)
  125. echo "Usage: ${0} {start}"
  126. exit 1
  127. ;;
  128. esac
  129. # End checkfs