You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
199 lines
4.1 KiB
199 lines
4.1 KiB
#!/bin/sh
|
|
# Daniel Robbins <drobbins@gentoo.org>
|
|
# Copyright 2003 Gentoo Technologies, Inc.
|
|
# Distributed under the GPL
|
|
|
|
. /etc/initrd.defaults
|
|
. /etc/initrd.scripts
|
|
|
|
USE_DEVFS_NORMAL=1
|
|
|
|
mount -o remount,rw /
|
|
mount /proc
|
|
|
|
[ -n "$QUIET" ] && echo "0" > /proc/sys/kernel/printk
|
|
|
|
echo "${GOOD} Gentoo initrd startup..."
|
|
echo "STEP 1: Command-line parsing"
|
|
CMDLINE=`cat /proc/cmdline`
|
|
# Scan CMDLINE for any specified real_root= or cdroot arguments
|
|
for x in ${CMDLINE}
|
|
do
|
|
case "${x}" in
|
|
real_root\=*)
|
|
REAL_ROOT=`parse_opt "${x}"`
|
|
;;
|
|
cdroot)
|
|
CDROOT=1
|
|
REAL_ROOT=""
|
|
;;
|
|
devfs)
|
|
USE_DEVFS_NORMAL=1
|
|
;;
|
|
nodevfs)
|
|
USE_DEVFS_NORMAL=0
|
|
;;
|
|
*)
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# Scan CMDLINE for any "doscsi" or "noscsi"-type arguments
|
|
for x in $HWOPTS
|
|
do
|
|
for y in $CMDLINE
|
|
do
|
|
if [ "$y" = "do${x}" ]
|
|
then
|
|
MY_HWOPTS="MY_HWOPTS $x"
|
|
elif [ "$y" = "no${x}" ]
|
|
then
|
|
MY_HWOPTS="`echo ${MY_HWOPTS} | sed -e 's/${x}//g' -`"
|
|
fi
|
|
done
|
|
done
|
|
|
|
echo "STEP 2: Module loading"
|
|
|
|
# Load appropriate kernel modules
|
|
for x in $MY_HWOPTS
|
|
do
|
|
modules_scan $x
|
|
done
|
|
|
|
echo "STEP 3: Mounting necessary filesystems per boot options"
|
|
|
|
mkdir /newroot
|
|
if [ "${CDROOT}" -eq "1" ]
|
|
then
|
|
mount -t tmpfs tmpfs /newroot
|
|
mkdir /newroot/dev /newroot/mnt /newroot/mnt/cdrom /newroot/mnt/.init.d /newroot/mnt/gentoo
|
|
[ ! -e /newroot/dev/.devfsd ] && mount -t devfs devfs /newroot/dev
|
|
devfsd /newroot/dev
|
|
findcdmount /newroot/dev/cdroms/*
|
|
if [ "${REAL_ROOT}" = "" ]
|
|
then
|
|
kill_devfsd
|
|
umount /newroot/dev/
|
|
umount /newroot
|
|
# shouldn't be anything in here b/c it was on tmpfs
|
|
rm -rf /newroot/*
|
|
CDROOT=0
|
|
echo "Could not find CD to boot, gonna need something else"
|
|
fi
|
|
fi
|
|
|
|
# Don't do else b/c we set CDROOT=0 if it fails to detect
|
|
if [ "${CDROOT}" -eq "0" -a "${USE_DEVFS_NORMAL}" -eq "1" ]
|
|
then
|
|
[ ! -e /dev/.devfsd ] && mount -t devfs devfs /dev
|
|
devfsd /dev
|
|
fi
|
|
|
|
echo "STEP 4: Determining root device"
|
|
|
|
while true
|
|
do
|
|
while [ "${got_good_root}" != "1" ]
|
|
do
|
|
|
|
if [ "${REAL_ROOT}" = "shell" ]
|
|
then
|
|
/bin/ash
|
|
|
|
#set REAL_ROOT to "" so we get a prompt for the real root after the shell exits.
|
|
REAL_ROOT=""
|
|
got_good_root=0
|
|
continue
|
|
elif [ "${REAL_ROOT}" = "" ]
|
|
then
|
|
#no REAL_ROOT determined/specified. Prompt user for root block device.
|
|
echo "Root block device unspecified or not detected."
|
|
echo "Please specify a device to boot, or \"shell\" for a shell."
|
|
echo -n ": "
|
|
read REAL_ROOT
|
|
got_good_root=0
|
|
elif [ -b "${REAL_ROOT}" ]
|
|
then
|
|
got_good_root=1
|
|
else
|
|
REAL_ROOT=""
|
|
got_good_root=0
|
|
fi
|
|
done
|
|
|
|
|
|
if [ "${CDROOT}" -eq "1" -a "${got_good_root}" = "1" ]
|
|
then
|
|
break
|
|
else
|
|
echo "STEP 4a: Mounting root"
|
|
|
|
mount -o rw ${REAL_ROOT} /newroot
|
|
if [ "$?" = "0" ]
|
|
then
|
|
break
|
|
else
|
|
echo "Could not mount specified ROOT, try again"
|
|
got_good_root=0
|
|
REAL_ROOT=""
|
|
fi
|
|
fi
|
|
done
|
|
|
|
[ -n "$QUIET" ] && echo "6" > /proc/sys/kernel/printk
|
|
echo "STEP 5: Finishing up"
|
|
|
|
if [ "${CDROOT}" = "1" ]
|
|
then
|
|
echo "STEP 5a: filling tmpfs filesystem"
|
|
cd /newroot
|
|
for x in ${ROOT_LINKS}
|
|
do
|
|
ln -s "mnt/cdrom/${x}" "${x}"
|
|
done
|
|
mkdir initrd proc tmp sys
|
|
chmod 1777 tmp
|
|
(cd /newroot/mnt/cdrom; cp -a ${ROOT_TREES} /newroot)
|
|
kill_devfsd
|
|
else
|
|
echo "STEP 5b: setting up stuff for pivot_root"
|
|
mkdir -p /newroot/tmp/.initrd
|
|
fi
|
|
|
|
echo "STEP 6: pivot_root and exec/chroot real init"
|
|
|
|
|
|
cd /newroot
|
|
pivot_root . tmp/.initrd
|
|
|
|
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
|
|
|
|
# Uhh, initrd is wasting memory ... let's
|
|
# kill the sucker here and now!
|
|
# umount tmp/.initrd
|
|
# blockdev --flushbufs /dev/ram0
|
|
|
|
# at this point it lets us umount the new
|
|
# devfs, don't know why, just does, stop
|
|
# asking questions!
|
|
umount /dev
|
|
umount /proc
|
|
fi
|
|
|
|
# why chroot ?? /usr/src/linux/Documentation/initrd.txt
|
|
# says to, but I see no reason to do this .... very odd...
|
|
# here's the line it says we should do:
|
|
# exec chroot . /sbin/init </dev/console >/dev/console 2>&1
|
|
# not gonna though ....
|
|
exec /sbin/init
|
|
|