mountfs.xml 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <sect1 id="ch07-mountfs">
  2. <title>Creating the mountfs script</title>
  3. <?dbhtml filename="mountfs.html" dir="chapter07"?>
  4. <para>Create the <filename>/etc/init.d/mountfs</filename> script by running
  5. the following command:</para>
  6. <para><screen><userinput>cat &gt; /etc/init.d/mountfs &lt;&lt; "EOF"</userinput>
  7. #!/bin/sh
  8. # Begin /etc/init.d/mountfs
  9. #
  10. # Include the functions declared in the /etc/init.d/functions file
  11. #
  12. source /etc/init.d/functions
  13. case "$1" in
  14. start)
  15. #
  16. # Remount the root partition in read-write mode. -n tells mount
  17. # not to
  18. # write to the /etc/mtab file (because it can't do this. The
  19. # root
  20. # partition is most likely still mounted in read-only mode
  21. #
  22. echo -n "Remounting root file system in read-write mode..."
  23. /bin/mount -n -o remount,rw /
  24. evaluate_retval
  25. #
  26. # First empty the /etc/mtab file. Then remount root partition
  27. # in read-write
  28. # mode again but pass -f to mount. This way mount does
  29. # everything
  30. # except the mount itself. This is needed for it to write to the
  31. # mtab
  32. # file which contains a list of currently mounted file systems.
  33. #
  34. echo &gt; /etc/mtab
  35. /bin/mount -f -o remount,rw /
  36. #
  37. # Remove the possible /fastboot and /forcefsck files. they are
  38. # only
  39. # supposed to be used during the next reboot's checkfs which just
  40. # happened. If you want to fastboot or forcefsck again you'll
  41. # have to
  42. # recreate the files
  43. #
  44. /bin/rm -f /fastboot /forcefsck
  45. #
  46. # Walk through /etc/fstab and mount all file systems that don't
  47. # have the noauto option set in the fs_mntops field (the 4th
  48. # field.
  49. # See man fstab for more info)
  50. #
  51. echo -n "Mounting other file systems..."
  52. /bin/mount -a
  53. evaluate_retval
  54. ;;
  55. stop)
  56. #
  57. # Deactivate all the swap partitions
  58. #
  59. echo -n "Deactivating swap..."
  60. /sbin/swapoff -a
  61. evaluate_retval
  62. #
  63. # And unmount all the file systems, mounting the root file
  64. # system
  65. # read-only (all are unmounted but because root can't be
  66. # unmounted
  67. # at this point mount will automatically mount it read-only
  68. # which
  69. # is what supposed to happen. This way no data can be written
  70. # anymore from disk)
  71. #
  72. echo -n "Unmounting file systems..."
  73. /bin/umount -a -r
  74. evaluate_retval
  75. ;;
  76. *)
  77. echo "Usage: $0 {start|stop}"
  78. exit 1
  79. ;;
  80. esac
  81. # End /etc/init.d/mountfs
  82. <userinput>EOF</userinput></screen></para>
  83. </sect1>