2 コミット c5b3b1df70 ... f9817ec523

作者 SHA1 メッセージ 日付
  baiywt f9817ec523 Add opi-bkimg script for backup image functionality 1 ヶ月 前
  baiywt 5cc413cd26 orangepi-config: add overlayroot support 1 ヶ月 前

+ 191 - 16
external/cache/sources/orangepi-config/debian-config-jobs

@@ -1554,25 +1554,200 @@ function jobs ()
 	# Toggle virtual read-only root filesystem
 	#
 	"Overlayroot" )
-		if ! is_package_manager_running; then
-			if [[ -n $(mount | grep -w overlay | grep -v chromium) ]]; then
-				dialog --title " Root overlay " --backtitle "$BACKTITLE" --yes-label "Disable" \
-				--no-label "Cancel" \
-				--yesno "\nYour system is already virtual read-only.\n\nDo you want to disable this feature and reboot?" 9 60
-				[[ $? = 0 ]] && overlayroot-chroot sed -i "s/^overlayroot=.*/overlayroot=\"\"/" /etc/overlayroot.conf && \
-				overlayroot-chroot rm /etc/update-motd.d/97-overlayroot && reboot
+		#if ! is_package_manager_running; then
+		#	if [[ -n $(mount | grep -w overlay | grep -v chromium) ]]; then
+		#		dialog --title " Root overlay " --backtitle "$BACKTITLE" --yes-label "Disable" \
+		#		--no-label "Cancel" \
+		#		--yesno "\nYour system is already virtual read-only.\n\nDo you want to disable this feature and reboot?" 9 60
+		#		[[ $? = 0 ]] && overlayroot-chroot sed -i "s/^overlayroot=.*/overlayroot=\"\"/" /etc/overlayroot.conf && \
+		#		overlayroot-chroot rm /etc/update-motd.d/97-overlayroot && reboot
+		#	else
+		#		debconf-apt-progress -- apt-get -o Dpkg::Options::="--force-confnew" -y --no-install-recommends install overlayroot
+		#		echo '#!/bin/bash' > /etc/update-motd.d/97-overlayroot
+		#		echo 'if [ -n "$(mount | grep -w tmpfs-root)" ]; then \
+		#		echo -e "[\e[0m \e[1mremember: your system is in virtual read only mode\e[0m ]\n";fi' >> /etc/update-motd.d/97-overlayroot
+		#		chmod +x /etc/update-motd.d/97-overlayroot
+		#		dialog --title "Root overlay" --backtitle "$BACKTITLE" --yes-label "Reboot" \
+		#		--no-label "Cancel" --yesno "\nEnable virtual read-only root and reboot." 7 45
+		#		[[ ! -f /etc/overlayroot.conf ]] && cp /etc/overlayroot.conf.dpkg-new /etc/overlayroot.conf
+		#		[[ $? = 0 ]] && sed -i "s/^overlayroot=.*/overlayroot=\"tmpfs\"/" /etc/overlayroot.conf && reboot
+		#	fi
+		#fi
+
+		CONFIG_FILE="/etc/overlayroot.conf"
+
+		if findmnt -n -o SOURCE / | grep -q "overlayroot"; then
+			CONFIG_FILE="/media/root-ro/etc/overlayroot.conf"
+			OVERLAY_ACTIVE=1
+		else
+			if ! is_package_manager_running; then
+				if ! dpkg -l | grep -q "overlayroot"; then
+					debconf-apt-progress -- apt-get update
+					if [[ "$DISTROID" == "bookworm" ]]; then
+						cat <<-'EOF' > /usr/share/initramfs-tools/hooks/custom
+						cp /bin/grep "${DESTDIR}"/bin
+						cp /bin/mount "${DESTDIR}"/bin
+						cp /lib/aarch64-linux-gnu/libmount.so.1 "${DESTDIR}"/lib
+						EOF
+						chmod +x /usr/share/initramfs-tools/hooks/custom
+						export PATH=$PATH:/usr/sbin
+						update-initramfs -u > /dev/null 2>&1
+					fi
+					apt -y install overlayroot > /dev/null 2>&1
+					[[ ! $? == 0 ]] && apt remove --purge -y overlayroot >/dev/null 2>&1 && return
+				fi
 			else
