checkfs.xml 2.9 KB

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