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>&-
37 /bin/busybox /bin/ash /bin/sh /bin/mount /bin/umount \
38 pivot_root mount_root reboot sync kill sleep \
39 md5sum hexdump cat zcat bzcat dd tar \
40 ls basename find cp mv rm mkdir rmdir mknod touch chmod \
41 '[' printf wc grep awk sed cut \
42 mtd partx losetup mkfs.ext4 \
43 ubiupdatevol ubiattach ubiblock ubiformat \
44 ubidetach ubirsvol ubirmvol ubimkvol \
45 snapshot snapshot_tool \
48 local file="$(which "$binary" 2>/dev/null)"
49 [ -n "$file" ] && install_bin "$file"
51 install_file /etc/resolv.conf /lib/*.sh /lib/functions/*.sh /lib/upgrade/*.sh /lib/upgrade/do_stage2 $RAMFS_COPY_DATA
53 [ -L "/lib64" ] && ln -s /lib $RAM_ROOT/lib64
55 supivot $RAM_ROOT /mnt || {
56 echo "Failed to switch over to ramfs. Please reboot."
60 /bin/mount -o remount,ro /mnt
63 grep /overlay /proc/mounts > /dev/null && {
64 /bin/mount -o noatime,remount,ro /overlay
65 /bin/umount -l /overlay
69 kill_remaining() { # [ <signal> [ <loop> ] ]
72 local sig="${1:-TERM}"
76 local proc_ppid=$(cut -d' ' -f4 /proc/$$/stat)
78 echo -n "Sending $sig to remaining processes ... "
82 for stat in /proc/[0-9]*/stat; do
83 [ -f "$stat" ] || continue
85 local pid name state ppid rest
86 read pid name state ppid rest < $stat
87 name="${name#(}"; name="${name%)}"
89 # Skip PID1, our parent, ourself and our children
90 [ $pid -ne 1 -a $pid -ne $proc_ppid -a $pid -ne $$ -a $ppid -ne $$ ] || continue
93 read cmdline < /proc/$pid/cmdline
96 [ -n "$cmdline" ] || continue
99 kill -$sig $pid 2>/dev/null
101 [ $loop -eq 1 ] && run=true
105 [ $loop_limit -eq 0 ] && {
107 echo "Failed to kill all processes."
122 kill_remaining KILL 1
127 if [ -n "$IMAGE" ] && type 'platform_pre_upgrade' >/dev/null 2>/dev/null; then
128 platform_pre_upgrade "$IMAGE"
131 if [ -n "$(rootfs_type)" ]; then
132 echo "Switching to ramdisk..."
136 # Exec new shell from ramfs
137 exec /bin/busybox ash -c "$COMMAND"