165 lines
4.0 KiB
Bash
Executable File
165 lines
4.0 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
# initramfs /init (busybox ash)
|
|
|
|
### CHANGELOG ###############################################################
|
|
#
|
|
# 2007.04.24 - remove extra status message for hidden CDROM unmount message
|
|
# 2007.04.22 - hide CDROM unmount message
|
|
# 2007.03.01 - initial creation
|
|
#
|
|
#############################################################################
|
|
|
|
BOLD="\033[1m"
|
|
NORM="\033[0m"
|
|
RED="\033[31m"
|
|
GREEN="\033[32m"
|
|
YELLOW="\033[33m"
|
|
BLUE="\033[34m"
|
|
OK="${BOLD}${GREEN}OK${NORM}"
|
|
FAILED="${BOLD}${RED}FAILED${NORM}"
|
|
DONE="${BOLD}${GREEN}DONE${NORM}"
|
|
|
|
checkReturn() {
|
|
if [ $? -ne 0 ]
|
|
then
|
|
echo -e $FAILED
|
|
# could spawn a shell here for the user to fix things
|
|
else
|
|
echo -e $OK
|
|
fi
|
|
}
|
|
|
|
echoDone() {
|
|
echo -e $DONE
|
|
}
|
|
|
|
echo ""
|
|
echo -e "${BOLD}CRUX 2.4 - ${BLUE}http://crux.nu/${NORM}"
|
|
echo ""
|
|
|
|
exec >/dev/console </dev/console 2>&1
|
|
|
|
echo -e -n " ${BOLD}${BLUE}*${NORM} Mounting "
|
|
echo -e -n "${BOLD}${GREEN}/proc${NORM}"
|
|
mount -t proc proc /proc
|
|
|
|
PRINTK="`cat /proc/sys/kernel/printk`"
|
|
echo "0" > /proc/sys/kernel/printk
|
|
|
|
echo -e ", ${BOLD}${GREEN}/sys${NORM}."
|
|
mount -t sysfs sysfs /sys
|
|
|
|
echo -e -n " ${BOLD}${BLUE}*${NORM} Populating /dev via mdev... "
|
|
mdev -s
|
|
checkReturn
|
|
echo -e -n " ${BOLD}${BLUE}*${NORM} Registering mdev as hotplug agent... "
|
|
echo "/bin/mdev" > /proc/sys/kernel/hotplug
|
|
checkReturn
|
|
|
|
echo -e -n " ${BOLD}${BLUE}*${NORM} Creating and mounting tmpfs... "
|
|
mkdir /.tmpfs
|
|
mount -t tmpfs tmpfs /.tmpfs
|
|
checkReturn
|
|
|
|
if [ -d /lib/modules ]
|
|
then
|
|
echo -e -n " ${BOLD}${BLUE}*${NORM} Loading modules... "
|
|
# usb
|
|
for mod in ehci-hcd ohci-hcd uhci-hcd sl811-hcd usb-storage usbhid
|
|
do
|
|
modprobe $mod
|
|
done
|
|
|
|
# firewire
|
|
for mod in ieee1394 ohci1394 sbp2
|
|
do
|
|
modprobe $mod
|
|
done
|
|
|
|
# sata
|
|
for mod in ata_piix sata_promise sata_sil sata_svw sata_via sata_nv \
|
|
sata_sx4 sata_sis sata_uli sata_qstor ahci
|
|
do
|
|
modprobe $mod
|
|
done
|
|
|
|
echoDone
|
|
else
|
|
echo -e " ${BOLD}${YELLOW}*${NORM} No modules were found in the initial RAM filesystem."
|
|
fi
|
|
|
|
echo -e " ${BOLD}${BLUE}*${NORM} Waiting for devices to settle..."
|
|
sleep 10 # make this number configurable
|
|
|
|
echo -e " ${BOLD}${BLUE}*${NORM} Searching for the CRUX CD..."
|
|
mkdir /.tmpfs/.cdrom
|
|
CRUXCD=""
|
|
CDROM_DEVICES="`grep 'drive name:' /proc/sys/dev/cdrom/info | cut -d: -f2`"
|
|
for DEV in $CDROM_DEVICES
|
|
do
|
|
DEV="/dev/$DEV"
|
|
mount -r -t iso9660 $DEV /.tmpfs/.cdrom
|
|
if [ $? -eq 0 ]
|
|
then
|
|
echo -e -n " ${BOLD}${GREEN}*${NORM} Found media on $DEV"
|
|
if [ -e /.tmpfs/.cdrom/crux-cd ]
|
|
then
|
|
echo ", CRUX CD."
|
|
CRUXCD=$DEV
|
|
ln -s $DEV /dev/cdrom
|
|
break
|
|
else
|
|
echo ", but it's not the CRUX CD."
|
|
umount /.tmpfs/.cdrom
|
|
fi
|
|
else
|
|
echo -e " ${BOLD}${YELLOW}*${NORM} No media found on $DEV."
|
|
fi
|
|
done
|
|
|
|
echo -e -n " ${BOLD}${BLUE}*${NORM} Mounting squashfs filesystem... "
|
|
mkdir /.tmpfs/.squashfs
|
|
mount -r -t squashfs -o loop /.tmpfs/.cdrom/crux.squashfs /.tmpfs/.squashfs
|
|
checkReturn
|
|
|
|
echo -e " ${BOLD}${BLUE}*${NORM} Populating root filesystem..."
|
|
mkdir -p /newroot
|
|
echo -e -n " ${BOLD}${BLUE}*${NORM} Mounting new root filesystem... "
|
|
mount -t tmpfs tmpfs /newroot
|
|
checkReturn
|
|
echo -e -n " ${BOLD}${BLUE}*${NORM} Copying files from squashfs... "
|
|
cp -af /.tmpfs/.squashfs/* /newroot/
|
|
checkReturn
|
|
echo -e -n " ${BOLD}${BLUE}*${NORM} Copying devices from rootfs... "
|
|
cp -af /dev/* /newroot/dev/
|
|
checkReturn
|
|
mkdir -p /newroot/dev/pts /newroot/cdrom
|
|
|
|
echo -e -n " ${BOLD}${BLUE}*${NORM} Unmounting squashfs filesystem... "
|
|
umount /.tmpfs/.squashfs
|
|
checkReturn
|
|
rmdir /.tmpfs/.squashfs
|
|
|
|
# even though the CDROM gets unmounted here, it gets remounted after
|
|
# the new init starts, so the message might be confusing...
|
|
#echo -e -n " ${BOLD}${BLUE}*${NORM} Unmounting CDROM... "
|
|
umount /.tmpfs/.cdrom
|
|
#checkReturn
|
|
rmdir /.tmpfs/.cdrom
|
|
|
|
echo -e -n " ${BOLD}${BLUE}*${NORM} Unmounting tmpfs... "
|
|
umount /.tmpfs
|
|
checkReturn
|
|
rmdir /.tmpfs
|
|
|
|
echo -e " ${BOLD}${BLUE}*${NORM} Switching root.\n"
|
|
echo "$PRINTK" > /proc/sys/kernel/printk
|
|
echo > /proc/sys/kernel/hotplug
|
|
umount /sys
|
|
umount /proc
|
|
exec /bin/switch_root /newroot /sbin/init
|
|
|
|
echo "Something's broken, here's a shell."
|
|
exec /bin/sh
|