]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/nslu2-binary-only/unslung-rootfs/linuxrc
OE tree imported from monotone branch org.openembedded.oz354fam083 at revision 8b12e3...
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / nslu2-binary-only / unslung-rootfs / linuxrc
1 #!/bin/sh
2
3 # ****  DO NOT EVEN THINK OF EDITING OR REMOVING THIS FILE  ****
4 # **** UNLESS YOU REALLY KNOW *EXACTLY* WHAT YOU ARE DOING. ****
5
6
7 # Determine the desired rootfs based on user flag files.
8
9 if [ -f /.sda1root ] ; then
10     /bin/echo "Preferred root device is /dev/sda1 (disk 1)"
11     mounted=/mnt
12     prefroot=sda1
13 elif [ -f /.sda2root ] ; then
14     /bin/echo "Preferred root device is /dev/sda2 (disk 1)"
15     mounted=/mnt
16     prefroot=sda2
17 elif [ -f /.sdb1root ] ; then
18     /bin/echo "Preferred root device is /dev/sdb1 (disk 2)"
19     mounted=/mnt
20     prefroot=sdb1
21 elif [ -f /.sdb2root ] ; then
22     /bin/echo "Preferred root device is /dev/sdb2 (disk 2)"
23     mounted=/mnt
24     prefroot=sdb2
25 elif [ -f /.nfsroot ] ; then
26     /bin/echo "Preferred root device is NFS"
27     mounted=/mnt
28     prefroot=nfsroot
29 else
30     /bin/echo "Preferred root device is jffs2"
31     mounted=
32     prefroot=jffs2
33 fi
34
35
36 # Perform prepatory tasks, and determine whether the desired rootfs is viable.
37
38 /bin/mount -t proc proc /proc
39
40 if [ $prefroot = "sda1" -o $prefroot = "sda2" -o $prefroot = "sdb1" -o $prefroot = "sdb2" ] ; then
41     /bin/echo "Sleeping while waiting for disk..."
42     cnt=20
43     while [ $cnt -gt 0 ] ; do
44       echo -ne "\r$cnt "
45       sleep 1
46       [ $prefroot = "sda1" ] && [ -f /proc/hd_conn ] && cnt=0
47       [ $prefroot = "sda2" ] && [ -f /proc/hd_conn ] && cnt=0
48       [ $prefroot = "sdb1" ] && [ -f /proc/hd2_conn ] && cnt=0
49       [ $prefroot = "sdb2" ] && [ -f /proc/hd2_conn ] && cnt=0
50       cnt=`expr $cnt - 1`
51     done
52     echo
53     /bin/mount -rt ext3 /dev/$prefroot /mnt
54     if [ -L /mnt/sbin/init -o -x /mnt/sbin/init -o \
55         -L /mnt/bin/init  -o -x /mnt/bin/init ] ; then
56         /bin/echo "Root filesystem will be mounted from /dev/$prefroot ..."
57     else
58         /bin/umount /mnt
59         /bin/echo "Can't find valid rootfs on /dev/$prefroot, using jffs2 ..."
60         mounted=
61         prefroot=jffs2
62     fi
63 fi
64
65 if [ $prefroot = "nfsroot" ] ; then
66
67     sysconflen=`/bin/dd if=/dev/mtd1 bs=4 count=1 2>/dev/null | /usr/bin/hexdump -n 6 -e '"%02d"'`
68     ipaddr=`/bin/dd if=/dev/mtd1 bs=1 count=$sysconflen skip=4 2>/dev/null | grep ip_addr | sed -e s/ip_addr=//`
69     netmask=`/bin/dd if=/dev/mtd1 bs=1 count=$sysconflen skip=4 2>/dev/null | grep netmask | sed -e s/netmask=//`
70     gateway=`/bin/dd if=/dev/mtd1 bs=1 count=$sysconflen skip=4 2>/dev/null | grep gateway | sed -e s/gateway=//`
71
72     /sbin/insmod ixp400
73     /sbin/insmod ixp425_eth
74     /sbin/ifconfig ixp0 up $ipaddr netmask $netmask
75     /sbin/route add default gw $gateway
76
77     /sbin/ifconfig lo up 127.0.0.1
78
79     # The nfsrootloc and nfsrootopts vars can be overridden here.
80     . /.nfsroot
81
82     /bin/mount $nfsrootopts $nfsrootloc /mnt
83
84     if  [ -L /mnt/sbin/init -o -x /mnt/sbin/init -o \
85         -L /mnt/bin/init  -o -x /mnt/bin/init ] ; then
86         /bin/echo "Root filesystem will be mounted from an NFS root ..."
87         mounted=/mnt
88     else
89         /bin/umount /mnt
90         /bin/echo "Can't find valid NFS rootfs, using jffs2 ..."
91         mounted=
92         prefroot=jffs2
93     fi
94 fi
95
96 if [ $prefroot = "jffs2" ] ; then
97     /bin/echo "Root filesystem will be mounted from /dev/mtdblock4 ..."
98     mounted=
99 fi
100
101
102 /bin/umount /proc
103
104 # Pivot to the desired rootfs and run the initial executable.
105
106 if [ -n "$mounted" ] ; then
107
108     cd $mounted
109
110     if [ -x ./sbin/init -o -L ./sbin/init ] ; then
111         runboot=/sbin/init
112     elif [ -x ./bin/init -o -L ./bin/init ] ; then
113         runboot=/bin/init
114     else
115         runboot=/bin/sh
116     fi
117
118     /sbin/pivot_root . initrd
119
120     exec /usr/sbin/chroot . $runboot < /dev/console 1> /dev/console 2> /dev/console
121
122 else
123
124     exec /bin/init
125
126 fi
127
128 /bin/echo "Can't chroot to $prefroot, using jffs2 ..."
129 exec /bin/init
130
131 # Last-resort fall-back - this should never be reached.
132 /bin/sh