checkfs.xml 2.9 KB

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