Advertisement
Guest User

Untitled

a guest
Jun 21st, 2010
453
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.89 KB | None | 0 0
  1. #!/bin/busybox ash
  2. # Install busybox's applets as symlinks
  3. /bin/busybox --install -s
  4.  
  5. . /init_functions
  6. HOOKS="encrypt"
  7. msg ":: Loading Initramfs"
  8. /bin/mount -t proc proc /proc
  9. /bin/mount -t sysfs sys /sys
  10.  
  11. read CMDLINE </proc/cmdline
  12. export CMDLINE
  13.  
  14. export root=""
  15. export init=""
  16. echo "/sbin/modprobe" > /proc/sys/kernel/modprobe
  17.  
  18. # set default mount handler
  19. mount_handler="default_mount_handler"
  20.  
  21. for cmd in ${CMDLINE}; do
  22.     case "${cmd}" in
  23.         \#*) break ;; # ignore everything after a # in the commandline
  24.         # The kernel passes those to the kernel on its own
  25.         [0123456Ss]) ;;
  26.         [0-9]*) ;;
  27.         single) ;;
  28.         rw) readwrite="yes" ;;
  29.         ro) readwrite="no" ;;
  30.         # only export stuff that does work with ash :)
  31.         *=*) rhs="$(echo "${cmd}" | cut -d= -f2-)"
  32.              cmd="$(echo "${cmd}" | cut -d= -f1 | sed 's|\.|_|g')"
  33.              cmd="$(echo "${cmd}" | sed 's|-|_|g')=${rhs}"
  34.              (echo "${cmd}" | grep -qe '^[0-9]') || export "${cmd}"
  35.              ;;
  36.         *)   cmd="$(echo "${cmd}" | sed 's|\.|_|g')"
  37.              cmd="$(echo "${cmd}" | sed 's|-|_|g')"
  38.              (echo "${cmd}" | grep -qe '^[0-9]') || export "${cmd}=y"
  39.              ;;
  40.     esac
  41. done
  42.  
  43. # If rootdelay is empty or not a non-negative integer, set it to 10
  44. if [ -z "${rootdelay}" ] || ! [ "${rootdelay}" -ge 0 ]; then
  45.     export rootdelay=10
  46. fi
  47.  
  48. if [ -e "/hooks" ]; then
  49.     for h in ${HOOKS}; do
  50.         TST=""
  51.         eval "TST=\$hook_${h}"
  52.         if [ "${TST}" != "disabled" ]; then
  53.             run_hook () { msg "${h}: no run function defined"; }
  54.             if [ -e "/hooks/${h}" ]; then
  55.                . /hooks/${h}
  56.                msg ":: Running Hook [${h}]"
  57.                run_hook
  58.             fi
  59.         fi
  60.     done
  61. fi
  62.  
  63. if [ "${break}" = "y" ]; then
  64.     echo ":: Break requested, type 'exit' to resume operation"
  65.     launch_interactive_shell
  66. fi
  67.  
  68. if [ -f "/message" ]; then
  69.     msg "$(cat /message)"
  70. fi
  71.  
  72. # Mount root at /new_root
  73. mkdir -p /new_root
  74. ${mount_handler} /new_root
  75.  
  76. [ -z "${init}" ] && init="/sbin/init"
  77. if [ "$(stat -c %D /)" = "$(stat -c %D /new_root)" ]; then
  78.     # Nothing got mounted on /new_root. This is the end, we don't know what to do anymore
  79.     # We fall back into a shell, but the shell has now PID 1
  80.     # This way, manual recovery is still possible.
  81.     err "Failed to mount the real root device."
  82.     echo "Bailing out, you are on your own. Good luck."
  83.     echo
  84.     launch_interactive_shell --exec
  85. elif [ ! -x "/new_root${init}" ]; then
  86.     # Successfully mounted /new_root, but ${init} is missing
  87.     # The same logic as above applies
  88.     err "Root device mounted successfully, but ${init} does not exist."
  89.     echo "Bailing out, you are on your own. Good luck."
  90.     echo
  91.     launch_interactive_shell --exec
  92. fi
  93.  
  94. umount /proc
  95. umount /sys
  96. exec /sbin/switch_root -c /dev/console /new_root ${init} "$@"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement