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

Archive Download this file



interactive