4 .
/lib
/functions
/system.sh
9 export SAVE_PARTITIONS
=1
13 export CONFFILES
=/tmp
/sysupgrade.conffiles
14 export CONF_TAR
=/tmp
/sysupgrade.tgz
16 RAMFS_COPY_BIN
= # extra programs for temporary ramfs root
17 RAMFS_COPY_DATA
= # extra data files
20 [ -f /tmp
/sysupgrade.always.overwrite.bootdisk.partmap
] && export SAVE_PARTITIONS
=0
25 supivot
() { # <new_root> <old_root>
26 /bin
/mount |
grep "on $1 type" 2>&- 1>&- ||
/bin
/mount
-o bind $1 $1
27 mkdir
-p $1$2 $1/proc
$1/sys
$1/dev
$1/tmp
$1/overlay
&& \
28 /bin
/mount
-o noatime
,move
/proc
$1/proc
&& \
29 pivot_root
$1 $1$2 ||
{
34 /bin
/mount
-o noatime
,move
$2/sys
/sys
35 /bin
/mount
-o noatime
,move
$2/dev
/dev
36 /bin
/mount
-o noatime
,move
$2/tmp
/tmp
37 /bin
/mount
-o noatime
,move
$2/overlay
/overlay
2>&-
43 /bin
/busybox
/bin
/ash
/bin
/sh
/bin
/mount
/bin
/umount \
44 pivot_root mount_root reboot sync
kill sleep \
45 md5sum hexdump cat zcat bzcat
dd tar \
46 ls basename find cp mv rm mkdir
rmdir mknod
touch chmod \
47 '[' printf wc grep awk sed cut \
48 mtd partx losetup mkfs.ext4 \
49 ubiupdatevol ubiattach ubiblock ubiformat \
50 ubidetach ubirsvol ubirmvol ubimkvol \
51 snapshot snapshot_tool \
54 local file="$(which "$binary" 2>/dev/null)"
55 [ -n "$file" ] && install_bin
"$file"
57 install_file
/etc
/resolv.conf
/lib
/*.sh
/lib
/functions
/*.sh
/lib
/upgrade
/*.sh
/lib
/upgrade
/do_stage2
$RAMFS_COPY_DATA
59 [ -L "/lib64" ] && ln -s /lib
$RAM_ROOT/lib64
61 supivot
$RAM_ROOT /mnt ||
{
62 echo "Failed to switch over to ramfs. Please reboot."
66 /bin
/mount
-o remount
,ro
/mnt
69 grep /overlay
/proc
/mounts
> /dev
/null
&& {
70 /bin
/mount
-o noatime
,remount
,ro
/overlay
71 /bin
/umount
-l /overlay
75 kill_remaining
() { # [ <signal> [ <loop> ] ]
78 local sig
="${1:-TERM}"
82 local proc_ppid
=$
(cut
-d' ' -f4 /proc
/$$
/stat
)
84 echo -n "Sending $sig to remaining processes ... "
88 for stat
in /proc
/[0-9]*/stat
; do
89 [ -f "$stat" ] ||
continue
91 local pid name state ppid rest
92 read pid name state ppid rest
< $stat
93 name
="${name#(}"; name
="${name%)}"
95 # Skip PID1, our parent, ourself and our children
96 [ $pid -ne 1 -a $pid -ne $proc_ppid -a $pid -ne $$
-a $ppid -ne $$
] ||
continue
99 read cmdline
< /proc
/$pid/cmdline
101 # Skip kernel threads
102 [ -n "$cmdline" ] ||
continue
105 kill -$sig $pid 2>/dev
/null
107 [ $loop -eq 1 ] && run
=true
111 [ $loop_limit -eq 0 ] && {
113 echo "Failed to kill all processes."
128 kill_remaining KILL
1
133 if [ -n "$IMAGE" ] && type 'platform_pre_upgrade' >/dev
/null
2>/dev
/null
; then
134 platform_pre_upgrade
"$IMAGE"
137 if [ -n "$(rootfs_type)" ]; then
138 echo "Switching to ramdisk..."
142 # Exec new shell from ramfs
143 exec /bin
/busybox ash
-c "$COMMAND"