4 .
/lib
/functions
/system.sh
11 export CONFFILES
=/tmp
/sysupgrade.conffiles
13 RAMFS_COPY_BIN
= # extra programs for temporary ramfs root
14 RAMFS_COPY_DATA
= # extra data files
19 supivot
() { # <new_root> <old_root>
20 /bin
/mount |
grep "on $1 type" 2>&- 1>&- ||
/bin
/mount
-o bind $1 $1
21 mkdir
-p $1$2 $1/proc
$1/sys
$1/dev
$1/tmp
$1/overlay
&& \
22 /bin
/mount
-o noatime
,move
/proc
$1/proc
&& \
23 pivot_root
$1 $1$2 ||
{
28 /bin
/mount
-o noatime
,move
$2/sys
/sys
29 /bin
/mount
-o noatime
,move
$2/dev
/dev
30 /bin
/mount
-o noatime
,move
$2/tmp
/tmp
31 /bin
/mount
-o noatime
,move
$2/overlay
/overlay
2>&-
36 RAMFS_COPY_LOSETUP
="$(command -v /usr/sbin/losetup)"
37 RAMFS_COPY_LVM
="$(command -v lvm)"
40 /bin
/busybox
/bin
/ash
/bin
/sh
/bin
/mount
/bin
/umount \
41 pivot_root mount_root reboot sync
kill sleep \
42 md5sum hexdump cat zcat
dd tar gzip \
43 ls basename find cp mv rm mkdir
rmdir mknod
touch chmod \
44 '[' printf wc grep awk sed cut
sort tail \
45 mtd partx losetup mkfs.ext4 nandwrite flash_erase \
46 ubiupdatevol ubiattach ubiblock ubiformat \
47 ubidetach ubirsvol ubirmvol ubimkvol \
48 snapshot snapshot_tool
date logger \
49 /usr
/sbin
/fw_printenv
/usr
/bin
/fwtool \
50 $RAMFS_COPY_LOSETUP $RAMFS_COPY_LVM \
53 local file="$(command -v "$binary" 2>/dev/null)"
54 [ -n "$file" ] && install_bin
"$file"
56 install_file
/etc
/resolv.conf
/lib
/*.sh
/lib
/functions
/*.sh \
57 /lib
/upgrade
/*.sh
/lib
/upgrade
/do_stage2 \
58 /usr
/share
/libubox
/jshn.sh
/usr
/sbin
/fw_setenv \
59 /etc
/fw_env.config
$RAMFS_COPY_DATA
61 mkdir
-p $RAM_ROOT/var
/lock
63 [ -L "/lib64" ] && ln -s /lib
$RAM_ROOT/lib64
65 supivot
$RAM_ROOT /mnt ||
{
66 v
"Failed to switch over to ramfs. Please reboot."
70 /bin
/mount
-o remount
,ro
/mnt
73 grep -e "^/dev/dm-.*" -e "^/dev/loop.*" /proc
/mounts |
while read bdev mp _r
; do
77 [ "$RAMFS_COPY_LOSETUP" ] && losetup
-D
78 [ "$RAMFS_COPY_LVM" ] && {
79 mkdir
-p /tmp
/lvm
/cache
80 $RAMFS_COPY_LVM vgchange
-aln --ignorelockingfailure
83 grep /overlay
/proc
/mounts
> /dev
/null
&& {
84 /bin
/mount
-o noatime
,remount
,ro
/overlay
85 /bin
/umount
-l /overlay
89 kill_remaining
() { # [ <signal> [ <loop> ] ]
92 local sig
="${1:-TERM}"
96 local proc_ppid
=$
(cut
-d' ' -f4 /proc
/$$
/stat
)
98 v
"Sending $sig to remaining processes ..."
102 for stat
in /proc
/[0-9]*/stat
; do
103 [ -f "$stat" ] ||
continue
105 local pid name state ppid rest
106 read pid rest
< $stat
107 name
="${rest#\(}" ; rest="${name##*\) }" ; name="${name%\)*}"
108 set -- $rest ; state
="$1" ; ppid
="$2"
110 # Skip PID1, our parent, ourself and our children
111 [ $pid -ne 1 -a $pid -ne $proc_ppid -a $pid -ne $$
-a $ppid -ne $$
] ||
continue
113 [ -f "/proc/$pid/cmdline" ] ||
continue
116 read cmdline
< /proc
/$pid/cmdline
118 # Skip kernel threads
119 [ -n "$cmdline" ] ||
continue
121 v
"Sending signal $sig to $name ($pid)"
122 kill -$sig $pid 2>/dev
/null
124 [ $loop -eq 1 ] && run
=true
128 [ $loop_limit -eq 0 ] && {
129 v
"Failed to kill all processes."
137 while read -r a b c
; do
139 MemT
*) mem
="$b" ;; esac
142 [ "$mem" -gt 32768 ] && \
143 skip_services
="dnsmasq log network"
144 for service
in /etc
/init.d
/*; do
145 service
=${service##*/}
147 case " $skip_services " in
148 *" $service "*) continue ;; esac
150 ubus call service delete
'{ "name": "'"$service"'" }' 2>/dev
/null
153 killall
-9 telnetd
2>/dev
/null
154 killall
-9 dropbear
2>/dev
/null
155 killall
-9 ash
2>/dev
/null
159 kill_remaining KILL
1
163 echo 3 > /proc
/sys
/vm
/drop_caches
165 if [ -n "$IMAGE" ] && type 'platform_pre_upgrade' >/dev
/null
2>/dev
/null
; then
166 platform_pre_upgrade
"$IMAGE"
169 if [ -n "$(rootfs_type)" ]; then
170 v
"Switching to ramdisk..."
174 # Exec new shell from ramfs
175 exec /bin
/busybox ash
-c "$COMMAND"