1
0

checkfs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #!/bin/sh
  2. ########################################################################
  3. # Begin $rc_base/init.d/checkfs
  4. #
  5. # Description : File System Check
  6. #
  7. # Authors : Gerard Beekmans - gerard@linuxfromscratch.org
  8. # A. Luebke - luebke@users.sourceforge.net
  9. #
  10. # Version : 00.00
  11. #
  12. # Notes :
  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. . /etc/sysconfig/rc
  28. . ${rc_functions}
  29. case "${1}" in
  30. start)
  31. if [ -f /fastboot ]; then
  32. boot_mesg -n "/fastboot found, will not perform" ${INFO}
  33. boot_mesg " file system checks as requested."
  34. echo_ok
  35. exit 0
  36. fi
  37. boot_mesg "Mounting root file system in read-only mode..."
  38. mount -n -o remount,ro / >/dev/null
  39. evaluate_retval
  40. if [ ${?} != 0 ]; then
  41. echo_failure
  42. boot_mesg -n "FAILURE:\n\nCannot check root" ${FAILURE}
  43. boot_mesg -n " filesystem because it could not be mounted"
  44. boot_mesg -n " in read-only mode.\n\nAfter you"
  45. boot_mesg -n " press Enter, this system will be"
  46. boot_mesg -n " halted and powered off."
  47. boot_mesg -n "\n\nPress enter to continue..." ${INFO}
  48. boot_mesg "" ${NORMAL}
  49. read ENTER
  50. ${rc_base}/init.d/halt stop
  51. fi
  52. if [ -f /forcefsck ]; then
  53. boot_mesg -n "/forcefsck found, forcing file" ${INFO}
  54. boot_mesg " system checks as requested."
  55. echo_ok
  56. options="-f"
  57. else
  58. options=""
  59. fi
  60. boot_mesg "Checking file systems..."
  61. # Note: -a option used to be -p; but this fails e.g.
  62. # on fsck.minix
  63. fsck ${options} -a -A -C -T
  64. error_value=${?}
  65. if [ "${error_value}" = 0 ]; then
  66. echo_ok
  67. fi
  68. if [ "${error_value}" = 1 ]; then
  69. echo_warning
  70. boot_mesg -n "WARNING:\n\nFile system errors" ${WARNING}
  71. boot_mesg -n " were found and have been corrected."
  72. boot_mesg -n " You may want to double-check that"
  73. boot_mesg -n " everything was fixed properly."
  74. boot_mesg "" ${NORMAL}
  75. fi
  76. if [ "${error_value}" = 2 -o "${error_value}" = 3 ]; then
  77. echo_warning
  78. boot_mesg -n "WARNING:\n\nFile system errors" ${WARNING}
  79. boot_mesg -n " were found and have been been"
  80. boot_mesg -n " corrected, but the nature of the"
  81. boot_mesg -n " errors require this system to be"
  82. boot_mesg -n " rebooted.\n\nAfter you press enter,"
  83. boot_mesg -n " this system will be rebooted"
  84. boot_mesg -n "\n\nPress Enter to continue..." ${INFO}
  85. boot_mesg "" ${NORMAL}
  86. read ENTER
  87. reboot -f
  88. fi
  89. if [ "${error_value}" -gt 3 -a "${error_value}" -lt 16 ]; then
  90. echo_failure
  91. boot_mesg -n "FAILURE:\n\nFile system errors" ${FAILURE}
  92. boot_mesg -n " were encountered that could not be"
  93. boot_mesg -n " fixed automatically. This system"
  94. boot_mesg -n " cannot continue to boot and will"
  95. boot_mesg -n " therefore be halted until those"
  96. boot_mesg -n " errors are fixed manually by a"
  97. boot_mesg -n " System Administrator.\n\nAfter you"
  98. boot_mesg -n " press Enter, this system will be"
  99. boot_mesg -n " halted and powered off."
  100. boot_mesg -n "\n\nPress Enter to continue..." ${INFO}
  101. boot_mesg "" ${NORMAL}
  102. read ENTER
  103. ${rc_base}/init.d/halt stop
  104. fi
  105. if [ "${error_value}" -ge 16 ]; then
  106. echo_failure
  107. boot_mesg -n "FAILURE:\n\nUnexpected Failure" ${FAILURE}
  108. boot_mesg -n " running fsck. Exited with error"
  109. boot_mesg -n " code: ${error_value}."
  110. boot_mesg "" ${NORMAL}
  111. exit ${error_value}
  112. fi
  113. ;;
  114. *)
  115. echo "Usage: ${0} {start}"
  116. exit 1
  117. ;;
  118. esac
  119. # End $rc_base/init.d/checkfs