Root/target/linux/generic/base-files/init

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

Archive Download this file



interactive