2007-05-10 08:35:48 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# Copyright (C) 2006 OpenWrt.org
|
|
|
|
|
2007-11-16 03:11:21 +00:00
|
|
|
. /etc/diag.sh
|
2007-05-10 08:35:48 +00:00
|
|
|
export PATH=/bin:/sbin:/usr/bin:/usr/sbin
|
|
|
|
mount none /proc -t proc
|
2007-10-23 06:23:33 +00:00
|
|
|
mount none /sys -t sysfs
|
2007-11-16 03:11:21 +00:00
|
|
|
size=$(awk '/MemTotal:/ {l=5242880;mt=($2*1024);print((s=mt/2)<l)?mt-l:s}' /proc/meminfo)
|
|
|
|
mount none /tmp -t tmpfs -o size=$size,nosuid,nodev,mode=1777
|
2007-05-10 08:35:48 +00:00
|
|
|
|
|
|
|
if grep devfs /proc/filesystems > /dev/null; then
|
|
|
|
mount none /dev -t devfs
|
2007-10-23 06:23:33 +00:00
|
|
|
|
|
|
|
elif [ -x /sbin/hotplug2 ]; then
|
2007-05-10 08:35:48 +00:00
|
|
|
mount -t tmpfs tmpfs /dev -o size=512K
|
|
|
|
mknod /dev/console c 5 1
|
|
|
|
mkdir /dev/pts
|
|
|
|
mkdir /dev/shm
|
|
|
|
/sbin/hotplug2 --no-persistent --coldplug --max_children 1
|
2007-10-23 06:23:36 +00:00
|
|
|
|
|
|
|
elif [ -x /sbin/udevd ]; then
|
|
|
|
mount -n -t tmpfs -o mode=0755 udev /dev
|
|
|
|
mkdir /dev/pts
|
|
|
|
mkdir /dev/shm
|
|
|
|
|
|
|
|
if [ -e /proc/sys/kernel/hotplug ]; then
|
|
|
|
echo "" > /proc/sys/kernel/hotplug
|
|
|
|
fi
|
|
|
|
|
|
|
|
/sbin/udevd --daemon
|
|
|
|
/sbin/udevtrigger
|
|
|
|
/sbin/udevsettle
|
|
|
|
|
2007-05-10 08:35:48 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
mount none /dev/pts -t devpts
|
|
|
|
|
|
|
|
# the root mount point can come from the kernel command line
|
|
|
|
# or it can be overridden in the preinit.arch file
|
2007-11-16 03:11:21 +00:00
|
|
|
trap 'FAILSAFE=true' USR1
|
|
|
|
[ -e /etc/preinit.arch ] && . /etc/preinit.arch
|
|
|
|
set_state preinit
|
|
|
|
echo "$HOTPLUG" > /proc/sys/kernel/hotplug
|
|
|
|
eval ${FAILSAFE:+failsafe}
|
|
|
|
lock -w /tmp/.failsafe
|
2007-05-10 08:35:48 +00:00
|
|
|
|
|
|
|
# if we have no root parameter, just go to running from ramfs
|
|
|
|
[ -z $rootfs ] && {
|
|
|
|
export NOMOUNT="No Root"
|
|
|
|
exec /sbin/init
|
|
|
|
}
|
|
|
|
|
|
|
|
#if we have a failsafe boot selected, dont bother
|
|
|
|
#trying to find or wait for a root mount point
|
|
|
|
[ -z "$FAILSAFE" ] || {
|
|
|
|
exec /bin/busybox init
|
|
|
|
}
|
|
|
|
|
|
|
|
# Load the modules we have in initramfs, this should
|
|
|
|
# make the media accessible, but, it may take some time
|
|
|
|
. /etc/functions.sh
|
|
|
|
load_modules /etc/modules /etc/modules.d/*
|
|
|
|
|
|
|
|
#wait 10 seconds for the disc to show up
|
|
|
|
#usb stick typically takes 4 to 6 seconds
|
|
|
|
#till it's readable
|
|
|
|
#it's quite possible the disc never shows up
|
|
|
|
#if we netbooted this kernel
|
|
|
|
COUNTER=0
|
|
|
|
while [ $COUNTER -lt 10 ]; do
|
|
|
|
sleep 1
|
|
|
|
[ -e $rootfs ] && let COUNTER=10;
|
|
|
|
let COUNTER=COUNTER+1
|
|
|
|
done
|
|
|
|
[ -e $rootfs ] || {
|
|
|
|
export FAILSAFE="NoDisc"
|
|
|
|
exec /bin/busybox init
|
|
|
|
}
|
|
|
|
|
|
|
|
# now we'll try mount it, again with a timeout
|
|
|
|
# This will fail if the inserted stick is formatted
|
|
|
|
# in a manner we dont understand
|
|
|
|
COUNTER=0
|
|
|
|
while [ $COUNTER -lt 10 ]; do
|
|
|
|
sleep 1
|
|
|
|
mount $rootfs /mnt
|
|
|
|
[ $? -eq "0" ] && let COUNTER=100;
|
|
|
|
let COUNTER=COUNTER+1
|
|
|
|
done
|
|
|
|
[ $? -ne "0" ] && {
|
|
|
|
export FAILSAFE="MountFail"
|
|
|
|
exec /bin/busybox init
|
|
|
|
}
|
|
|
|
|
|
|
|
#It mounted, lets look for a postinit file, again, give it time
|
|
|
|
#I've seen this take 6 seconds to actually complete
|
|
|
|
COUNTER=0
|
|
|
|
while [ $COUNTER -lt 10 ]; do
|
|
|
|
sleep 1
|
|
|
|
[ -e /mnt/etc/banner ] && let COUNTER=10;
|
|
|
|
let COUNTER=COUNTER+1
|
|
|
|
done
|
|
|
|
[ -e /mnt/etc/banner ] || {
|
|
|
|
export FAILSAFE="No Openwrt FS"
|
|
|
|
exec /bin/busybox init
|
|
|
|
}
|
|
|
|
|
|
|
|
unset rootfs
|
|
|
|
|
|
|
|
mount -o move /proc /mnt/proc
|
|
|
|
mount -o move /dev /mnt/dev
|
|
|
|
mount -o move /dev/pts /mnt/dev/pts
|
|
|
|
mount -o move /tmp /mnt/tmp
|
|
|
|
mount -o move /sys /mnt/sys
|
|
|
|
mount none /tmp -t tmpfs
|
|
|
|
exec switch_root -c /dev/console /mnt /sbin/init
|