/rc6.d/S60umountroot

http://github.com/brinkman83/bashrc · Shell · 62 lines · 33 code · 7 blank · 22 comment · 9 complexity · aa9aa9db438cc99f76b065827971ff42 MD5 · raw file

  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: umountroot
  4. # Required-Start:
  5. # Required-Stop:
  6. # Should-Stop: halt reboot kexec
  7. # Default-Start:
  8. # Default-Stop: 0 6
  9. # Short-Description: Mount the root filesystem read-only.
  10. ### END INIT INFO
  11. PATH=/sbin:/bin
  12. . /lib/init/vars.sh
  13. . /lib/lsb/init-functions
  14. do_stop () {
  15. [ "$VERBOSE" = no ] || log_action_begin_msg "Mounting root filesystem read-only"
  16. # These directories must exist on the root filesystem as they are
  17. # targets for system mountpoints. We've just unmounted all other
  18. # filesystems, so either they are mounted now (in which case the
  19. # mount point exists) or we can make the mountpoint.
  20. for dir in /proc /sys /var/run /var/lock; do
  21. mkdir -p $dir || true
  22. done
  23. # Ask init to reexec itself before we go down if it has been
  24. # upgraded this cycle. It'll lose all its state, but at least
  25. # it won't hold open files on the root filesystem
  26. [ -f /var/run/init.upgraded ] && telinit u || :
  27. MOUNT_FORCE_OPT=
  28. [ "$(uname -s)" = "GNU/kFreeBSD" ] && MOUNT_FORCE_OPT=-f
  29. # This:
  30. # mount -n -o remount,ro /
  31. # will act on a bind mount of / if there is one.
  32. # See #339023 and the comment in checkroot.sh
  33. mount $MOUNT_FORCE_OPT -n -o remount,ro -t dummytype dummydev / 2>/dev/null \
  34. || mount $MOUNT_FORCE_OPT -n -o remount,ro dummydev / 2>/dev/null \
  35. || mount $MOUNT_FORCE_OPT -n -o remount,ro /
  36. ES=$?
  37. [ "$VERBOSE" = no ] || log_action_end_msg $ES
  38. }
  39. case "$1" in
  40. start)
  41. # No-op
  42. ;;
  43. restart|reload|force-reload)
  44. echo "Error: argument '$1' not supported" >&2
  45. exit 3
  46. ;;
  47. stop)
  48. do_stop
  49. ;;
  50. *)
  51. echo "Usage: $0 start|stop" >&2
  52. exit 3
  53. ;;
  54. esac
  55. :