Flesh out early userspace for initramfs to allow booting from media
[openwrt.git] / target / linux / generic-2.6 / files / init
1 #!/bin/sh
2 # Copyright (C) 2006 OpenWrt.org
3
4 export PATH=/bin:/sbin:/usr/bin:/usr/sbin
5 mount none /proc -t proc
6 mount none /dev -t devfs
7
8 # the root mount point can come from the kernel command line
9 # or it can be overridden in the preinit.arch file
10 [ -f /etc/preinit.arch ] && . /etc/preinit.arch
11
12 # if we have no root parameter, just go to running from ramfs
13 [ -z $rootfs ] && {
14 export NOMOUNT="No Root"
15 exec /sbin/init
16 }
17
18 #if we have a failsafe boot selected, dont bother
19 #trying to find or wait for a root mount point
20 [ -z "$FAILSAFE" ] || {
21 exec /bin/busybox init
22 }
23
24 # Load the modules we have in initramfs, this should
25 # make the media accessible, but, it may take some time
26 . /etc/functions.sh
27 load_modules /etc/modules /etc/modules.d/*
28
29 #wait 10 seconds for the disc to show up
30 #usb stick typically takes 4 to 6 seconds
31 #till it's readable
32 #it's quite possible the disc never shows up
33 #if we netbooted this kernel
34 COUNTER=0
35 while [ $COUNTER -lt 10 ]; do
36 sleep 1
37 [ -e $rootfs ] && let COUNTER=10;
38 let COUNTER=COUNTER+1
39 done
40 [ -e $rootfs ] || {
41 export FAILSAFE="NoDisc"
42 exec /bin/busybox init
43 }
44
45 # now we'll try mount it, again with a timeout
46 # This will fail if the inserted stick is formatted
47 # in a manner we dont understand
48 COUNTER=0
49 while [ $COUNTER -lt 10 ]; do
50 sleep 1
51 mount $rootfs /mnt
52 [ $? -eq "0" ] && let COUNTER=100;
53 let COUNTER=COUNTER+1
54 done
55 [ $? -ne "0" ] && {
56 export FAILSAFE="MountFail"
57 exec /bin/busybox init
58 }
59
60 #It mounted, lets look for a postinit file, again, give it time
61 #I've seen this take 6 seconds to actually complete
62 COUNTER=0
63 while [ $COUNTER -lt 10 ]; do
64 sleep 1
65 [ -e /mnt/postinit ] && let COUNTER=10;
66 let COUNTER=COUNTER+1
67 done
68 [ -e /mnt/postinit ] || {
69 export FAILSAFE="No postinit"
70 exec /bin/busybox init
71 }
72
73 unset rootfs
74
75 mount -o move /proc /mnt/proc
76 mount -o move /dev /mnt/dev
77 mount -o move /tmp /mnt/tmp
78 mount -o move /sys /mnt/sys
79
80 exec switch_root -c /dev/console /mnt /postinit
This page took 0.060216 seconds and 5 git commands to generate.