4 rom
=$
(awk '/squashfs/ {print $2}' /proc
/mounts
)
5 jffs
=$
(awk '/jffs2/ {print $2}' /proc
/mounts
)
7 dupe
() { # <new_root> <old_root>
9 echo -n "creating directories... "
13 echo "./dev ./jffs ./mnt ./proc ./tmp"
14 # xdev skips mounted directories
19 echo -n "setting up symlinks... "
20 for file in $
(cd $2; find .
-xdev -type f
;); do
22 .
/rom
/note
) ;; #nothing
24 .
/usr
/lib
/ipkg
/info
/*) cp -af $2/$file $file;;
25 *) ln -sf /rom
/${file#./*} $file;;
28 for file in $
(cd $2; find .
-xdev -type l
;); do
29 cp -af $2/${file#./*} $file
34 pivot
() { # <new_root> <old_root>
35 mount
-o move
/proc
$1/proc
&& \
36 pivot_root
$1 $1$2 && {
37 mount
-o move
$2/dev
/dev
38 mount
-o move
$2/tmp
/tmp
39 mount
-o move
$2/jffs
/jffs
2>&-
44 fopivot
() { # <rw_root> <ro_root> <dupe?>
47 mount
-t mini_fo
-o base
=/,sto
=$1 $1 /mnt
2>&- && root
=/mnt
50 mount |
grep "on $1 type" 2>&- 1>&- || mount
-o bind $1 $1
59 fopivot
/tmp
/root
/rom
1
62 # invoked as an executable
63 [ "${0##*/}" = "firstboot" ] && {
66 echo "You do not have a squashfs partition; aborting"
67 echo "(firstboot cannot be run on jffs2 based firmwares)"
71 [ "$1" = "switch2jffs" ] && {
74 # try to avoid fs changing while copying
75 mount
-o remount
,ro none
/ 2>&-
77 # copy ramoverlay to jffs2
78 mount
/dev
/mtdblock
/4 /rom
/jffs
-t jffs2
79 echo -n "copying files ... "
80 cp -a /tmp
/root
/* /rom
/jffs
2>&-
83 # switch back to squashfs (temporarily)
84 # and park the ramdisk ontop of /tmp/root
86 mount
-o move
/mnt
/tmp
/root
88 # /jffs is the overlay
89 # /rom is the readonly
92 # try to get rid of /tmp/root
93 # this will almost always fail
101 # script run manually
102 [ \
! -z "$jffs" ] && {
103 echo "firstboot has already been run"
104 echo "jffs2 partition is mounted, only resetting files"
105 grep mini_fo
/proc
/filesystems
>&-
111 mount
-o remount
$jffs / 2>&-
117 mount
/dev
/mtdblock
/4 /jffs
-t jffs2