5 mtdpart
="$(find_mtd_part $partname)"
7 rom
=$
(awk '/squashfs/ {print $2}' /proc
/mounts
)
8 jffs
=$
(awk '/jffs2/ {print $2}' /proc
/mounts
)
10 dupe
() { # <new_root> <old_root>
12 echo -n "creating directories... "
16 echo "./dev ./jffs ./mnt ./proc ./tmp"
17 # xdev skips mounted directories
22 echo -n "setting up symlinks... "
23 for file in $
(cd $2; find .
-xdev -type f
;); do
25 .
/rom
/note
) ;; #nothing
27 .
/usr
/lib
/opkg
/info
/*) cp -af $2/$file $file;;
28 *) ln -sf /rom
/${file#./*} $file;;
31 for file in $
(cd $2; find .
-xdev -type l
;); do
32 cp -af $2/${file#./*} $file
37 pivot
() { # <new_root> <old_root>
38 mount
-o move
/proc
$1/proc
&& \
39 pivot_root
$1 $1$2 && {
40 mount
-o move
$2/dev
/dev
41 mount
-o move
$2/tmp
/tmp
42 mount
-o move
$2/sys
/sys
2>&-
43 mount
-o move
$2/jffs
/jffs
2>&-
48 fopivot
() { # <rw_root> <ro_root> <dupe?>
51 if grep -q mini_fo
/proc
/filesystems
; then
52 mount
-t mini_fo
-o base
=/,sto
=$1 "mini_fo:$1" /mnt
2>&- && root
=/mnt
55 mount
--bind -o union
"$1" /mnt
&& root
=/mnt
59 mount |
grep "on $1 type" 2>&- 1>&- || mount
-o bind $1 $1
68 mount
-t tmpfs root
/tmp
/root
69 fopivot
/tmp
/root
/rom
1
72 # invoked as an executable
73 [ "${0##*/}" = "firstboot" ] && {
75 [ -z "$mtdpart" ] && {
76 echo "MTD partition not found."
81 echo "You do not have a squashfs partition; aborting"
82 echo "(firstboot cannot be run on jffs2 based firmwares)"
86 [ "$1" = "switch2jffs" ] && {
87 if grep -q mini_fo
/proc
/filesystems
; then
88 mount
"$mtdpart" /rom
/jffs
-t jffs2 ||
exit
90 # try to avoid fs changing while copying
91 mount
-o remount
,ro none
/ 2>&-
93 # copy ramoverlay to jffs2
94 echo -n "copying files ... "
95 cp -a /tmp
/root
/* /rom
/jffs
2>&-
98 # switch back to squashfs (temporarily)
99 # and park the ramdisk ontop of /tmp/root
101 mount
-o move
/mnt
/tmp
/root
103 # /jffs is the overlay
104 # /rom is the readonly
107 # try to get rid of /tmp/root
108 # this will almost always fail
109 umount
/tmp
/root
2>&-
111 # switch back to squashfs temporarily
114 # get rid of the old overlay
117 # another umount to get rid of the bind from /tmp/root
121 mount
"$mtdpart" /jffs
-t jffs2 ||
exit
123 # workaround to ensure that union can attach properly
127 # switch to the new (empty) jffs2
130 # copy ramoverlay to jffs2, must be done after switching
131 # to the new rootfs to avoid creating opaque directories
132 echo -n "copying files ... "
133 cp -a /tmp
/root
/* / >/dev
/null
2>&1
144 # script run manually
145 [ \
! -z "$jffs" ] && {
146 echo "firstboot has already been run"
147 echo "jffs2 partition is mounted, only resetting files"
148 grep mini_fo
/proc
/filesystems
>&-
154 mount
-o remount
$jffs / 2>&-
159 mtd erase
"$partname"
160 mount
"$mtdpart" /jffs
-t jffs2
This page took 0.055157 seconds and 5 git commands to generate.