#!/bin/sh
# $Id$
-mount | grep squashfs >&- || {
- echo "You do not have a squashfs partition; aborting"
- echo "(firstboot cannot be run on jffs2 based firmwares)"
- return
-}
-
-[ -f "/tmp/.firstboot" ] && {
- echo "firstboot is already running"
- return
-}
-touch /tmp/.firstboot
+rom=$(awk '/squashfs/ {print $2}' /proc/mounts)
+jffs=$(awk '/jffs2/ {print $2}' /proc/mounts)
-jdev=$(mount | awk '/jffs2/ {print $3}')
+dupe() { # <new_root> <old_root>
+ cd $1
+ echo -n "creating directories... "
+ {
+ cd $2
+ find . -xdev -type d
+ echo "./dev ./jffs ./mnt ./proc ./tmp"
+ # xdev skips mounted directories
+ cd $1
+ } | xargs mkdir -p
+ echo "done"
-if [ -z "$jdev" ]; then
- echo -n "Creating jffs2 partition... "
- mtd erase OpenWrt >&- 2>&-
- mount -t jffs2 /dev/mtdblock/4 /jffs
+ echo -n "setting up symlinks... "
+ for file in $(cd $2; find . -xdev -type f; find . -xdev -type l;)
+ do {
+ case "$file" in
+ "./rom/note") ;; #nothing
+ "./etc/config"|\
+ "./etc/resolv.conf"|\
+ "./usr/lib/ipkg/info") cp -af $2/$file $file;;
+ *) ln -sf /rom/${file#./*} $file;;
+ esac
+ } done
echo "done"
- cd /jffs
-else
- echo "firstboot has already been run"
- echo "jffs2 partition is mounted, only resetting files"
- cd $jdev
-fi
+}
-exec 2>/dev/null
+pivot() { # <new_root> <old_root>
+ pivot_root $1 $1$2
+ mount none /proc -t proc
+ umount $2/proc
+ mount -o move $2/dev /dev
+ mount -o move $2/tmp /tmp
+}
-mount /dev/mtdblock/2 /rom -o ro
+mountdp() { # <device> <mount_point> <ignored> <fs>
+ mount $1 $2 -t $4
+ dupe $2 $rom
+ pivot $2 /rom
+}
-echo -n "creating directories... "
-{
- cd /rom
- find . -type d
- cd -
-} | xargs mkdir
-echo "done"
+# script run by mount_root
+[ "$1" = "ramoverlay" ] && {
+ #1st stage
+ mountdp none /mnt -t tmpfs
+ exit 0
+}
-echo -n "setting up symlinks... "
-for file in $(cd /rom; find * -type f; find * -type l;)
-do {
- case "${file%/*}" in
- "usr/lib/ipkg/info"|"etc/config") cp -f /rom/$file $file;;
- *) ln -sf /rom/$file $file;;
- esac
-} done
-echo "done"
+[ "$1" = "switch2jffs" ] && {
+ #2nd stage
+ mtd erase OpenWrt
+ mount -o remount,ro none / # try to avoid fs changing while copying
+ mount -o bind / /mnt
+ mount /dev/mtdblock/4 /rom/jffs -t jffs2
+ echo -n "copying files ... "
+ cp -a /mnt/* /rom/jffs
+ umount /mnt
+ echo "done"
+ pivot /rom /mnt
+ pivot /jffs /rom
+ jffs2root --clean
+ exit 0
+}
-touch /tmp/resolv.conf
-ln -s /tmp/resolv.conf /etc/resolv.conf
+# script run manually
+[ -z "$rom" ] && {
+ echo "You do not have a squashfs partition; aborting"
+ echo "(firstboot cannot be run on jffs2 based firmwares)"
+ exit 1
+}
-umount /rom
-mount none /jffs/proc -t proc
-pivot_root /jffs /jffs/rom
-mount none /dev -t devfs
-mount none /tmp -t ramfs
-umount /rom/proc
-umount /rom/tmp
-umount /rom/dev
+[ \! -z "$jffs" ] && {
+ echo "firstboot has already been run"
+ echo "jffs2 partition is mounted, only resetting files"
+ dupe $jffs $rom
+ exit 0
+}
-# normally created by boot script
-mkdir -p /var/run
+mtd erase OpenWrt
+mountdp /dev/mtdblock/4 /jffs -t jffs2
#!/bin/sh
-echo "S" > /proc/jffs2_bbc
+[ -f /proc/jffs2_bbc ] && echo "S" > /proc/jffs2_bbc
mkdir -p /var/run
mkdir -p /var/log
ifconfig lo 127.0.0.1 up
ifconfig eth0 promisc
-# configure the switch based on nvram if not in failsafe mode
-[ -d /proc/switch/eth0 -a -z "$FAILSAFE" ] && {
- for nr in `seq 0 15`; do
+# configure the switch based on nvram
+[ -d /proc/switch/eth0 ] && {
+ for nr in $(seq 0 15); do
vp="$(nvram get vlan${nr}ports)"
[ -z "$vp" -o -z "$(nvram get vlan${nr}hwname)" ] || {
echo "$vp" > /proc/switch/eth0/vlan/$nr/ports
vconfig set_name_type VLAN_PLUS_VID_NO_PAD
-# automagically run firstboot
-[ -z "$FAILSAFE" -a -z "$(nvram get no_root_swap)" ] && {
- { mount|grep "on / type jffs2" 1>&-; } || firstboot
-}
#!/bin/sh
-is_clean() {
- OFFSET="$((0x$(dd if=/dev/mtdblock/1 bs=1 skip=$((0x14)) count=2 2>&- | hexdump | grep 0000000 | cut -d ' ' -f 2) - 1))"
- dd if=/dev/mtdblock/1 bs=1 skip=$OFFSET count=1 2>&- | hexdump -v | grep ' 0000' > /dev/null && return 255 || return 0
+is_dirty() {
+ grep Broadcom /proc/cpuinfo >&- || return 1
+ OFFSET="$(($(hexdump -v /dev/mtdblock/1 -s 20 -n 2 -e '"%d"')-1))"
+ return $(hexdump -v /dev/mtdblock/1 -s $OFFSET -n 1 -e '"%d"')
}
-if [ "$1" != "failsafe" ]; then
+if [ "$1" != "failsafe" -a "$(nvram get no_root_swap)" != 1 ]; then
+ mtd unlock linux
mount | grep jffs2 >&-
if [ $? = 0 ] ; then
if [ $(cat /proc/mtd | wc -l) = 6 ]; then
- echo 5 > /proc/sys/diag
- mtd unlock linux
mtd erase OpenWrt
jffs2root --move
else
- mtd unlock rootfs
mount -o remount,rw /dev/root /
fi
else
- if [ -z "$(nvram get no_root_swap)" ]; then
- is_clean || {
- mtd erase OpenWrt
- mtd unlock linux
- jffs2root --clean
- }
- mtd unlock OpenWrt
- mount -t jffs2 /dev/mtdblock/4 /jffs
+ is_dirty
+ if [ $? = 0 ]; then
+ firstboot ramoverlay >&- 2>&-
+ else
+ mount /dev/mtdblock/4 /jffs
pivot_root /jffs /jffs/rom
mount none /proc -t proc
- mount none /dev -t devfs
- umount /rom/proc /rom/dev >&-
+ umount /rom/proc
+ mount -o move /rom/dev /dev
fi
fi
fi
+
mount none /tmp -t tmpfs -o nosuid,nodev,mode=1777,size=50%
mkdir -p /dev/pts
mount none /dev/pts -t devpts
+mount -t sysfs none /sys 2>&-