1500779280b614ff6104d8d0f054385b6b7317fd
[openembedded.git] / recipes / nslu2-binary-only / unslung-rootfs / linuxrc
1 #!/bin/sh
2
3 NC_SLUGIP="192.168.1.77"
4 NC_TARGIP="192.168.1.100"
5
6 if ( [ -f "/.nc" ] ) ; then
7   if ( [ -z "$RERUN" ] ) ; then
8     /bin/echo " DEBUG: Starting network console from flash ..."
9     . /.nc
10     /bin/echo "Insmod ixp400"
11     /sbin/insmod ixp400.o
12     /bin/echo "Insmod ixp425"
13     /sbin/insmod ixp425_eth.o
14     /sbin/ifconfig ixp0 $NC_SLUGIP
15     /bin/echo "Insmod netconsole"
16     /sbin/insmod netconsole.o target_ipaddr=$NC_TARGIP
17     /bin/echo "Redirecting output via nc and restarting /linuxrc ..."
18     export RERUN=1
19     exec /linuxrc 2>&1 | tee /dev/console | /usr/bin/nc $NC_TARGIP 6666
20   fi
21 fi
22
23 # ****  DO NOT EVEN THINK OF EDITING OR REMOVING THIS FILE  ****
24 # **** UNLESS YOU REALLY KNOW *EXACTLY* WHAT YOU ARE DOING. ****
25
26
27 # Perform prepatory tasks, and determine whether an alternate rootfs is viable.
28
29 /bin/mount -t proc proc /proc
30
31 /bin/echo "1" > /proc/sys/kernel/panic
32
33 if ( ! [ -f /.nodisk ] ) ; then
34
35   /bin/echo "Sleeping while waiting for disk..."
36   cnt=20
37   while [ $cnt -gt 0 ] ; do
38     /bin/echo -ne "\r$cnt "
39     /bin/sleep 1
40     [ -e /.sda1root -a -f /proc/hdd_sda ] && cnt=0
41     [ -e /.sdb1root -a -f /proc/hdd_sdb ] && cnt=0
42     cnt=`expr $cnt - 1`
43   done
44   /bin/echo
45
46   if [ -e /.fastdisk ] ; then
47     /bin/sleep 5
48   else
49     /bin/sleep 15
50   fi
51
52   mounted=
53
54   for prefroot in sda1 sdb1 ; do
55     if [ -z "$mounted" -a -e /.${prefroot}root ] ; then
56       if /bin/mount -rt ext3 /dev/$prefroot /mnt ; then
57         if [ -e /mnt/.${prefroot}root -a -x /mnt/bin/init ] ; then
58           /bin/echo "Root filesystem will be mounted from /dev/$prefroot ..."
59           mounted=/mnt
60         else
61           /bin/umount /mnt
62           /bin/echo "Can't find valid rootfs on /dev/$prefroot ..."
63         fi
64       fi
65     fi
66   done
67
68   if [ -z "$mounted" ] ; then
69     /bin/echo "Can't find valid rootfs, using ramdisk ..."
70     mounted=
71   fi
72
73   /bin/umount /proc
74
75   # Pivot to the desired rootfs and run the initial executable.
76
77   if [ -n "$mounted" ] ; then
78
79       cd $mounted
80
81       /bin/echo "Pivoting to external rootfs ..."
82       /sbin/pivot_root . initrd
83
84       if ( [ -z "$RERUN" ] ) ; then
85         exec /usr/sbin/chroot . /bin/init < /dev/console 1> /dev/console 2> /dev/console
86       else
87         exec /usr/sbin/chroot . /bin/init
88       fi
89   else
90
91       exec /bin/init
92
93   fi
94
95   /bin/echo "Can't pivot to external rootfs, using ramdisk ..."
96
97 else
98   /bin/echo "Forced boot to internal flash ..."
99   /bin/echo "(One-time only, clearing forced boot flag file.)"
100   /bin/rm -f /.nodisk
101 fi
102
103 exec /bin/init
104
105 # Last-resort fall-back - this should never be reached.
106 /bin/sh