From 40735025cd47f41bc95bf9323fc9f1114f1f3fc1 Mon Sep 17 00:00:00 2001 From: Mike Baker Date: Tue, 28 Mar 2006 15:10:06 +0000 Subject: [PATCH] clean up firstboot & mount_root; fix tmpfs sizes on low ram SVN-Revision: 3523 --- .../package/base-files/default/bin/firstboot | 85 ++++++++++--------- .../base-files/default/sbin/mount_root | 14 +-- 2 files changed, 50 insertions(+), 49 deletions(-) diff --git a/openwrt/package/base-files/default/bin/firstboot b/openwrt/package/base-files/default/bin/firstboot index fbace811c9..0b3552fb12 100755 --- a/openwrt/package/base-files/default/bin/firstboot +++ b/openwrt/package/base-files/default/bin/firstboot @@ -33,55 +33,56 @@ dupe() { # } pivot() { # - 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 -o move /proc $1/proc && \ + pivot_root $1 $1$2 && { + mount -o move $2/dev /dev + mount -o move $2/tmp /tmp + } } mountdp() { # - mount $1 $2 -t $4 - dupe $2 $rom - pivot $2 /rom + dev=$1; mnt=$2; shift 2; opt=$* + mount $dev $mnt $opt + dupe $mnt $rom + pivot $mnt /rom } -# script run by mount_root -[ "$1" = "ramoverlay" ] && { - #1st stage - mountdp none /mnt -t tmpfs - exit 0 +ramoverlay() { + mkdir -p /tmp/root + mountdp /tmp/root /mnt -o bind } -[ -z "$rom" ] && { - echo "You do not have a squashfs partition; aborting" - echo "(firstboot cannot be run on jffs2 based firmwares)" - exit 1 -} +[ "${0##*/}" = "firstboot" ] && { + [ -z "$rom" ] && { + echo "You do not have a squashfs partition; aborting" + echo "(firstboot cannot be run on jffs2 based firmwares)" + exit 1 + } -[ "$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 -} + [ "$1" = "switch2jffs" ] && { + 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 + mount -o move /mnt /tmp/root + pivot /jffs /rom + jffs2root --clean + exit 0 + } -# script run manually -[ \! -z "$jffs" ] && { - echo "firstboot has already been run" - echo "jffs2 partition is mounted, only resetting files" - dupe $jffs $rom - exit 0 -} + # script run manually + [ \! -z "$jffs" ] && { + echo "firstboot has already been run" + echo "jffs2 partition is mounted, only resetting files" + dupe $jffs $rom + exit 0 + } -mtd erase OpenWrt -mountdp /dev/mtdblock/4 /jffs -t jffs2 + mtd erase OpenWrt + mountdp /dev/mtdblock/4 /jffs -t jffs2 +} diff --git a/openwrt/package/base-files/default/sbin/mount_root b/openwrt/package/base-files/default/sbin/mount_root index 8fddce7e25..4d3a0367de 100755 --- a/openwrt/package/base-files/default/sbin/mount_root +++ b/openwrt/package/base-files/default/sbin/mount_root @@ -5,6 +5,9 @@ is_dirty() { return $(hexdump -v /dev/mtdblock/1 -s $OFFSET -n 1 -e '"%d"') } +size=$(awk '/Mem:/ {l=5242880;print((s=$2/2)&- @@ -16,19 +19,16 @@ if [ "$1" != "failsafe" -a "$(nvram get no_root_swap)" != 1 ]; then mount -o remount,rw /dev/root / fi else + . /bin/firstboot is_dirty [ $? != 0 ] && { mount /dev/mtdblock/4 /jffs - pivot_root /jffs /jffs/rom && { - mount none /proc -t proc - umount /rom/proc - mount -o move /rom/dev /dev - } - } || firstboot ramoverlay + pivot /rom + } || ramoverlay fi fi -mount none /tmp -t tmpfs -o nosuid,nodev,mode=1777,size=50% +mount none /tmp -t tmpfs -o remount,nosuid,nodev,mode=1777 mkdir -p /dev/pts mount none /dev/pts -t devpts mount -t sysfs none /sys 2>&- -- 2.30.2