From: Jacek Kryszyn Date: Wed, 3 Apr 2024 14:16:11 +0000 (+0200) Subject: Clone partitions using head instead of dd X-Git-Tag: accepted/tizen/unified/20240430.020633~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=826b0c40b3efb37a3c51d3a1fa2f80eecdb5dc23;p=platform%2Fcore%2Fsystem%2Fupgrade.git Clone partitions using head instead of dd Instead of cloning partitions (whole disks) using dd, head -c $part_size is used to copy only necessary bytes. This can be much faster in case of partitions placed on much bigger disks. Change-Id: Ie15b9f543bac8ef351ef0a4ed4e9adfd148cf704 --- diff --git a/scripts/upgrade-support/upgrade-common.inc b/scripts/upgrade-support/upgrade-common.inc index d542590..e53ab46 100644 --- a/scripts/upgrade-support/upgrade-common.inc +++ b/scripts/upgrade-support/upgrade-common.inc @@ -235,6 +235,33 @@ check_used_block_device() { check_if_super } +calculate_size () { + local part=$1 + local info="" + local block_size=0 + local block_count=0 + local size=0 + + untrap + + if info="$(dumpe2fs -h "$part" 2>/dev/null)"; then + retrap + block_size="$(echo "$info" | grep "Block size" | awk '{print $3}')" + block_count="$(echo "$info" | grep "Block count" | awk '{print $3}')" + echo "$((block_size*block_count))" + return 0 + fi + + if size="$(blockdev --getsize64 "$part" 2>/dev/null)"; then + retrap + echo "$size" + return 0 + fi + + retrap + return 1 +} + background_copy() { log "[Info] Background copying A|B partitions for update..." start_duration=$(date +%s) @@ -295,7 +322,8 @@ background_copy() { fi fi else - /bin/dd if="$CURRENT_PARTITION" of="$NEXT_PARTITION" bs=4096 + PART_SIZE="$(calculate_size "$CURRENT_PARTITION")" + head -c "$PART_SIZE" "$CURRENT_PARTITION" > "$NEXT_PARTITION" fi log "[Info] Finished background copy $partition_name from $CURRENT_PARTITION to $NEXT_PARTITION" @@ -310,8 +338,8 @@ background_copy() { NEXT_SHA1=$(head -c "$ROOTFS_CURR_SIZE" "$NEXT_PARTITION" | sha1sum | awk '{print $1}') fi else - CUR_SHA1=$(sha1sum "$CURRENT_PARTITION" | awk '{print $1}') - NEXT_SHA1=$(sha1sum "$NEXT_PARTITION" | awk '{print $1}') + CUR_SHA1=$(head -c "$PART_SIZE" "$CURRENT_PARTITION" | sha1sum | awk '{print $1}') + NEXT_SHA1=$(head -c "$PART_SIZE" "$NEXT_PARTITION" | sha1sum | awk '{print $1}') fi if [ "$CUR_SHA1" == "$NEXT_SHA1" ]; then