mountfs.xml 2.6 KB

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