4 .
/lib
/functions
/system.sh
11 export CONFFILES
=/tmp
/sysupgrade.conffiles
12 export CONF_TAR
=/tmp
/sysupgrade.tgz
14 RAMFS_COPY_BIN
= # extra programs for temporary ramfs root
15 RAMFS_COPY_DATA
= # extra data files
20 supivot
() { # <new_root> <old_root>
21 /bin
/mount |
grep "on $1 type" 2>&- 1>&- ||
/bin
/mount
-o bind $1 $1
22 mkdir
-p $1$2 $1/proc
$1/sys
$1/dev
$1/tmp
$1/overlay
&& \
23 /bin
/mount
-o noatime
,move
/proc
$1/proc
&& \
24 pivot_root
$1 $1$2 ||
{
29 /bin
/mount
-o noatime
,move
$2/sys
/sys
30 /bin
/mount
-o noatime
,move
$2/dev
/dev
31 /bin
/mount
-o noatime
,move
$2/tmp
/tmp
32 /bin
/mount
-o noatime
,move
$2/overlay
/overlay
2>&-
38 /bin
/busybox
/bin
/ash
/bin
/sh
/bin
/mount
/bin
/umount \
39 pivot_root mount_root reboot sync
kill sleep \
40 md5sum hexdump cat zcat bzcat
dd tar \
41 ls basename find cp mv rm mkdir
rmdir mknod
touch chmod \
42 '[' printf wc grep awk sed cut \
43 mtd partx losetup mkfs.ext4 \
44 ubiupdatevol ubiattach ubiblock ubiformat \
45 ubidetach ubirsvol ubirmvol ubimkvol \
46 snapshot snapshot_tool \
49 local file="$(which "$binary" 2>/dev/null)"
50 [ -n "$file" ] && install_bin
"$file"
52 install_file
/etc
/resolv.conf
/lib
/*.sh
/lib
/functions
/*.sh
/lib
/upgrade
/*.sh
/lib
/upgrade
/do_stage2
$RAMFS_COPY_DATA
54 [ -L "/lib64" ] && ln -s /lib
$RAM_ROOT/lib64
56 supivot
$RAM_ROOT /mnt ||
{
57 echo "Failed to switch over to ramfs. Please reboot."
61 /bin
/mount
-o remount
,ro
/mnt
64 grep /overlay
/proc
/mounts
> /dev
/null
&& {
65 /bin
/mount
-o noatime
,remount
,ro
/overlay
66 /bin
/umount
-l /overlay
70 kill_remaining
() { # [ <signal> [ <loop> ] ]
73 local sig
="${1:-TERM}"
77 local proc_ppid
=$
(cut
-d' ' -f4 /proc
/$$
/stat
)
79 echo -n "Sending $sig to remaining processes ... "
83 for stat
in /proc
/[0-9]*/stat
; do
84 [ -f "$stat" ] ||
continue
86 local pid name state ppid rest
87 read pid name state ppid rest
< $stat
88 name
="${name#(}"; name
="${name%)}"
90 # Skip PID1, our parent, ourself and our children
91 [ $pid -ne 1 -a $pid -ne $proc_ppid -a $pid -ne $$
-a $ppid -ne $$
] ||
continue
94 read cmdline
< /proc
/$pid/cmdline
97 [ -n "$cmdline" ] ||
continue
100 kill -$sig $pid 2>/dev
/null
102 [ $loop -eq 1 ] && run
=true
106 [ $loop_limit -eq 0 ] && {
108 echo "Failed to kill all processes."
123 kill_remaining KILL
1
128 if [ -n "$IMAGE" ] && type 'platform_pre_upgrade' >/dev
/null
2>/dev
/null
; then
129 platform_pre_upgrade
"$IMAGE"
132 if [ -n "$(rootfs_type)" ]; then
133 echo "Switching to ramdisk..."
137 # Exec new shell from ramfs
138 exec /bin
/busybox ash
-c "$COMMAND"