4 .
/lib
/functions
/system.sh
13 export SAVE_PARTITIONS
=1
17 export CONFFILES
=/tmp
/sysupgrade.conffiles
18 export CONF_TAR
=/tmp
/sysupgrade.tgz
20 RAMFS_COPY_BIN
= # extra programs for temporary ramfs root
21 RAMFS_COPY_DATA
= # extra data files
24 [ -f "$CONF_TAR" ] ||
export SAVE_CONFIG
=0
25 [ -f /tmp
/sysupgrade.always.overwrite.bootdisk.partmap
] && export SAVE_PARTITIONS
=0
30 supivot
() { # <new_root> <old_root>
31 /bin
/mount |
grep "on $1 type" 2>&- 1>&- ||
/bin
/mount
-o bind $1 $1
32 mkdir
-p $1$2 $1/proc
$1/sys
$1/dev
$1/tmp
$1/overlay
&& \
33 /bin
/mount
-o noatime
,move
/proc
$1/proc
&& \
34 pivot_root
$1 $1$2 ||
{
39 /bin
/mount
-o noatime
,move
$2/sys
/sys
40 /bin
/mount
-o noatime
,move
$2/dev
/dev
41 /bin
/mount
-o noatime
,move
$2/tmp
/tmp
42 /bin
/mount
-o noatime
,move
$2/overlay
/overlay
2>&-
48 /bin
/busybox
/bin
/ash
/bin
/sh
/bin
/mount
/bin
/umount \
49 pivot_root mount_root reboot sync
kill sleep \
50 md5sum hexdump cat zcat bzcat
dd tar \
51 ls basename find cp mv rm mkdir
rmdir mknod
touch chmod \
52 '[' printf wc grep awk sed cut \
53 mtd partx losetup mkfs.ext4 \
54 ubiupdatevol ubiattach ubiblock ubiformat \
55 ubidetach ubirsvol ubirmvol ubimkvol \
56 snapshot snapshot_tool \
59 local file="$(which "$binary" 2>/dev/null)"
60 [ -n "$file" ] && install_bin
"$file"
62 install_file
/etc
/resolv.conf
/lib
/*.sh
/lib
/functions
/*.sh
/lib
/upgrade
/*.sh
/lib
/upgrade
/do_stage2
$RAMFS_COPY_DATA
64 [ -L "/lib64" ] && ln -s /lib
$RAM_ROOT/lib64
66 supivot
$RAM_ROOT /mnt ||
{
67 echo "Failed to switch over to ramfs. Please reboot."
71 /bin
/mount
-o remount
,ro
/mnt
74 grep /overlay
/proc
/mounts
> /dev
/null
&& {
75 /bin
/mount
-o noatime
,remount
,ro
/overlay
76 /bin
/umount
-l /overlay
80 kill_remaining
() { # [ <signal> [ <loop> ] ]
83 local sig
="${1:-TERM}"
87 local proc_ppid
=$
(cut
-d' ' -f4 /proc
/$$
/stat
)
89 echo -n "Sending $sig to remaining processes ... "
93 for stat
in /proc
/[0-9]*/stat
; do
94 [ -f "$stat" ] ||
continue
96 local pid name state ppid rest
97 read pid name state ppid rest
< $stat
98 name
="${name#(}"; name
="${name%)}"
100 # Skip PID1, our parent, ourself and our children
101 [ $pid -ne 1 -a $pid -ne $proc_ppid -a $pid -ne $$
-a $ppid -ne $$
] ||
continue
104 read cmdline
< /proc
/$pid/cmdline
106 # Skip kernel threads
107 [ -n "$cmdline" ] ||
continue
110 kill -$sig $pid 2>/dev
/null
112 [ $loop -eq 1 ] && run
=true
116 [ $loop_limit -eq 0 ] && {
118 echo "Failed to kill all processes."
133 kill_remaining KILL
1
138 if [ -n "$IMAGE" ] && type 'platform_pre_upgrade' >/dev
/null
2>/dev
/null
; then
139 platform_pre_upgrade
"$IMAGE"
142 if [ -n "$(rootfs_type)" ]; then
143 echo "Switching to ramdisk..."
147 # Exec new shell from ramfs
148 exec /bin
/busybox ash
-c "$COMMAND"