2011-11-17 01:22:52 +01:00
|
|
|
#!/usr/bin/ash
|
2012-11-18 01:29:44 +01:00
|
|
|
|
2012-05-13 22:37:05 +02:00
|
|
|
udevd_running=0
|
2012-11-18 17:38:55 +01:00
|
|
|
mount_handler=default_mount_handler
|
|
|
|
init=/sbin/init
|
2013-06-17 16:06:58 +02:00
|
|
|
rd_logmask=0
|
2011-06-09 04:37:07 +02:00
|
|
|
|
2009-06-06 22:47:53 +02:00
|
|
|
. /init_functions
|
2006-04-20 21:17:22 +02:00
|
|
|
|
2017-03-10 13:12:42 +01:00
|
|
|
mount_setup
|
2006-04-20 21:17:22 +02:00
|
|
|
|
2011-04-10 21:34:55 +02:00
|
|
|
# parse the kernel command line
|
2012-12-23 19:58:36 +01:00
|
|
|
parse_cmdline </proc/cmdline
|
2006-04-20 21:17:22 +02:00
|
|
|
|
2013-06-17 16:06:58 +02:00
|
|
|
# setup logging as early as possible
|
|
|
|
rdlogger_start
|
|
|
|
|
2011-11-16 18:03:31 +01:00
|
|
|
for d in ${disablehooks//,/ }; do
|
2012-05-12 02:34:39 +02:00
|
|
|
[ -e "/hooks/$d" ] && chmod 644 "/hooks/$d"
|
2011-11-16 18:03:31 +01:00
|
|
|
done
|
2006-04-20 21:17:22 +02:00
|
|
|
|
|
|
|
. /config
|
|
|
|
|
2012-05-12 02:45:12 +02:00
|
|
|
run_hookfunctions 'run_earlyhook' 'early hook' $EARLYHOOKS
|
|
|
|
|
2012-11-01 21:39:55 +01:00
|
|
|
if [ -n "$earlymodules$MODULES" ]; then
|
|
|
|
modprobe -qab ${earlymodules//,/ } $MODULES
|
|
|
|
fi
|
2006-04-25 08:08:55 +02:00
|
|
|
|
2012-05-12 02:34:39 +02:00
|
|
|
run_hookfunctions 'run_hook' 'hook' $HOOKS
|
2006-04-20 21:17:22 +02:00
|
|
|
|
2011-07-17 05:34:43 +02:00
|
|
|
# honor the old behavior of break=y as a synonym for break=premount
|
|
|
|
if [ "${break}" = "y" ] || [ "${break}" = "premount" ]; then
|
|
|
|
echo ":: Pre-mount break requested, type 'exit' to resume operation"
|
2010-01-29 19:56:50 +01:00
|
|
|
launch_interactive_shell
|
2006-04-20 21:17:22 +02:00
|
|
|
fi
|
|
|
|
|
2011-11-06 18:30:40 +01:00
|
|
|
rootdev=$(resolve_device "$root") && root=$rootdev
|
|
|
|
unset rootdev
|
|
|
|
|
2012-01-29 04:41:34 +01:00
|
|
|
fsck_root
|
2011-11-06 18:30:40 +01:00
|
|
|
|
2010-02-16 00:57:32 +01:00
|
|
|
# Mount root at /new_root
|
2012-11-18 17:38:55 +01:00
|
|
|
"$mount_handler" /new_root
|
2010-02-14 19:15:09 +01:00
|
|
|
|
2012-06-07 22:47:23 +02:00
|
|
|
run_hookfunctions 'run_latehook' 'late hook' $LATEHOOKS
|
|
|
|
run_hookfunctions 'run_cleanuphook' 'cleanup hook' $CLEANUPHOOKS
|
|
|
|
|
2010-02-16 20:15:16 +01:00
|
|
|
if [ "$(stat -c %D /)" = "$(stat -c %D /new_root)" ]; then
|
2010-02-16 01:05:26 +01:00
|
|
|
# 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
|
2010-02-17 01:41:51 +01:00
|
|
|
elif [ ! -x "/new_root${init}" ]; then
|
2010-02-16 01:05:26 +01:00
|
|
|
# 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
|
2010-02-15 16:19:04 +01:00
|
|
|
fi
|
|
|
|
|
2011-07-17 05:34:43 +02:00
|
|
|
if [ "${break}" = "postmount" ]; then
|
|
|
|
echo ":: Post-mount break requested, type 'exit' to resume operation"
|
|
|
|
launch_interactive_shell
|
|
|
|
fi
|
|
|
|
|
2013-06-30 16:43:04 +02:00
|
|
|
# this should always be the last thing we do before the switch_root.
|
2013-06-17 16:06:58 +02:00
|
|
|
rdlogger_stop
|
|
|
|
|
2012-05-18 04:18:47 +02:00
|
|
|
exec env -i \
|
|
|
|
"TERM=$TERM" \
|
|
|
|
/usr/bin/switch_root /new_root $init "$@"
|
2011-06-07 21:42:39 +02:00
|
|
|
|
|
|
|
# vim: set ft=sh ts=4 sw=4 et:
|