Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/busybox ash
- # Install busybox's applets as symlinks
- /bin/busybox --install -s
- . /init_functions
- HOOKS="encrypt"
- msg ":: Loading Initramfs"
- /bin/mount -t proc proc /proc
- /bin/mount -t sysfs sys /sys
- read CMDLINE </proc/cmdline
- export CMDLINE
- export root=""
- export init=""
- echo "/sbin/modprobe" > /proc/sys/kernel/modprobe
- # set default mount handler
- mount_handler="default_mount_handler"
- for cmd in ${CMDLINE}; do
- case "${cmd}" in
- \#*) break ;; # ignore everything after a # in the commandline
- # The kernel passes those to the kernel on its own
- [0123456Ss]) ;;
- [0-9]*) ;;
- single) ;;
- rw) readwrite="yes" ;;
- ro) readwrite="no" ;;
- # only export stuff that does work with ash :)
- *=*) rhs="$(echo "${cmd}" | cut -d= -f2-)"
- cmd="$(echo "${cmd}" | cut -d= -f1 | sed 's|\.|_|g')"
- cmd="$(echo "${cmd}" | sed 's|-|_|g')=${rhs}"
- (echo "${cmd}" | grep -qe '^[0-9]') || export "${cmd}"
- ;;
- *) cmd="$(echo "${cmd}" | sed 's|\.|_|g')"
- cmd="$(echo "${cmd}" | sed 's|-|_|g')"
- (echo "${cmd}" | grep -qe '^[0-9]') || export "${cmd}=y"
- ;;
- esac
- done
- # If rootdelay is empty or not a non-negative integer, set it to 10
- if [ -z "${rootdelay}" ] || ! [ "${rootdelay}" -ge 0 ]; then
- export rootdelay=10
- fi
- if [ -e "/hooks" ]; then
- for h in ${HOOKS}; do
- TST=""
- eval "TST=\$hook_${h}"
- if [ "${TST}" != "disabled" ]; then
- run_hook () { msg "${h}: no run function defined"; }
- if [ -e "/hooks/${h}" ]; then
- . /hooks/${h}
- msg ":: Running Hook [${h}]"
- run_hook
- fi
- fi
- done
- fi
- if [ "${break}" = "y" ]; then
- echo ":: Break requested, type 'exit' to resume operation"
- launch_interactive_shell
- fi
- if [ -f "/message" ]; then
- msg "$(cat /message)"
- fi
- # Mount root at /new_root
- mkdir -p /new_root
- ${mount_handler} /new_root
- [ -z "${init}" ] && init="/sbin/init"
- if [ "$(stat -c %D /)" = "$(stat -c %D /new_root)" ]; then
- # Nothing got mounted on /new_root. This is the end, we don't know what to do anymore
- # We fall back into a shell, but the shell has now PID 1
- # This way, manual recovery is still possible.
- err "Failed to mount the real root device."
- echo "Bailing out, you are on your own. Good luck."
- echo
- launch_interactive_shell --exec
- elif [ ! -x "/new_root${init}" ]; then
- # Successfully mounted /new_root, but ${init} is missing
- # The same logic as above applies
- err "Root device mounted successfully, but ${init} does not exist."
- echo "Bailing out, you are on your own. Good luck."
- echo
- launch_interactive_shell --exec
- fi
- umount /proc
- umount /sys
- exec /sbin/switch_root -c /dev/console /new_root ${init} "$@"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement