]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/openslug-init/openslug-init-0.10/linuxrc
OE tree imported from monotone branch org.openembedded.oz354fam083 at revision 8b12e3...
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / openslug-init / openslug-init-0.10 / 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 /.ramdisk ] ; then
10     /bin/echo "Preferred root device is /dev/ram0 (maintenence)"
11     mounted=/mnt
12     prefroot=maintenence
13 elif [ -f /.sda1root ] ; then
14     /bin/echo "Preferred root device is /dev/sda1 (disk 1)"
15     mounted=/mnt
16     prefroot=sda1
17 elif [ -f /.sda2root ] ; then
18     /bin/echo "Preferred root device is /dev/sda2 (disk 1)"
19     mounted=/mnt
20     prefroot=sda2
21 elif [ -f /.sdb1root ] ; then
22     /bin/echo "Preferred root device is /dev/sdb1 (disk 2)"
23     mounted=/mnt
24     prefroot=sdb1
25 elif [ -f /.sdb2root ] ; then
26     /bin/echo "Preferred root device is /dev/sdb2 (disk 2)"
27     mounted=/mnt
28     prefroot=sdb2
29 elif [ -f /.nfsroot ] ; then
30     /bin/echo "Preferred root device is NFS"
31     mounted=/mnt
32     prefroot=nfsroot
33 else
34     /bin/echo "Preferred root device is jffs2"
35     mounted=
36     prefroot=jffs2
37 fi
38
39
40 # Perform prepatory tasks, and determine whether the desired rootfs is viable.
41
42 /bin/mount -t proc proc /proc
43
44 if [ $prefroot = "sda1" -o $prefroot = "sda2" -o $prefroot = "sdb1" -o $prefroot = "sdb2" ] ; then
45     /bin/echo "Sleeping 10sec while waiting for disk..."
46     sleep 10
47     /bin/mount -rt ext3 /dev/$prefroot /mnt
48     if [ -L /mnt/sbin/init -o -x /mnt/sbin/init -o \
49         -L /mnt/bin/init  -o -x /mnt/bin/init ] ; then
50         /bin/echo "Root filesystem will be mounted from /dev/$prefroot ..."
51     else
52         /bin/umount /mnt
53         /bin/echo "Can't find valid rootfs on /dev/$prefroot, using jffs2 ..."
54         mounted=
55         prefroot=jffs2
56     fi
57 fi
58
59 if [ $prefroot = "maintenence" ] ; then
60     /bin/dd if=/dev/zero of=/dev/ram0 bs=1k count=12k 2>/dev/null 
61     /usr/bin/mke2fs -m 0 /dev/ram0 12288
62     /bin/mount -t ext2 /dev/ram0 /mnt
63     ( /usr/bin/find . -print0 -mount | /usr/bin/cpio -p -0 -d -m -u /mnt )
64     /bin/rm -f /mnt/linuxrc
65     /bin/cp /mnt/home/httpd/html/Management/upgrade.cgi /mnt/home/httpd/html/Management/upgrade-real.cgi
66     /bin/echo "#!/bin/sh" > /mnt/home/httpd/html/Management/upgrade.cgi
67     /bin/echo >> /mnt/home/httpd/html/Management/upgrade.cgi
68     /bin/echo "/bin/mount -t ramfs none /upload -o size=8196 2>/dev/null" \
69         >> /mnt/home/httpd/html/Management/upgrade.cgi
70     /bin/echo "/bin/dd if=/dev/zero of=/upload/free-ram bs=1k count=8k 2>/dev/null" \
71         >> /mnt/home/httpd/html/Management/upgrade.cgi
72     /bin/echo "/bin/umount /upload 2>/dev/null" \
73         >> /mnt/home/httpd/html/Management/upgrade.cgi
74     /bin/echo "exec /home/httpd/html/Management/upgrade-real.cgi" \
75         >> /mnt/home/httpd/html/Management/upgrade.cgi
76     /bin/echo "Root filesystem will be mounted from /dev/ram0 (a copy of /dev/mtdblock4) ..."
77 fi
78
79 if [ $prefroot = "nfsroot" ] ; then
80
81     sysconflen=`/bin/dd if=/dev/mtd1 bs=4 count=1 2>/dev/null | /usr/bin/hexdump -n 6 -e '"%02d"'`
82     ipaddr=`/bin/dd if=/dev/mtd1 bs=1 count=$sysconflen skip=4 2>/dev/null | grep ip_addr | sed -e s/ip_addr=//`
83     netmask=`/bin/dd if=/dev/mtd1 bs=1 count=$sysconflen skip=4 2>/dev/null | grep netmask | sed -e s/netmask=//`
84     gateway=`/bin/dd if=/dev/mtd1 bs=1 count=$sysconflen skip=4 2>/dev/null | grep gateway | sed -e s/gateway=//`
85
86     /sbin/insmod ixp400
87     /sbin/insmod ixp425_eth
88     /sbin/ifconfig ixp0 up $ipaddr netmask $netmask
89     /sbin/route add default gw $gateway
90
91     /sbin/ifconfig lo up 127.0.0.1
92
93     # The nfsrootloc and nfsrootopts vars can be overridden here.
94     . /.nfsroot
95
96     /bin/mount $nfsrootopts $nfsrootloc /mnt
97
98     if  [ -L /mnt/sbin/init -o -x /mnt/sbin/init -o \
99         -L /mnt/bin/init  -o -x /mnt/bin/init ] ; then
100         /bin/echo "Root filesystem will be mounted from an NFS root ..."
101         mounted=/mnt
102     else
103         /bin/umount /mnt
104         /bin/echo "Can't find valid NFS rootfs, using jffs2 ..."
105         mounted=
106         prefroot=jffs2
107     fi
108 fi
109
110 if [ $prefroot = "jffs2" ] ; then
111     /bin/echo "Root filesystem will be mounted from /dev/mtdblock4 ..."
112     mounted=
113 fi
114
115
116 /bin/umount /proc
117
118 # Pivot to the desired rootfs and run the initial executable.
119
120 if [ -n "$mounted" ] ; then
121
122     cd $mounted
123
124     if [ -x ./sbin/init -o -L ./sbin/init ] ; then
125         runboot=/sbin/init
126     elif [ -x ./bin/init -o -L ./bin/init ] ; then
127         runboot=/bin/init
128     else
129         runboot=/bin/sh
130     fi
131
132     /sbin/pivot_root . initrd
133
134     exec /usr/sbin/chroot . $runboot < /dev/console 1> /dev/console 2> /dev/console
135
136 else
137
138     exec /sbin/init
139
140 fi
141
142 /bin/echo "Can't chroot to $prefroot, using jffs2 ..."
143 exec /sbin/init
144
145 # Last-resort fall-back - this should never be reached.
146 /bin/sh