-				debconf-apt-progress -- apt-get -o Dpkg::Options::="--force-confnew" -y --no-install-recommends install overlayroot
-				echo '#!/bin/bash' > /etc/update-motd.d/97-overlayroot
-				echo 'if [ -n "$(mount | grep -w tmpfs-root)" ]; then \
-				echo -e "[\e[0m \e[1mremember: your system is in virtual read only mode\e[0m ]\n";fi' >> /etc/update-motd.d/97-overlayroot
-				chmod +x /etc/update-motd.d/97-overlayroot
-				dialog --title "Root overlay" --backtitle "$BACKTITLE" --yes-label "Reboot" \
-				--no-label "Cancel" --yesno "\nEnable virtual read-only root and reboot." 7 45
-				[[ ! -f /etc/overlayroot.conf ]] && cp /etc/overlayroot.conf.dpkg-new /etc/overlayroot.conf
-				[[ $? = 0 ]] && sed -i "s/^overlayroot=.*/overlayroot=\"tmpfs\"/" /etc/overlayroot.conf && reboot
+				return
 			fi
+
+			OVERLAY_ACTIVE=0
+		fi
+
+		CURRENT_MODE="none"
+		CURRENT_DEVICE="N/A"
+
+		if grep -q '^overlayroot="tmpfs"' "$CONFIG_FILE" 2>/dev/null; then
+			CURRENT_MODE="tmpfs"
+		elif grep -q '^overlayroot="device:dev=' "$CONFIG_FILE" 2>/dev/null; then
+			CURRENT_MODE="block"
+			CURRENT_DEVICE=$(grep -oP '(?<=overlayroot="device:dev=).*?(?=")' "$CONFIG_FILE")
+		elif grep -q '^overlayroot=""' "$CONFIG_FILE" 2>/dev/null; then
+			CURRENT_MODE="none"
+		fi
+
+		ALL_PARTITIONS=$(lsblk -lnp -o NAME,TYPE | awk '$2=="part" {print $1}' | grep -E '/dev/(mmcblk|nvme|sd)')
+		MOUNTED_PARTITIONS=$(findmnt -n -o SOURCE)
+		ROOT_SOURCE=$(findmnt -n -o SOURCE /)
+		[[ $OVERLAY_ACTIVE == "1" ]] && ROOT_SOURCE=$(findmnt -n -o SOURCE /media/root-ro)
+		ROOT_DEVICE=${ROOT_SOURCE%%p*}
+		ROOT_PARTITION=${ROOT_SOURCE##*p}
+		MENU_OPTIONS=()
+		for PART in $ALL_PARTITIONS; do
+			if ! grep -q "$PART" <<< "$MOUNTED_PARTITIONS"; then
+				DEVICE_NAME=$(echo "$PART" | sed -E 's/p[0-9]+$//')
+				PARTITION_NUMBER=$(echo "$PART" | grep -o '[0-9]*$')
+
+				if [[ "$DEVICE_NAME" == "$ROOT_DEVICE" && "$PARTITION_NUMBER" -gt "$ROOT_PARTITION" ]]; then
+					MENU_OPTIONS+=("$PART" "Available partition")
+				elif [[ "$DEVICE_NAME" != "$ROOT_DEVICE" ]]; then
+					MENU_OPTIONS+=("$PART" "Available partition")
+				fi
+			fi
+		done
+
+		NEW_PART="${ROOT_DEVICE}p$((ROOT_PARTITION + 1))"
+		if ! grep -q "$NEW_PART" <<< "$ALL_PARTITIONS"; then
+			MENU_OPTIONS+=("$NEW_PART" "Potential new partition (p$((ROOT_PARTITION + 1)))")
+		fi
+
+		MENU_ITEMS=(
+			"none"  "disable overlayroot $( [ "$CURRENT_MODE" = "none" ] && echo "(active)" )"
+			"tmpfs" "tmpfs mode $( [ "$CURRENT_MODE" = "tmpfs" ] && echo "(active)" )"
+			"block" "block device mode $( [ "$CURRENT_MODE" = "block" ] && echo "(active: $CURRENT_DEVICE)" )"
+		)
+		CHOICE=$(dialog --clear --title "Overlayroot Configuration" --default-item "$CURRENT_MODE" \
+			--menu "\nChoose the storage mode:" 12 60 3 "${MENU_ITEMS[@]}" 3>&1 1>&2 2>&3)
+
+		clear
+
+		if [ "$OVERLAY_ACTIVE" -eq 1 ]; then
+			#echo "Remounting /media/root-ro as read-write..."
+			mount -o remount,rw /media/root-ro
 		fi
+
+		case "$CHOICE" in
+			"none")
+				sed -i "s/^overlayroot=.*/overlayroot=\"\"/" "$CONFIG_FILE"
+				if ! grep -q "overlayroot" "$CONFIG_FILE"; then echo "overlayroot=\"\"" >> "$CONFIG_FILE"; fi
+				dialog --title "Root overlay" --backtitle "$BACKTITLE" --yes-label "Reboot" \
+					--no-label "Cancel" --yesno "\nDisable overlayroot and reboot." 7 45
+				[[ $? == 0 ]] && reboot
+				;;
+			"tmpfs")
+				sed -i "s/^overlayroot=.*/overlayroot=\"$CHOICE\"/" "$CONFIG_FILE"
+				if ! grep -q "overlayroot" "$CONFIG_FILE"; then echo "overlayroot=$CHOICE" >> "$CONFIG_FILE"; fi
+				dialog --title "Root overlay" --backtitle "$BACKTITLE" --yes-label "Reboot" \
+					--no-label "Cancel" --yesno "\nEnable overlayroot and reboot." 7 45
+				[[ $? == 0 ]] && reboot
+				;;
+			"block")
+				if [ ${#MENU_OPTIONS[@]} -eq 0 ]; then
+					DEVICE=$(dialog --inputbox "No available partitions detected.\nEnter a block device path manually:" 10 50 "/dev/mmcblk0p2" 3>&1 1>&2 2>&3)
+				else
+					DEVICE=$(dialog --menu "Select a block device for storage:" 10 60 5 "${MENU_OPTIONS[@]}" 3>&1 1>&2 2>&3)
+				fi
+				clear
+				if [ -n "$DEVICE" ]; then
+					sed -i "s|^overlayroot=.*|overlayroot=\"device:dev=$DEVICE\"|" "$CONFIG_FILE"
+					if ! grep -q "overlayroot" "$CONFIG_FILE"; then echo "overlayroot=\"device:dev=$DEVICE\"" >> "$CONFIG_FILE"; fi
+					sync
+					#echo "Overlayroot set to block device mode using $DEVICE."
+
+					if [ "$DEVICE" = "$NEW_PART" ]; then
+
+						if [[ -b "$DEVICE" ]]; then
+							if [[ "$(lsblk -no FSTYPE $DEVICE)" != "ext4" ]]; then
+								dialog --yesno "Warning: format $DEVICE as ext4? This will erase all data." 10 50
+								[[ $? -eq 0 ]] && yes|mkfs.ext4 "$DEVICE"
+								dialog --title "Root overlay" --backtitle "$BACKTITLE" --yes-label "Reboot" \
+									--no-label "Cancel" --yesno "\nEnable overlayroot and reboot." 7 45
+								[[ $? == 0 ]] && reboot
+							else
+								dialog --title "Root overlay" --backtitle "$BACKTITLE" --yes-label "Reboot" \
+									--no-label "Cancel" --yesno "\nEnable overlayroot and reboot." 7 45
+								[[ $? == 0 ]] && reboot
+							fi
+							return
+						fi
+
+						dialog --yesno "Warning: Creating a new partition ($DEVICE) may destroy existing data." 10 50
+						[[ ! $? -eq 0 ]] && return
+						rootfs_size=$(df -BM | grep ^/dev | head -1 | awk '{print $3}' | tr -cd '[0-9]. \n')
+						sdsize=$(bc -l <<< "scale=0; ((($rootfs_size * 2) / 1 + 0) / 4 + 1) * 4")
+						#echo "sdsize: $sdsize"
+						rootsource=$ROOT_SOURCE
+						rootdevice=${rootsource%p*}
+						partitions=${rootsource##*p}
+						lastsector=$(fdisk -l ${rootdevice} |grep "Disk ${rootdevice}" |awk '{print $7}')
+						lastsector=$(( $lastsector - 1024 ))
+						startfrom=$(fdisk -l ${rootdevice} |grep ${rootsource} |awk '{print $2}')
+						partend=$(fdisk -l ${rootdevice} |grep ${rootsource} |awk '{print $3}')
+						new_part_size=$(($sdsize * 1024 * 1024 / 512))
+						new_partend=$((${new_part_size} + ${startfrom} -1))
+						new_partstart=$((${new_partend}+1))
+						LOOP=$(losetup -f)
+						losetup ${LOOP} ${rootsource}
+						e2fsck -f -y ${LOOP}
+						resize2fs ${LOOP} $((${new_part_size} / 8))
+						(echo d; echo $partitions; echo n; echo p; echo ; echo $startfrom; echo $new_partend ; echo w;)| fdisk $rootdevice
+						(echo n; echo p; echo ;echo $new_partstart; echo $lastsector; echo w;)| fdisk $rootdevice
+						e2fsck -f -y ${LOOP}
+						yes |mkfs.ext4 $DEVICE
+						sync
+						losetup -d ${LOOP}
+						dialog --title "Root overlay" --backtitle "$BACKTITLE" --yes-label "Reboot" \
+							--no-label "Cancel" --yesno "\nEnable overlayroot and reboot." 7 45
+						[[ $? == 0 ]] && reboot
+
+					else
+						#if [[ "$(lsblk -no FSTYPE /dev/sda2)" != "ext4" ]]; then
+						dialog --yesno "Warning: format $DEVICE as ext4? This will erase all data." 10 50
+						[[ $? -eq 0 ]] && yes|mkfs.ext4 "$DEVICE"
+						dialog --title "Root overlay" --backtitle "$BACKTITLE" --yes-label "Reboot" \
+							--no-label "Cancel" --yesno "\nEnable overlayroot and reboot." 7 45
+						[[ $? == 0 ]] && reboot
+						#fi
+					fi
+
+				else
+					:
+				fi
+				;;
+			*)
+				:
+				;;
+		esac
+		sync
 	;;
 
 

+ 9 - 8
external/cache/sources/orangepi-config/debian-config-submenu

@@ -109,14 +109,15 @@ while true; do
 	fi
 
 	# overlayroot
-	if [[ "$DISTRO" == "Ubuntu" && "$(modinfo overlay > /dev/null 2>&1; echo $?)" == "0" ]]; then
-		if [ -n "$(mount | grep -w tmpfs-root)" ]; then
-			:
-			#LIST+=( "Overlayroot" "Disable virtual read-only root filesystem" )
-		else
-			:
-			#LIST+=( "Overlayroot" "Enable virtual read-only root filesystem" )
-		fi
+	if [[ "$DISTRO" =~ "Ubuntu"|"Debian" && "$(modinfo overlay > /dev/null 2>&1; echo $?)" == "0" ]]; then
+		#if [ -n "$(mount | grep -w tmpfs-root)" ]; then
+		#	:
+		#	#LIST+=( "Overlayroot" "Disable virtual read-only root filesystem" )
+		#else
+		#	:
+		#	#LIST+=( "Overlayroot" "Enable virtual read-only root filesystem" )
+		#fi
+		LIST+=( "Overlayroot" "Enable or disable a overlay filesystem." )
 	fi
 
 	# count number of menu items to adjust window size

+ 250 - 0
external/packages/bsp/common/usr/sbin/opi-bkimg

@@ -0,0 +1,250 @@
+#!/bin/bash
+
+OFFSET=30
+image=/mnt/backup.img
+type=83
+next=$OFFSET
+rootpart=1
+ROOTFS_TYPE=ext4
+bootfs=
+logfile="/var/log/backup.log"
+# script configuration
+CWD="/usr/lib/nand-sata-install"
+EX_LIST="${CWD}/exclude.txt"
+[[ -f /usr/lib/u-boot/platform_install.sh ]] && source /usr/lib/u-boot/platform_install.sh
+[[ -f /etc/orangepi-release ]] && source /etc/orangepi-release
+
+if [[ $EUID -ne 0 ]]; then
+	echo 'This tool must run as root. Exiting ...' >&2
+	exit 14
+fi
+
+[[ -f "$image" ]] && rm "$image"
+
+# define makefs and mount options
+declare -A mkopts mountopts
+# for ARMv7 remove 64bit feature from default mke2fs format features
+if [[ $LINUXFAMILY =~ sun50iw6|sun50iw2|sun50iw1 && $BRANCH == legacy ]]; then
+	mkopts[ext2]='-O ^64bit -qF'
+	mkopts[ext3]='-O ^64bit -qF'
+	mkopts[ext4]='-O ^64bit -qF'
+else
+	mkopts[ext2]='-qF'
+	mkopts[ext3]='-qF'
+	mkopts[ext4]='-qF'
+fi
+mkopts[btrfs]='-f'
+mkopts[f2fs]='-f'
+
+mountopts[ext2]='defaults,noatime,commit=600,errors=remount-ro,x-gvfs-hide	0	1'
+mountopts[ext3]='defaults,noatime,commit=600,errors=remount-ro,x-gvfs-hide	0	1'
+mountopts[ext4]='defaults,noatime,commit=600,errors=remount-ro,x-gvfs-hide	0	1'
+mountopts[btrfs]='defaults,noatime,commit=600,compress=lzo,x-gvfs-hide			0	2'
+mountopts[f2fs]='defaults,noatime,x-gvfs-hide	0	2'
+
+
+function display_alert()
+{
+
+        local tmp=""
+        [[ -n $2 ]] && tmp="[\e[0;33m $2 \x1B[0m]"
+
+        case $3 in
+                err)
+                echo -e "[\e[0;31m error \x1B[0m] $1 $tmp"
+                ;;
+
+                wrn)
+                echo -e "[\e[0;35m warn \x1B[0m] $1 $tmp"
+                ;;
+
+                ext)
+                echo -e "[\e[0;32m o.k. \x1B[0m] \e[1;32m$1\x1B[0m $tmp"
+                ;;
+
+                info)
+                echo -e "[\e[0;32m o.k. \x1B[0m] $1 $tmp"
+                ;;
+
+                *)
+                echo -e "[\e[0;32m .... \x1B[0m] $1 $tmp"
+                ;;
+        esac
+}
+
+stop_running_services()
+{
+	systemctl --state=running | awk -F" " '/.service/ {print $1}' | sort -r | \
+		grep -E -e "$1" | while read ; do
+		echo -e "\nStopping ${REPLY} \c"
+		systemctl stop ${REPLY} 2>&1
+	done
+}
+
+display_alert "Starting backup to image" "$image" "info"
+
+rootfs_size=$(df -BM | grep ^/dev | head -1 | awk '{print $3}' | tr -cd '[0-9]. \n')
+display_alert "Current rootfs size" "$rootfs_size MiB" "info"
+
+imagesize=$(($rootfs_size + $OFFSET))
+sdsize=$(bc -l <<< "scale=0; ((($imagesize * 1.35) / 1 + 0) / 4 + 1) * 4")
+
+mnt_free=$(df -BM /mnt | grep ^/dev | head -1 | awk '{print $4}' | tr -cd '[0-9]. \n')
+
+if [ "$mnt_free" -lt "$sdsize" ]; then
+	display_alert "Not enough space in /mnt" "Required: ${sdsize}MiB, Available: ${mnt_free}MiB" "err"
+	exit 1
+fi
+
+cleanup() {
+	if [[ -d "${TempDir}" ]] && findmnt -r "${TempDir}/rootfs" > /dev/null; then
+		display_alert "Unmounting" "${TempDir}/rootfs" "info"
+		umount "${TempDir}"/bootfs
+		umount "${TempDir}"/rootfs
+		rm -r ${TempDir}
+		losetup -d $LOOP
+	fi
+
+	[[ -d "${TempDir}" ]] && rm "${TempDir}"
+
+	exit
+}
+
+trap cleanup EXIT INT
+
+display_alert "Creating blank image for rootfs" "$sdsize MiB" "info"
+dd if=/dev/zero bs=1M status=none count=$sdsize | pv -p -b -r -s $(($sdsize * 1024 * 1024)) -N "[ .... ] dd" | dd status=none of=$image
+
+display_alert "Creating partitions" "${bootfs:+/boot: $bootfs }root: $ROOTFS_TYPE" "info"
+{
+	echo "$rootpart : name=\"rootfs\", start=${next}MiB, type=${type}"
+} | sfdisk $image >> "$logfile" 2>&1
+
+LOOP=$(losetup -f)
+[[ -z $LOOP ]] && echo "error" && exit
+
+losetup $LOOP $image
+
+partprobe $LOOP
+
+rootdevice="${LOOP}p${rootpart}"
+
+display_alert "Creating rootfs" "$ROOTFS_TYPE on $rootdevice"
+
+mkfs.ext4 -q -m 2 -O '^64bit,^metadata_csum' -L opi_root $rootdevice
+
+[[ $ROOTFS_TYPE == ext4 ]] && tune2fs -o journal_data_writeback $rootdevice > /dev/null
+
+TempDir=$(mktemp -d /mnt/${0##*/}.XXXXXX || exit 2)
+
+sync && mkdir -p "${TempDir}"/bootfs "${TempDir}"/rootfs
+
+( mount -o compress-force=zlib "${rootdevice}" "${TempDir}"/rootfs 2> /dev/null || mount "${rootdevice}" "${TempDir}"/rootfs )
+mount  $rootdevice "${TempDir}"/bootfs
+
+# stop running services
+echo -e "\nFiles currently open for writing:" >> $logfile
+lsof / | awk 'NR==1 || $4~/[0-9][uw]/' | grep -v "^COMMAND" >> $logfile
+echo -e "\nTrying to stop running services to minimize open files:\c" >> $logfile
+stop_running_services "nfs-|smbd|nmbd|winbind|ftpd|netatalk|monit|cron|webmin|rrdcached" >> $logfile
+stop_running_services "fail2ban|ramlog|folder2ram|postgres|mariadb|mysql|postfix|mail|nginx|apache|snmpd" >> $logfile
+pkill dhclient 2>/dev/null
+LANG=C echo -e "\n\nChecking again for open files:" >> $logfile
+lsof / | awk 'NR==1 || $4~/[0-9][uw]/' | grep -v "^COMMAND" >> $logfile
+
+TODO=$(rsync -ahvrltDn --delete --stats --exclude-from=$EX_LIST / "${TempDir}"/rootfs | grep "Number of files:"|awk '{print $4}' | tr -d '.,')
+echo -e "\nCopying ${TODO} files to $rootdevice. \c" >> $logfile
+#display_alert "Copying ${TODO} files to" "/"
+
+# creating rootfs
+# Speed copy increased x10
+ # Variables for interfacing with rsync progress
+nsi_conn_path="${TempDir}/nand-sata-install"
+nsi_conn_done="${nsi_conn_path}/done"
+nsi_conn_progress="${nsi_conn_path}/progress"
+mkdir -p "${nsi_conn_path}"
+echo 0 >"${nsi_conn_progress}"
+echo no >"${nsi_conn_done}"
+
+ # Launch rsync in background
+{ \
+rsync -avrltD --delete --exclude-from=$EX_LIST / "${TempDir}"/rootfs | \
+nl | awk '{ printf "%.0f\n", 100*$1/"'"$TODO"'" }' \
+> "${nsi_conn_progress}" ;
+ # save exit code from rsync
+echo  ${PIPESTATUS[0]} >"${nsi_conn_done}"
+} &
+
+ # while variables
+rsync_copy_finish=0
+rsync_progress=0
+prev_progress=0
+rsync_done=""
+while [ "${rsync_copy_finish}" -eq 0 ]; do
+        # Sometimes reads the progress file while writing and only partial numbers (like 1 when is 15)
+        prev_progress=${rsync_progress}
+        rsync_progress=$(tail -n1 "${nsi_conn_progress}")
+        if [[ -z ${rsync_progress} ]]; then
+                rsync_progress=${prev_progress}
+        fi
+        if [ ${prev_progress} -gt ${rsync_progress} ]; then
+                rsync_progress=${prev_progress}
+        fi
+
+        echo "${rsync_progress}"
+        # finish the while if the rsync is finished
+        rsync_done=$(cat ${nsi_conn_done})
+        if [[ "${rsync_done}" != "no" ]]; then
+                if [[ ${rsync_done} -eq 0 ]]; then
+                        rm -rf "${nsi_conn_path}"
+                        rsync_copy_finish=1
+                else
+                        # if rsync return error
+                        echo "Error: could not copy rootfs files, exiting"
+                        exit 4
+                fi
+        else
+                sleep 0.5
+        fi
+
+done | \
+while read i; do
+    width=30
+    num_hash=$((i * width / 100))
+    bar=$(printf "%-${width}s" "#" | tr ' ' '#')
+    printf "\r[\e[0;32m .... \x1B[0m] Copying "$TODO" file to [\e[0;33m / \x1B[0m] [%-${width}s] %3d%%" "${bar:0:num_hash}" "$i"
+done
+echo ""
+
+#pv -l -s 100 -p  -e -N "[ .... ] Copying 48304 files to [ / ]" > /dev/null
+
+#rsync --info=progress2 -arltD --delete --exclude-from=$EX_LIST / "${TempDir}"/rootfs
+
+rsync -avrltD --delete --exclude-from=$EX_LIST / "${TempDir}"/rootfs >/dev/null 2>&1
+
+display_alert "Re-enabling" "orangepi-resize-filesystem"
+chroot ${TempDir}/rootfs/ /bin/bash -c "systemctl --quiet enable orangepi-resize-filesystem" 2>&1 > /dev/null
+
+rm -f "${TempDir}"/rootfs/etc/fstab
+# Restore TMP and swap
+echo "# <file system>					<mount point>	<type>	<options>							<dump>	<pass>" > "${TempDir}"/rootfs/etc/fstab
+echo "tmpfs						/tmp		tmpfs	defaults,nosuid							0	0" >> "${TempDir}"/rootfs/etc/fstab
+grep swap /etc/fstab >> "${TempDir}"/rootfs/etc/fstab
+
+cp -R /boot "${TempDir}"/bootfs
+targetuuid=$(blkid -o export $rootdevice | grep -w UUID)
+
+sed -e 's,rootdev=.*,rootdev='"$targetuuid"',g' -i "${TempDir}"/bootfs//boot/orangepiEnv.txt
+grep -q '^rootdev' "${TempDir}"/bootfs/boot/orangepiEnv.txt || echo "rootdev=$targetuuid" >> "${TempDir}"/bootfs/boot/orangepiEnv.txt
+echo "$targetuuid       /               $ROOTFS_TYPE     ${mountopts[$ROOTFS_TYPE]}" >> "${TempDir}"/rootfs/etc/fstab
+
+
+if [[ $(type -t write_uboot_platform) != function ]]; then
+	display_alert "no u-boot package found" "write bootloader"
+	exit
+fi
+
+display_alert "Writing U-boot bootloader" "$LOOP" "info"
+write_uboot_platform "$DIR" $LOOP
+
+display_alert "Backup completed" "${image}" "info"