From 93bf318e5114233f3cacc4575ab2e58d60e785c7 Mon Sep 17 00:00:00 2001 From: Brad House Date: Sat, 14 Feb 2004 16:21:59 +0000 Subject: [PATCH] initrd updates for correctness, squashfs, and gcloop git-svn-id: svn+ssh://svn.gentoo.org/var/svnroot/genkernel/trunk@73 67a159dc-881f-0410-a524-ba9dfbe2cb84 --- generic/linuxrc | 84 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 61 insertions(+), 23 deletions(-) diff --git a/generic/linuxrc b/generic/linuxrc index 6027bdc..0cf93c5 100644 --- a/generic/linuxrc +++ b/generic/linuxrc @@ -79,7 +79,7 @@ then mount -t tmpfs tmpfs /newroot mkdir /newroot/dev /newroot/mnt /newroot/mnt/cdrom /newroot/mnt/livecd /newroot/tmp /newroot/tmp/.initrd /newroot/mnt/gentoo [ ! -e /newroot/dev/.devfsd ] && mount -t devfs devfs /newroot/dev - devfsd /newroot/dev + devfsd /newroot/dev -np sleep 1 findcdmount /newroot/dev/cdroms/* @@ -96,7 +96,7 @@ then exec /bin/ash # Undo stuff - kill_devfsd + # kill_devfsd # We run devfsd with -np now sleep 1 umount /newroot/dev/ sleep 1 @@ -112,7 +112,7 @@ fi if [ "${CDROOT}" -eq "0" -a "${USE_DEVFS_NORMAL}" -eq "1" ] then [ ! -e /dev/.devfsd ] && mount -t devfs devfs /dev - devfsd /dev + devfsd /dev -np fi echo "STEP 4: Determining root device" @@ -194,6 +194,12 @@ then elif [ "${LOOP}" = "/zisofs" ] then LOOPTYPE="zisofs" + elif [ "${LOOP}" = "/livecd.squashfs" ] + then + LOOPTYPE="squashfs" + elif [ "${LOOP}" = "/livecd.gcloop" ] + then + LOOPTYPE="gcloop" else LOOPTYPE="noloop" fi @@ -216,6 +222,33 @@ then fi FS_LOCATION="mnt/livecd" umount /dev + elif [ "${LOOPTYPE}" = "squashfs" ] + then + check_loop + mount -o bind /newroot/dev /dev + echo "STEP 5a1: mounting squashfs filesystem" + mount -t squashfs -o loop,ro /newroot/mnt/cdrom/${LOOP} /newroot/mnt/livecd + if [ "$?" != "0" ] + then + echo "FAILED TO MOUNT LOOP FILESYSTEM, barfing out to shell" + /bin/ash + fi + FS_LOCATION="mnt/livecd" + umount /dev + elif [ "${LOOPTYPE}" = "gcloop" ] + then + check_loop + mount -o bind /newroot/dev /dev + echo "STEP 5a1: mounting gcloop (ext2) filesystem" + echo " " | losetup -e ucl-0 /newroot/dev/loop0 /newroot/mnt/cdrom/${LOOP} + if [ "$?" != "0" ] + then + echo "FAILED TO losetup THE LOOP DEVICE" + /bin/ash + fi + mount -t ext2 -o ro /newroot/dev/loop0 /newroot/mnt/livecd + FS_LOCATION="mnt/livecd" + umount /dev elif [ "${LOOPTYPE}" = "zisofs" ] then check_loop @@ -233,37 +266,29 @@ then mkdir initrd proc tmp sys chmod 1777 tmp (cd /newroot/${FS_LOCATION}; cp -a ${ROOT_TREES} /newroot) - - # Unmount the -o bind /dev and kill devfsd -# umount /dev - kill_devfsd else echo "STEP 5b: setting up stuff for pivot_root" mkdir -p /newroot/tmp/.initrd fi +echo "STEP 5c: redirect console" +console=/newroot/dev/console +exec < $console > $console 2>&1 || echo "CONSOLE REDIRECTION FAILED, /dev ON ROOT DOES NOT CONTAIN console !!!" + echo "STEP 6: pivot_root and exec/chroot real init" cd /newroot pivot_root . tmp/.initrd -# We cannot use if [ this = that ] after a pivot_root as -# an old version of coreutils in real_root does not support -# that style, noted by Weeve -# Well, changed it back to using [ ] for 3.0.1_beta10 too many -# people reporting with newer binutils that using 'test' does -# not work for some reason - if [ "${USE_DEVFS_NORMAL}" -eq "1" -a "${CDROOT}" -eq "0" ] then # must mount a new devfs before we can # umount the old one for some reason mount -t proc proc /proc mount -t devfs devfs /dev - kill_devfsd - umount /tmp/.initrd/proc - umount /tmp/.initrd/dev + umount /tmp/.initrd/proc || echo "COULD NOT UMOUNT tmp/.initrd/proc !!!" + umount /tmp/.initrd/dev || echo "COULD NOT UMOUNT tmp/.initrd/dev !!!" # Uhh, initrd is wasting memory ... let's # kill the sucker here and now! @@ -281,16 +306,29 @@ then # also umount proc echo "STEP 6a: clean up mounts" sleep 1 - umount /tmp/.initrd/dev > /dev/null 2>&1 + umount /tmp/.initrd/dev || echo "COULD NOT UMOUNT tmp/.initrd/dev !!!" sleep 1 - umount /tmp/.initrd/proc > /dev/null 2>&1 + umount /tmp/.initrd/proc || echo "COULD NOT UMOUNT tmp/.initrd/proc !!!" sleep 1 fi -# why chroot ?? /usr/src/linux/Documentation/initrd.txt -# says to, but I see no reason to do this .... very odd... +# /usr/src/linux/Documentation/initrd.txt # here's the line it says we should do: # exec chroot . /sbin/init /dev/console 2>&1 -# not gonna though .... -exec chroot . /sbin/init ${CMDLINE} < /dev/console > /dev/console 2>&1 +exec chroot . /bin/sh <<- EOF + echo "UMOUNTING /tmp/.initrd" + umount /tmp/.initrd || echo "UMOUNT of /tmp/.initrd FAILED!!!" && /sbin/blockdev --flushbufs /dev/ram0 + echo "INIT: starting /sbin/init ${CMDLINE}" + exec /sbin/init ${CMDLINE} +EOF + +# exec chroot . /sbin/init ${CMDLINE} < /dev/console > /dev/console 2>&1 +echo "IF YOU ARE SEEING THIS MESSAGE, A FATAL ERROR HAS OCCURRED" +echo "MOST LIKELY /sbin/init DOES NOT EXIST, ATTEMPTING TO DROP" +echo "YOU TO A SHELL" + +exec /bin/bash +exec /bin/sh +exec /bin/ash +exec sh -- 2.26.2