Add udev initilisation
[openwrt-10.03/.git] / target / linux / generic-2.6 / base-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 /sys -t sysfs
7
8 if grep devfs /proc/filesystems > /dev/null; then
9         mount none /dev -t devfs
10
11 elif [ -x /sbin/hotplug2 ]; then
12         mount -t tmpfs tmpfs /dev -o size=512K
13         mknod /dev/console c 5 1
14         mkdir /dev/pts
15         mkdir /dev/shm
16         /sbin/hotplug2 --no-persistent --coldplug --max_children 1
17
18 elif [ -x /sbin/udevd ]; then
19         mount -n -t tmpfs -o mode=0755 udev /dev
20         mkdir /dev/pts
21         mkdir /dev/shm
22
23         if [ -e /proc/sys/kernel/hotplug ]; then
24                 echo "" > /proc/sys/kernel/hotplug
25         fi
26
27         /sbin/udevd --daemon
28         /sbin/udevtrigger
29         /sbin/udevsettle
30
31 fi
32
33 mount none /dev/pts -t devpts
34
35 # the root mount point can come from the kernel command line
36 # or it can be overridden in the preinit.arch file
37 [ -f /etc/preinit.arch ] && . /etc/preinit.arch
38
39 # if we have no root parameter, just go to running from ramfs
40 [ -z $rootfs ] && {
41   export NOMOUNT="No Root"
42   exec /sbin/init
43 }
44
45 #if we have a failsafe boot selected, dont bother
46 #trying to find or wait for a root mount point
47 [ -z "$FAILSAFE" ] || {
48   exec /bin/busybox init
49 }
50
51 # Load the modules we have in initramfs, this should
52 # make the media accessible, but, it may take some time
53 . /etc/functions.sh
54 load_modules /etc/modules /etc/modules.d/*
55
56 #wait 10 seconds for the disc to show up
57 #usb stick typically takes 4 to 6 seconds
58 #till it's readable
59 #it's quite possible the disc never shows up
60 #if we netbooted this kernel
61 COUNTER=0
62 while [ $COUNTER -lt 10 ]; do
63   sleep 1
64   [ -e $rootfs ] && let COUNTER=10;
65   let COUNTER=COUNTER+1
66 done
67 [ -e $rootfs ] || {
68   export FAILSAFE="NoDisc"
69   exec /bin/busybox init
70 }
71
72 # now we'll try mount it, again with a timeout
73 # This will fail if the inserted stick is formatted
74 # in a manner we dont understand
75 COUNTER=0
76 while [ $COUNTER -lt 10 ]; do
77   sleep 1
78   mount $rootfs /mnt
79   [ $? -eq "0" ] && let COUNTER=100;
80   let COUNTER=COUNTER+1
81 done
82 [ $? -ne "0" ] && {
83   export FAILSAFE="MountFail"
84   exec /bin/busybox init
85 }
86
87 #It mounted, lets look for a postinit file, again, give it time
88 #I've seen this take 6 seconds to actually complete
89 COUNTER=0
90 while [ $COUNTER -lt 10 ]; do
91   sleep 1
92   [ -e /mnt/etc/banner ] && let COUNTER=10;
93   let COUNTER=COUNTER+1
94 done
95 [ -e /mnt/etc/banner ] || {
96   export FAILSAFE="No Openwrt FS"
97   exec /bin/busybox init
98 }
99
100 unset rootfs
101
102 mount -o move /proc /mnt/proc
103 mount -o move /dev /mnt/dev
104 mount -o move /dev/pts /mnt/dev/pts
105 mount -o move /tmp /mnt/tmp
106 mount -o move /sys /mnt/sys
107 mount none /tmp -t tmpfs
108 exec switch_root -c /dev/console /mnt /sbin/init