-pivot() { # <new_root> <old_root>
- mount | grep "on $1 type" 2>&- 1>&- || mount -o bind $1 $1
- mkdir -p $1$2 $1/proc $1/dev $1/tmp $1/overlay && \
- mount -o move /proc $1/proc && \
- pivot_root $1 $1$2 || {
- umount $1 $1
- return 1
- }
- mount -o move $2/dev /dev
- mount -o move $2/tmp /tmp
- mount -o move $2/overlay /overlay 2>&-
- return 0
-}
-
-run_ramfs() { # <command> [...]
- install_bin /bin/busybox /bin/ash /bin/sh /bin/mount /bin/umount /sbin/pivot_root /usr/bin/wget /sbin/reboot /bin/sync /bin/dd /bin/grep /bin/cp /bin/mv /bin/tar /usr/bin/md5sum "/usr/bin/[" /bin/vi /bin/ls /bin/cat /usr/bin/awk /usr/bin/hexdump /bin/sleep /bin/zcat /usr/bin/bzcat
- install_bin /sbin/mtd
- for file in $RAMFS_COPY_BIN; do
- install_bin $file
- done
- install_file /etc/resolv.conf /etc/functions.sh /lib/upgrade/*.sh $RAMFS_COPY_DATA
-
- pivot $RAM_ROOT /mnt || {
- echo "Failed to switch over to ramfs. Please reboot."
- exit 1
- }
-
- mount -o remount,ro /mnt
- umount -l /mnt
-
- grep /overlay /proc/mounts > /dev/null && {
- mount -o remount,ro /overlay
- umount -l /overlay
- }
-
- # spawn a new shell from ramdisk to reduce the probability of cache issues
- exec /bin/busybox ash -c "$*"
-}
-