checkfs.xml 3.0 KB

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