3
0

stop_storage 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/bin/sh
  2. # Do unmount/remount-ro. Wait.
  3. # KILL everybody. Wait.
  4. # Repeat.
  5. umountcnt=2
  6. writeout=0 # increase if your kernel does not guarantee writes to complete
  7. # No /usr - we are expecting all binaries to be accessible
  8. # from root fs alone
  9. PATH=/sbin:/bin
  10. say() {
  11. printf "\r%s\n\r" "$*"
  12. }
  13. showps() {
  14. # sleep 1 ensures that xargs will have time to start up
  15. # this makes pslist less prone to random jitter
  16. pslist=`{ sleep 1; ps -A -o comm=; } | sort | xargs`
  17. pscnt=$(( `say "$pslist" | wc -w` + 0 ))
  18. if test x"$VERBOSE" = x; then
  19. say "* `date '+%H:%M:%S'` $pscnt processes"
  20. else
  21. say "* `date '+%H:%M:%S'` Processes ($pscnt): $pslist"
  22. fi
  23. }
  24. say "<*> `date '+%Y-%m-%d %H:%M:%S'` Executing '$0 $*'"
  25. showps
  26. i="$umountcnt"
  27. while test "$i" -gt 0; do
  28. say "* `date '+%H:%M:%S'` Unmounting filesystems"
  29. umount -a -n -r -f
  30. # In case we unmounted proc...
  31. test -e /proc/version || mount -t proc none /proc
  32. # Remounting / RO isn't necessary when /etc/mtab is linked to /proc/mounts:
  33. # already done. But let's be more paranoid here...
  34. say "* `date '+%H:%M:%S'` Remounting root filesystem read-only"
  35. mount -n -o remount,ro /
  36. say "* `date '+%H:%M:%S'` Freeing loop devices"
  37. for a in /dev/loop*; do
  38. test -b "$a" && losetup -d "$a"
  39. done
  40. say "* `date '+%H:%M:%S'` Syncing"
  41. sync
  42. say "* `date '+%H:%M:%S'` Executing: killall5 -KILL"
  43. killall5 -9
  44. showps
  45. i=$((i-1))
  46. done
  47. say "* `date '+%H:%M:%S'` Filesystem status (/proc/mounts)"
  48. cat /proc/mounts \
  49. | {
  50. bad=false
  51. while read dev mntpoint fstype opt n1 n2; do
  52. case "$fstype" in
  53. ( proc | sysfs | usbfs | devpts | rpc_pipefs | binfmt_misc | autofs | rootfs | tmpfs | ramfs )
  54. say "$dev $mntpoint $fstype $opt $n1 $n2"
  55. continue
  56. ;;
  57. esac
  58. if test "${opt:0:2}" = "rw"; then
  59. say "$dev $mntpoint $fstype $opt $n1 $n2 - RW!"
  60. bad=true
  61. else
  62. say "$dev $mntpoint $fstype $opt $n1 $n2"
  63. fi
  64. done
  65. if $bad; then
  66. say "ERROR: we have filesystems mounted RW! Press <Enter> (^J)..."
  67. read junk </dev/console
  68. #sh </dev/console >&0 2>&0 # debug
  69. fi
  70. }
  71. # Disk cache writeout
  72. sleep "$writeout"