#!/bin/sh mounted= runboot= prefroot= /bin/mount -t proc proc /proc /bin/echo "0x0100" > /proc/sys/kernel/real-root-dev sysconflen=`/bin/dd if=/dev/mtd1 bs=4 count=1 2>/dev/null | hexdump -n 6 -e '"%02d"'` ipaddr=`/bin/dd if=/dev/mtd1 bs=1 count=$sysconflen skip=4 2>/dev/null | grep ip_addr | sed -e s/ip_addr=//` netmask=`/bin/dd if=/dev/mtd1 bs=1 count=$sysconflen skip=4 2>/dev/null | grep netmask | sed -e s/netmask=//` gateway=`/bin/dd if=/dev/mtd1 bs=1 count=$sysconflen skip=4 2>/dev/null | grep gateway | sed -e s/gateway=//` nfsrootloc=`/bin/dd if=/dev/mtd1 bs=1 count=$sysconflen skip=4 2>/dev/null | grep nfsroot | sed -e s/nfsroot=// | cut -d, -f 1` nfsrootopts=`/bin/dd if=/dev/mtd1 bs=1 count=$sysconflen skip=4 2>/dev/null | grep nfsroot | sed -e s/nfsroot=// | cut -d, -f 2- | sed -e s/\"//g` device=/dev/`/bin/sed -n -e 's/^\(mtd[0-9]*\): .* "FIS directory"/\1/p' /proc/mtd` length=`/bin/dd if=$device bs=2 skip=2048 2>/dev/null | /bin/hexdump -n 4 -e '4/1 "%02X"' $device` # Determine desired rootfs if [ -z "$mounted" ] && /bin/mount -rt jffs2 /dev/mtdblock4 /mnt/jffs2 ; then if [ -f /mnt/jffs2/.recovery ] ; then /bin/echo "Preferred root device is /dev/ram0 (recovery)" mounted= runboot= prefroot= elif [ -f /mnt/jffs2/.sda1root ] ; then /bin/echo "Preferred root device is /dev/sda1 (disk 1)" mounted=/mnt/newroot runboot=/bin/init prefroot=sda1 elif [ -f /mnt/jffs2/.sda2root ] ; then /bin/echo "Preferred root device is /dev/sda2 (disk 1)" mounted=/mnt/newroot runboot=/bin/init prefroot=sda2 elif [ -f /mnt/jffs2/.sdb1root ] ; then /bin/echo "Preferred root device is /dev/sdb1 (disk 2)" mounted=/mnt/newroot runboot=/bin/init prefroot=sdb1 elif [ -f /mnt/jffs2/.sdb2root ] ; then /bin/echo "Preferred root device is /dev/sdb2 (disk 2)" mounted=/mnt/newroot runboot=/bin/init prefroot=sdb2 elif [ -f /mnt/jffs2/.ramdisk ] ; then /bin/echo "Preferred root device is /dev/ram1 (maintenence)" mounted=/mnt/newroot runboot=/bin/init prefroot=maintenence elif [ -f /mnt/jffs2/.nfsroot ] ; then /bin/echo "Preferred root device is through NFS" mounted=/mnt/newroot runboot=/linuxrc prefroot=nfsroot else /bin/echo "Preferred root device is jffs2" mounted=/mnt/jffs2 runboot=/linuxrc prefroot=jffs2 fi fi # perform prepatory tasks if [ -n "$prefroot" ] ; then if [ $prefroot = "sda1" -o $prefroot = "sda2" -o $prefroot = "sdb1" -o $prefroot = "sdb2" ] ; then /bin/echo "Sleeping 10sec while waiting for disk..." sleep 10 /bin/mount -rt ext3 /dev/$prefroot /mnt/newroot if [ -L /mnt/newroot/sbin/init -o -x /mnt/newroot/sbin/init -o \ -L /mnt/newroot/bin/init -o -x /mnt/newroot/bin/init ] ; then /bin/echo "Root filesystem will be mounted from /dev/$prefroot ..." else /bin/echo "Cant find valid rootfs on /dev/$prefroot, using recovery ..." mounted= runboot= fi elif [ $prefroot = "maintenence" ] ; then /bin/dd if=/dev/zero of=/dev/ram1 bs=1k count=12k 2>/dev/null /bin/mkdir /lib /bin/ln -s /mnt/jffs2/lib/* /lib /bin/mkdir /usr/bin /bin/ln -s /mnt/jffs2/usr/bin/mke2fs /usr/bin /bin/ln -s /mnt/jffs2/usr/bin/find /usr/bin /bin/ln -s /mnt/jffs2/usr/bin/cpio /usr/bin /usr/bin/mke2fs -m 0 /dev/ram1 12288 /bin/mount -t ext2 /dev/ram1 /mnt/newroot ( cd /mnt/jffs2 ; /usr/bin/find . -print0 -mount | /usr/bin/cpio -p -0 -d -m -u /mnt/newroot ) if [ -x /mnt/newroot/bin/init ] && [ -r /mnt/newroot/.unslung ] ; then /bin/cp /mnt/newroot/home/httpd/html/Management/upgrade.cgi /mnt/newroot/home/httpd/html/Management/upgrade-real.cgi /bin/echo "#!/bin/sh" > /mnt/newroot/home/httpd/html/Management/upgrade.cgi /bin/echo >> /mnt/newroot/home/httpd/html/Management/upgrade.cgi /bin/echo "/bin/mount -t ramfs none /upload -o size=8196 2>/dev/null" \ >> /mnt/newroot/home/httpd/html/Management/upgrade.cgi /bin/echo "/bin/dd if=/dev/zero of=/upload/free-ram bs=1k count=8k 2>/dev/null" \ >> /mnt/newroot/home/httpd/html/Management/upgrade.cgi /bin/echo "/bin/umount /upload 2>/dev/null" \ >> /mnt/newroot/home/httpd/html/Management/upgrade.cgi /bin/echo "exec /home/httpd/html/Management/upgrade-real.cgi" \ >> /mnt/newroot/home/httpd/html/Management/upgrade.cgi /bin/echo "Root filesystem will be mounted from /dev/ram1 (a copy of /dev/mtdblock4) ..." else /bin/echo "Cant find valid rootfs on ram1, using recovery ..." mounted= runboot= fi elif [ $prefroot = "nfsroot" ] ; then # Should the network drivers come from payload or the jffs2? if ( [ "$length" != "FFFFFFFF" ] ); then /bin/dd if=$device bs=2 skip=2056 2>/dev/null | /bin/tar zxvf - /sbin/insmod ixp400 /sbin/insmod ixp425_eth /sbin/ifconfig ixp0 up $ipaddr netmask $netmask /sbin/route add default gw $gateway fi /bin/mkdir -p /lib /bin/ln -s /mnt/jffs2/lib/* /lib /bin/mkdir -p /sbin /bin/ln -s /mnt/jffs2/sbin/portmap /sbin /sbin/ifconfig lo up 127.0.0.1 /sbin/portmap . /mnt/jffs2/.nfsroot mount -o $nfsrootopts $nfsrootloc /mnt/newroot if [ -L /mnt/newroot/sbin/init -o -x /mnt/newroot/sbin/init -o \ -L /mnt/newroot/bin/init -o -x /mnt/newroot/bin/init ] ; then /bin/echo "Root filesystem will be mounted from a NFS root ..." mounted=/mnt/newroot runboot=/linuxrc else /bin/echo "Cant find valid NFS rootfs, using recovery ..." mounted= runboot= fi else if [ -L /mnt/jffs2/sbin/init -o -x /mnt/jffs2/sbin/init -o \ -L /mnt/jffs2/bin/init -o -x /mnt/jffs2/bin/init ] ; then /bin/echo "Root filesystem will be mounted from /dev/mtdblock4 ..." mounted=/mnt/jffs2 runboot=/linuxrc else /bin/echo "Cant find valid rootfs on jffs2, using recovery ..." mounted= runboot= fi fi fi # Pivot if [ -n "$mounted" ] ; then if [ $prefroot = "nfsroot" ] ; then /bin/killall portmap fi if [ $mounted != "/mnt/jffs2" ] ; then sleep 1 /bin/umount /mnt/jffs2 fi umount /proc cd $mounted /sbin/pivot_root . initrd exec chroot . $runboot < dev/console > dev/console 2>&1 fi #if [ -z "$mounted" ] ; then # # /bin/umount /mnt/jffs2 # if [ -L /mnt/jffs2/sbin/init -o -x /mnt/jffs2/sbin/init -o \ # -L /mnt/jffs2/bin/init -o -x /mnt/jffs2/bin/init ] ; then # /bin/echo "5" > /proc/sys/kernel/panic # /bin/echo "Root filesystem will be mounted from /dev/ram0 ..." # /bin/echo "0x0100" > /proc/sys/kernel/real-root-dev # fi #fi if [ -z "$mounted" ] ; then /bin/echo "Root filesystem cannot be found - dropping into shell ..." if ( [ "$length" != "FFFFFFFF" ] ); then /bin/dd if=$device bs=2 skip=2056 2>/dev/null | /bin/tar zxvf - /sbin/insmod ixp400 /sbin/insmod ixp425_eth /sbin/ifconfig ixp0 up $ipaddr netmask $netmask /sbin/telnetd fi exec /bin/sh fi /bin/umount /proc exit 0