aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin H. Johnson <robbat2@gentoo.org>2017-06-23 14:51:16 -0700
committerRobin H. Johnson <robbat2@gentoo.org>2017-06-23 14:52:20 -0700
commit5eaf116d571a17fdc0bd14fdb6761557bc4fa763 (patch)
tree529a8e1669f34d9b2b9b5da6c3e122505f2339c0 /defaults
parentmodules_load: add qemu_fw_cfg on supported hardware. (diff)
downloadgenkernel-5eaf116d571a17fdc0bd14fdb6761557bc4fa763.tar.gz
genkernel-5eaf116d571a17fdc0bd14fdb6761557bc4fa763.tar.bz2
genkernel-5eaf116d571a17fdc0bd14fdb6761557bc4fa763.zip
linuxrc: show why switch_root might fail, and make related code more readable.
Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
Diffstat (limited to 'defaults')
-rw-r--r--defaults/initrd.scripts5
-rw-r--r--defaults/linuxrc19
2 files changed, 21 insertions, 3 deletions
diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts
index d00e1c7c..efc64211 100644
--- a/defaults/initrd.scripts
+++ b/defaults/initrd.scripts
@@ -567,6 +567,7 @@ findnfsmount() {
else
bad_msg "The DHCP Server did not send a valid root-path."
bad_msg "Please check your DHCP setup, or provide a nfsroot=<...> parameter."
+ return 1
fi
fi
@@ -590,6 +591,7 @@ findnfsmount() {
REAL_ROOT="/dev/nfs"
else
bad_msg "NFS Mounting failed. Is the path corrent ?"
+ return 1
fi
else
good_msg "Attempting to mount NFS root on ${NFSROOT} with options ${NFSOPTIONS}"
@@ -599,12 +601,15 @@ findnfsmount() {
REAL_ROOT="/dev/nfs"
else
bad_msg "NFS Mounting failed. Is the path correct ?"
+ return 1
fi
# FIXME: Need to start portmap and the other rpc daemons in
# order to remount rw.
fi
fi
+ else # IP / DHCP
+ return 1
fi
}
diff --git a/defaults/linuxrc b/defaults/linuxrc
index 66f7bd98..b227ed2c 100644
--- a/defaults/linuxrc
+++ b/defaults/linuxrc
@@ -640,6 +640,7 @@ do
# Try to mount the device as ${NEW_ROOT}
if [ "${REAL_ROOT}" = '/dev/nfs' ]; then
findnfsmount
+ mountret=$?
else
# If $REAL_ROOT is a symlink
# Resolve it like util-linux mount does
@@ -648,15 +649,17 @@ do
if [ "${REAL_ROOTFLAGS}" = '' ]; then
good_msg "Using mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE} ${REAL_ROOT} ${NEW_ROOT}"
mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE} ${REAL_ROOT} ${NEW_ROOT}
+ mountret=$?
else
good_msg "Using mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE},${REAL_ROOTFLAGS} ${REAL_ROOT} ${NEW_ROOT}"
mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE},${REAL_ROOTFLAGS} ${REAL_ROOT} ${NEW_ROOT}
+ mountret=$?
fi
fi
# If mount is successful break out of the loop
# else not a good root and start over.
- if [ "$?" = '0' ]
+ if [ "$mountret" = '0' ]
then
if [ -d ${NEW_ROOT}/dev -a -x "${NEW_ROOT}${REAL_INIT:-/sbin/init}" ] || [ "${REAL_ROOT}" = "/dev/nfs" ]
then
@@ -1037,12 +1040,22 @@ fi
rundebugshell "before entering switch_root"
# init_opts is set in the environment by the kernel when it parses the command line
-exec /sbin/switch_root -c "/dev/console" "${CHROOT}" "${REAL_INIT:-/sbin/init}" ${init_opts}
+init=${REAL_INIT:-/sbin/init}
+if ! mountpoint "${CHROOT}"; then
+ bad_msg "$CHROOT was not a mountpoint"
+elif [ ! -x ${CHROOT}/${init} ]; then
+ bad_msg "init=${init} does not exist in the rootfs!"
+elif [ $$ != 1 ]; then
+ bad_msg "PID was not 1! switch_root would fail"
+else
+ good_msg "Switching to real root: /sbin/switch_root -c /dev/console ${CHROOT} ${init} ${init_opts}"
+ exec /sbin/switch_root -c "/dev/console" "${CHROOT}" "${init}" ${init_opts}
+fi
# If we get here, something bad has happened
splash 'verbose'
-bad_msg "A fatal error has occured since ${REAL_INIT:-/sbin/init} did not"
+bad_msg "A fatal error has occured since ${init} did not"
bad_msg "boot correctly. Trying to open a shell..."
exec /bin/bash