summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Bächler <thomas@archlinux.org>2010-02-15 16:19:04 +0100
committerThomas Bächler <thomas@archlinux.org>2010-02-15 16:19:04 +0100
commit049712038da250f1436373ae62e2d611f1edfb49 (patch)
tree0d21be2954b7b6369069776fedb356ec787a47de
parent9ce0669a892c5e6608e215a38768f2b65dbd7ec9 (diff)
downloadmkinitcpio-049712038da250f1436373ae62e2d611f1edfb49.tar.gz
mkinitcpio-049712038da250f1436373ae62e2d611f1edfb49.tar.xz
If we could not mount the real root device, or the init program did not exist on it, bail out instead of panicing
In these cases, we will exec /bin/sh, such that manual recovery is still possible as sh has PID 1 An expert might be able to mount and switch_root manually. In any case, this is less scary than a panic and a useless trace.
-rw-r--r--init19
-rw-r--r--init_functions4
2 files changed, 21 insertions, 2 deletions
diff --git a/init b/init
index e860047..180ce84 100644
--- a/init
+++ b/init
@@ -180,6 +180,24 @@ else
nfsmount ${nfs_option:+-o ${nfs_option}} "${nfs_server}:${nfs_path}" /new_root
fi
+[ -z "${init}" ] && init="/sbin/init"
+if [ "$(stat -f -c %i /)" = "$(stat -f -c %i /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 [ ! -f "/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
+
#Special handling if udev is running
udevpid=$(/bin/pidof udevd)
if [ -n "${udevpid}" ]; then
@@ -191,5 +209,4 @@ fi
umount /proc
umount /sys
-[ -z "${init}" ] && init="/sbin/init"
exec /sbin/switch_root -c /dev/console /new_root ${init} "$@"
diff --git a/init_functions b/init_functions
index c0f10e9..72bf6ae 100644
--- a/init_functions
+++ b/init_functions
@@ -23,5 +23,7 @@ poll_device() {
}
launch_interactive_shell() {
- PS1='[ramfs \W]\$ ' /bin/sh -i
+ PS1='[ramfs \W]\$ '
+ [ "$1" = "--exec" ] && exec /bin/sh -i
+ /bin/sh -i
}