checkfs.xml 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <sect1 id="ch07-checkfs">
  2. <title>Creating the checkfs script</title>
  3. <para>Create the <filename>/etc/init.d/checkfs</filename> script by running
  4. the following command:</para>
  5. <para><screen><userinput>cat &gt; /etc/init.d/checkfs &lt;&lt; "EOF"</userinput>
  6. #!/bin/sh
  7. # Begin /etc/init.d/checkfs
  8. #
  9. # Include the functions declared in the /etc/init.d/functions file
  10. #
  11. source /etc/init.d/functions
  12. #
  13. # Activate all the swap partitions declared in the /etc/fstab file
  14. #
  15. echo -n "Activating swap..."
  16. /sbin/swapon -a
  17. evaluate_retval
  18. #
  19. # If the /fastboot file exists we don't want to run the partition checks
  20. #
  21. if [ -f /fastboot ]
  22. then
  23. echo "Fast boot, no file system check"
  24. else
  25. #
  26. # Mount the root partition read-only (just in case the kernel mounts it
  27. # read-write and we don't want to run fsck on a read-write mounted
  28. # partition).
  29. #
  30. /bin/mount -n -o remount,ro /
  31. if [ $? = 0 ]
  32. then
  33. #
  34. # If the /forcefsck file exists we want to force a partition check even
  35. # if the partition was unmounted cleanly the last time
  36. #
  37. if [ -f /forcefsck ]
  38. then
  39. echo -n "/forcefsck exists, forcing "
  40. echo "file system check"
  41. force="-f"
  42. else
  43. force=""
  44. fi
  45. #
  46. # Check all the file systems mentioned in /etc/fstab that have the
  47. # fs_passno value set to 1 or 2 (the 6th field. See man fstab for more
  48. # info)
  49. #
  50. echo "Checking file systems..."
  51. /sbin/fsck $force -a -A -C -T
  52. #
  53. # If something went wrong during the checks of one of the partitions,
  54. # fsck will exit with a return value greater than 1. If this is
  55. # the case we start sulogin so you can repair the damage manually
  56. #
  57. if [ $? -gt 1 ]
  58. then
  59. $FAILURE
  60. echo
  61. echo -n "fsck failed. Please repair your file "
  62. echo "systems manually by running /sbin/fsck"
  63. echo "without the -a option"
  64. echo
  65. echo -n "Please note that the root file system "
  66. echo "is currently mounted in read-only mode."
  67. echo
  68. echo -n "I will start sulogin now. When you "
  69. echo "logout I will reboot your system."
  70. echo
  71. $NORMAL
  72. /sbin/sulogin
  73. /sbin/reboot -f
  74. else
  75. print_status success
  76. fi
  77. else
  78. #
  79. # If the remount to read-only mode didn't work abort the fsck and print
  80. # an error
  81. #
  82. echo -n "Cannot check root file system because it "
  83. echo "could not be mounted in read-only mode."
  84. fi
  85. fi
  86. # End /etc/init.d/checkfs
  87. <userinput>EOF</userinput></screen></para>
  88. </sect1>