diff options
author | Rod Whitby <rod@whitby.id.au> | 2005-04-30 12:13:52 +0000 |
---|---|---|
committer | Rod Whitby <rod@whitby.id.au> | 2005-04-30 12:13:52 +0000 |
commit | f5ff746cf5e7e085d28f0abc898be08862c4c5e7 (patch) | |
tree | efe6e40239c7ff7b5e6baea21864eedec756f867 /packages/nslu2-binary-only/unslung-rootfs-2.3r25 | |
parent | e0d553eec5f1cbbfa6994ee28b89e1bc9a667b29 (diff) |
Second cut at the new Unslung linuxrc
BKrev: 42737680rKmyyJF2BCRA_qw23u3waQ
Diffstat (limited to 'packages/nslu2-binary-only/unslung-rootfs-2.3r25')
-rw-r--r-- | packages/nslu2-binary-only/unslung-rootfs-2.3r25/linuxrc | 221 |
1 files changed, 102 insertions, 119 deletions
diff --git a/packages/nslu2-binary-only/unslung-rootfs-2.3r25/linuxrc b/packages/nslu2-binary-only/unslung-rootfs-2.3r25/linuxrc index d47ae79c01..bdf840125d 100644 --- a/packages/nslu2-binary-only/unslung-rootfs-2.3r25/linuxrc +++ b/packages/nslu2-binary-only/unslung-rootfs-2.3r25/linuxrc @@ -1,151 +1,132 @@ #!/bin/sh +# **** DO NOT EVEN THINK OF EDITING OR REMOVING THIS FILE **** +# **** UNLESS YOU REALLY KNOW *EXACTLY* WHAT YOU ARE DOING. **** + + +# Determine the desired rootfs based on user flag files. + mounted= prefroot= -runboot= -/bin/mount -t proc proc /proc +if [ -f /.ramdisk ] ; then + /bin/echo "Preferred root device is /dev/ram0 (maintenence)" + mounted=/mnt/newroot + prefroot=maintenence +elif [ -f /.sda1root ] ; then + /bin/echo "Preferred root device is /dev/sda1 (disk 1)" + mounted=/mnt/newroot + prefroot=sda1 +elif [ -f /.sda2root ] ; then + /bin/echo "Preferred root device is /dev/sda2 (disk 1)" + mounted=/mnt/newroot + prefroot=sda2 +elif [ -f /.sdb1root ] ; then + /bin/echo "Preferred root device is /dev/sdb1 (disk 2)" + mounted=/mnt/newroot + prefroot=sdb1 +elif [ -f /.sdb2root ] ; then + /bin/echo "Preferred root device is /dev/sdb2 (disk 2)" + mounted=/mnt/newroot + prefroot=sdb2 +elif [ -f /.nfsroot ] ; then + /bin/echo "Preferred root device is NFS" + mounted=/mnt/newroot + prefroot=nfsroot +else + /bin/echo "Preferred root device is jffs2" + mounted= + prefroot=jffs2 +fi -sysconflen=`/bin/dd if=/dev/mtd1 bs=4 count=1 2>/dev/null | /usr/bin/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=//` -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 | /usr/bin/hexdump -n 4 -e '4/1 "%02X"' $device` -# Determine desired rootfs - if [ -f /.ramdisk ] ; then - /bin/echo "Preferred root device is /dev/ram0 (maintenence)" - mounted=/mnt/newroot - prefroot=maintenence - elif [ -f /.sda1root ] ; then - /bin/echo "Preferred root device is /dev/sda1 (disk 1)" - mounted=/mnt/newroot - prefroot=sda1 - elif [ -f /.sda2root ] ; then - /bin/echo "Preferred root device is /dev/sda2 (disk 1)" - mounted=/mnt/newroot - prefroot=sda2 - elif [ -f /.sdb1root ] ; then - /bin/echo "Preferred root device is /dev/sdb1 (disk 2)" - mounted=/mnt/newroot - prefroot=sdb1 - elif [ -f /.sdb2root ] ; then - /bin/echo "Preferred root device is /dev/sdb2 (disk 2)" - mounted=/mnt/newroot - prefroot=sdb2 - elif [ -f /.altroot ] ; then - /bin/echo "Preferred root device is a user defined blockdevice" - mounted=/mnt/newroot - prefroot=altroot - elif [ -f /.nfsroot ] ; then - /bin/echo "Preferred root device is through NFS" - mounted=/mnt/newroot - prefroot=nfsroot +# Perform prepatory tasks, and determine whether the desired rootfs is viable. + +/bin/mount -t proc proc /proc + +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 "Preferred root device is jffs2" + /bin/umount /mnt/newroot + /bin/echo "Cant find valid rootfs on /dev/$prefroot, using jffs2 ..." mounted= 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/umount /mnt/newroot - /bin/echo "Cant find valid rootfs on /dev/$prefroot, using jffs2 ..." - mounted= - prefroot=jffs2 - fi - +if [ $prefroot = "maintenence" ] ; then + /bin/dd if=/dev/zero of=/dev/ram0 bs=1k count=12k 2>/dev/null + /usr/bin/mke2fs -m 0 /dev/ram0 12288 + /bin/mount -t ext2 /dev/ram0 /mnt/newroot + ( /usr/bin/find . -print0 -mount | /usr/bin/cpio -p -0 -d -m -u /mnt/newroot ) + if [ -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/ram0 (a copy of /dev/mtdblock4) ..." fi +fi - if [ $prefroot = "maintenence" ] ; then - /bin/dd if=/dev/zero of=/dev/ram0 bs=1k count=12k 2>/dev/null - /usr/bin/mke2fs -m 0 /dev/ram0 12288 - /bin/mount -t ext2 /dev/ram0 /mnt/newroot - ( /usr/bin/find . -print0 -mount | /usr/bin/cpio -p -0 -d -m -u /mnt/newroot ) - if [ -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/ram0 (a copy of /dev/mtdblock4) ..." - fi +if [ $prefroot = "nfsroot" ] ; then - fi + sysconflen=`/bin/dd if=/dev/mtd1 bs=4 count=1 2>/dev/null | /usr/bin/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=//` - if [ $prefroot = "altroot" ] ; then - # The altrootloc and altrootopts vars MUST be chosen here. - # ie: $altrootopts="-rt ext3" and $altrootloc=/dev/md0 - # Also modules can be loaded here. - # also if you have a really slow starting disk, you can put a large sleep value here. - . /.altroot - - /bin/mount $altrootopts $altrootloc /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 user defined rootfs (altroot) ..." - else - /bin/umount /mnt/newroot - /bin/echo "Cant find valid rootfs on user defined rootfs (altroot), using jffs2 ..." - mounted= - prefroot=jffs2 - fi - fi + /sbin/insmod ixp400 + /sbin/insmod ixp425_eth + /sbin/ifconfig ixp0 up $ipaddr netmask $netmask + /sbin/route add default gw $gateway - if [ $prefroot = "nfsroot" ] ; then + /sbin/ifconfig lo up 127.0.0.1 - /sbin/insmod ixp400 - /sbin/insmod ixp425_eth - /sbin/ifconfig ixp0 up $ipaddr netmask $netmask - /sbin/route add default gw $gateway + # The nfsrootloc and nfsrootopts vars can be overridden here. + . /.nfsroot - /sbin/ifconfig lo up 127.0.0.1 + /bin/mount $nfsrootopts $nfsrootloc /mnt/newroot - # The nfsrootloc and nfsrootopts vars can be overridden here. - . /.nfsroot + 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 an NFS root ..." + mounted=/mnt/newroot + else + /bin/umount /mnt/newroot + /bin/echo "Cant find valid NFS rootfs, using jffs2 ..." + mounted= + prefroot=jffs2 + fi +fi - /bin/mount $nfsrootopts $nfsrootloc /mnt/newroot +if [ $prefroot = "jffs2" ] ; then + /bin/echo "Root filesystem will be mounted from /dev/mtdblock4 ..." + mounted= +fi - 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 an NFS root ..." - mounted=/mnt/newroot - else - /bin/umount /mnt/newroot - /bin/echo "Cant find valid NFS rootfs, using jffs2 ..." - mounted= - prefroot=jffs2 - fi - fi +# Pivot to the desired rootfs and run the initial executable. - if [ $prefroot = "jffs2" ] ; then - /bin/echo "Root filesystem will be mounted from /dev/mtdblock4 ..." - mounted= - fi -fi +runboot= -# Pivot if [ -n "$mounted" ] ; then + /bin/umount /proc + cd $mounted + if [ -x ./linuxrc -o -L ./linuxrc ] ; then runboot=/linuxrc elif [ -x ./sbin/init -o -L ./sbin/init ] ; then @@ -155,7 +136,9 @@ if [ -n "$mounted" ] ; then else runboot=/bin/sh fi + /sbin/pivot_root . initrd + exec /usr/sbin/chroot . $runboot < /dev/console 1> /dev/console 2> /dev/console fi |