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