1
0

preinit.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/bin/sh
  2. # Copyright (C) 2006-2013 OpenWrt.org
  3. # Copyright (C) 2010 Vertical Communications
  4. boot_hook_splice_start() {
  5. export -n PI_HOOK_SPLICE=1
  6. }
  7. boot_hook_splice_finish() {
  8. local hook
  9. for hook in $PI_STACK_LIST; do
  10. local v; eval "v=\${${hook}_splice:+\$${hook}_splice }$hook"
  11. export -n "${hook}=${v% }"
  12. export -n "${hook}_splice="
  13. done
  14. export -n PI_HOOK_SPLICE=
  15. }
  16. boot_hook_init() {
  17. local hook="${1}_hook"
  18. export -n "PI_STACK_LIST=${PI_STACK_LIST:+$PI_STACK_LIST }$hook"
  19. export -n "$hook="
  20. }
  21. boot_hook_add() {
  22. local hook="${1}_hook${PI_HOOK_SPLICE:+_splice}"
  23. local func="${2}"
  24. [ -n "$func" ] && {
  25. local v; eval "v=\$$hook"
  26. export -n "$hook=${v:+$v }$func"
  27. }
  28. }
  29. boot_hook_shift() {
  30. local hook="${1}_hook"
  31. local rvar="${2}"
  32. local v; eval "v=\$$hook"
  33. [ -n "$v" ] && {
  34. local first="${v%% *}"
  35. [ "$v" != "${v#* }" ] && \
  36. export -n "$hook=${v#* }" || \
  37. export -n "$hook="
  38. export -n "$rvar=$first"
  39. return 0
  40. }
  41. return 1
  42. }
  43. boot_run_hook() {
  44. local hook="$1"
  45. local func
  46. while boot_hook_shift "$hook" func; do
  47. local ran; eval "ran=\$PI_RAN_$func"
  48. [ -n "$ran" ] || {
  49. export -n "PI_RAN_$func=1"
  50. $func "$1" "$2"
  51. }
  52. done
  53. }
  54. pivot() { # <new_root> <old_root>
  55. /bin/mount -o noatime,move /proc $1/proc && \
  56. pivot_root $1 $1$2 && {
  57. /bin/mount -o noatime,move $2/dev /dev
  58. /bin/mount -o noatime,move $2/tmp /tmp
  59. /bin/mount -o noatime,move $2/sys /sys 2>&-
  60. /bin/mount -o noatime,move $2/overlay /overlay 2>&-
  61. return 0
  62. }
  63. }
  64. fopivot() { # <rw_root> <work_dir> <ro_root> <dupe?>
  65. /bin/mount -o noatime,lowerdir=/,upperdir=$1,workdir=$2 -t overlay "overlayfs:$1" /mnt
  66. pivot /mnt $3
  67. }
  68. ramoverlay() {
  69. mkdir -p /tmp/root
  70. /bin/mount -t tmpfs -o noatime,mode=0755 root /tmp/root
  71. mkdir -p /tmp/root/root /tmp/root/work
  72. fopivot /tmp/root/root /tmp/root/work /rom 1
  73. }