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 \
43 ls basename find cp mv rm mkdir
rmdir mknod
touch chmod \
44 '[' printf wc grep awk sed cut \
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 $RAMFS_COPY_LOSETUP $RAMFS_COPY_LVM \
52 local file="$(command -v "$binary" 2>/dev/null)"
53 [ -n "$file" ] && install_bin
"$file"
55 install_file
/etc
/resolv.conf
/lib
/*.sh
/lib
/functions
/*.sh
/lib
/upgrade
/*.sh
/lib
/upgrade
/do_stage2
/usr
/share
/libubox
/jshn.sh
$RAMFS_COPY_DATA
57 [ -L "/lib64" ] && ln -s /lib
$RAM_ROOT/lib64
59 supivot
$RAM_ROOT /mnt ||
{
60 v
"Failed to switch over to ramfs. Please reboot."
64 /bin
/mount
-o remount
,ro
/mnt
67 grep -e "^/dev/dm-.*" -e "^/dev/loop.*" /proc
/mounts |
while read bdev mp _r
; do
71 [ "$RAMFS_COPY_LOSETUP" ] && losetup
-D
72 [ "$RAMFS_COPY_LVM" ] && {
73 mkdir
-p /tmp
/lvm
/cache
74 $RAMFS_COPY_LVM vgchange
-aln --ignorelockingfailure
77 grep /overlay
/proc
/mounts
> /dev
/null
&& {
78 /bin
/mount
-o noatime
,remount
,ro
/overlay
79 /bin
/umount
-l /overlay
83 kill_remaining
() { # [ <signal> [ <loop> ] ]
86 local sig
="${1:-TERM}"
90 local proc_ppid
=$
(cut
-d' ' -f4 /proc
/$$
/stat
)
92 v
"Sending $sig to remaining processes ..."
96 for stat
in /proc
/[0-9]*/stat
; do
97 [ -f "$stat" ] ||
continue
99 local pid name state ppid rest
100 read pid name state ppid rest
< $stat
101 name
="${name#(}"; name
="${name%)}"
103 # Skip PID1, our parent, ourself and our children
104 [ $pid -ne 1 -a $pid -ne $proc_ppid -a $pid -ne $$
-a $ppid -ne $$
] ||
continue
107 read cmdline
< /proc
/$pid/cmdline
109 # Skip kernel threads
110 [ -n "$cmdline" ] ||
continue
112 v
"Sending signal $sig to $name ($pid)"
113 kill -$sig $pid 2>/dev
/null
115 [ $loop -eq 1 ] && run
=true
119 [ $loop_limit -eq 0 ] && {
120 v
"Failed to kill all processes."
128 while read -r a b c
; do
130 MemT
*) mem
="$b" ;; esac
133 [ "$mem" -gt 32768 ] && \
134 skip_services
="dnsmasq log network"
135 for service
in /etc
/init.d
/*; do
136 service
=${service##*/}
138 case " $skip_services " in
139 *" $service "*) continue ;; esac
141 ubus call service delete
'{ "name": "'"$service"'" }' 2>/dev
/null
144 killall
-9 telnetd
2>/dev
/null
145 killall
-9 dropbear
2>/dev
/null
146 killall
-9 ash
2>/dev
/null
150 kill_remaining KILL
1
154 echo 3 > /proc
/sys
/vm
/drop_caches
156 if [ -n "$IMAGE" ] && type 'platform_pre_upgrade' >/dev
/null
2>/dev
/null
; then
157 platform_pre_upgrade
"$IMAGE"
160 if [ -n "$(rootfs_type)" ]; then
161 v
"Switching to ramdisk..."
165 # Exec new shell from ramfs
166 exec /bin
/busybox ash
-c "$COMMAND"