2 # $Id: firstboot 5544 2006-11-17 03:07:10Z nbd $
6 mtdpart
="$(find_mtd_part $partname)"
8 rom
=$
(awk '/squashfs/ {print $2}' /proc
/mounts
)
9 jffs
=$
(awk '/jffs2/ {print $2}' /proc
/mounts
)
11 dupe
() { # <new_root> <old_root>
13 echo -n "creating directories... "
17 echo "./dev ./jffs ./mnt ./proc ./tmp"
18 # xdev skips mounted directories
23 echo -n "setting up symlinks... "
24 for file in $
(cd $2; find .
-xdev -type f
;); do
26 .
/rom
/note
) ;; #nothing
28 .
/usr
/lib
/opkg
/info
/*) cp -af $2/$file $file;;
29 *) ln -sf /rom
/${file#./*} $file;;
32 for file in $
(cd $2; find .
-xdev -type l
;); do
33 cp -af $2/${file#./*} $file
38 pivot
() { # <new_root> <old_root>
39 mount
-o move
/proc
$1/proc
&& \
40 pivot_root
$1 $1$2 && {
41 mount
-o move
$2/dev
/dev
42 mount
-o move
$2/tmp
/tmp
43 mount
-o move
$2/sys
/sys
2>&-
44 mount
-o move
$2/jffs
/jffs
2>&-
49 fopivot
() { # <rw_root> <ro_root> <dupe?>
52 mount
-t mini_fo
-o base
=/,sto
=$1 "mini_fo:$1" /mnt
2>&- && root
=/mnt
55 mount |
grep "on $1 type" 2>&- 1>&- || mount
-o bind $1 $1
64 fopivot
/tmp
/root
/rom
1
67 # invoked as an executable
68 [ "${0##*/}" = "firstboot" ] && {
70 [ -z "$mtdpart" ] && {
71 echo "MTD partition not found."
76 echo "You do not have a squashfs partition; aborting"
77 echo "(firstboot cannot be run on jffs2 based firmwares)"
81 [ "$1" = "switch2jffs" ] && {
82 mount
"$mtdpart" /rom
/jffs
-t jffs2 ||
exit
84 # try to avoid fs changing while copying
85 mount
-o remount
,ro none
/ 2>&-
87 # copy ramoverlay to jffs2
88 echo -n "copying files ... "
89 cp -a /tmp
/root
/* /rom
/jffs
2>&-
92 # switch back to squashfs (temporarily)
93 # and park the ramdisk ontop of /tmp/root
95 mount
-o move
/mnt
/tmp
/root
97 # /jffs is the overlay
98 # /rom is the readonly
101 # try to get rid of /tmp/root
102 # this will almost always fail
103 umount
/tmp
/root
2>&-
108 # script run manually
109 [ \
! -z "$jffs" ] && {
110 echo "firstboot has already been run"
111 echo "jffs2 partition is mounted, only resetting files"
112 grep mini_fo
/proc
/filesystems
>&-
118 mount
-o remount
$jffs / 2>&-
123 mtd erase
"$partname"
124 mount
"$mtdpart" /jffs
-t jffs2
This page took 0.071334 seconds and 5 git commands to generate.