From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 04696139694 for ; Fri, 23 Jun 2017 21:53:44 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 3B30523402A; Fri, 23 Jun 2017 21:53:43 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 09A6223402A for ; Fri, 23 Jun 2017 21:53:42 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id A52FA3419DE for ; Fri, 23 Jun 2017 21:53:41 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 14FF47480 for ; Fri, 23 Jun 2017 21:53:40 +0000 (UTC) From: "Robin H. Johnson" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Robin H. Johnson" Message-ID: <1498254740.5eaf116d571a17fdc0bd14fdb6761557bc4fa763.robbat2@gentoo> Subject: [gentoo-commits] proj/genkernel:master commit in: defaults/ X-VCS-Repository: proj/genkernel X-VCS-Files: defaults/initrd.scripts defaults/linuxrc X-VCS-Directories: defaults/ X-VCS-Committer: robbat2 X-VCS-Committer-Name: Robin H. Johnson X-VCS-Revision: 5eaf116d571a17fdc0bd14fdb6761557bc4fa763 X-VCS-Branch: master Date: Fri, 23 Jun 2017 21:53:40 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 6bb4e595-371c-4ab5-a70e-6990ff0e4545 X-Archives-Hash: f9f07e1dedaa475babdf04c00b04e712 commit: 5eaf116d571a17fdc0bd14fdb6761557bc4fa763 Author: Robin H. Johnson gentoo org> AuthorDate: Fri Jun 23 21:51:16 2017 +0000 Commit: Robin H. Johnson gentoo org> CommitDate: Fri Jun 23 21:52:20 2017 +0000 URL: https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=5eaf116d linuxrc: show why switch_root might fail, and make related code more readable. Signed-off-by: Robin H. Johnson gentoo.org> defaults/initrd.scripts | 5 +++++ defaults/linuxrc | 19 ++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts index d00e1c7..efc6421 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 66f7bd9..b227ed2 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