Replace Etcher with dd + verify, tested under Docker (#1522)

* Replace Etcher with dd + verify, tested under Docker

Signed-off-by: Igor Pecovnik <igor.pecovnik@gmail.com>
This commit is contained in:
Igor Pečovnik 2019-09-01 00:12:36 +02:00 committed by GitHub
parent c042c503b3
commit da903f2d65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 45 deletions

View File

@ -383,7 +383,7 @@ prepare_partitions()
# stage: create blank image
display_alert "Creating blank image for rootfs" "$sdsize MiB" "info"
# truncate --size=${sdsize}M ${SDCARD}.raw # sometimes results in fs corruption, revert to previous know to work solution
dd if=/dev/zero bs=1M status=none count=$sdsize | pv -p -b -r -s $(( $sdsize * 1024 * 1024 )) | dd status=none of=${SDCARD}.raw
dd if=/dev/zero bs=1M status=none count=$sdsize | pv -p -b -r -s $(( $sdsize * 1024 * 1024 )) -N "[ .... ] dd" | dd status=none of=${SDCARD}.raw
# stage: calculate boot partition size
local bootstart=$(($OFFSET * 2048))
@ -635,14 +635,31 @@ create_image()
[[ $(type -t post_build_image) == function ]] && post_build_image "$DEST/images/${version}.img"
# write image to SD card
if [[ $(lsblk "$CARD_DEVICE" 2>/dev/null) && -f $DEST/images/${version}.img && $COMPRESS_OUTPUTIMAGE != yes ]]; then
display_alert "Writing image" "$CARD_DEVICE" "info"
balena-etcher $DEST/images/${version}.img -d $CARD_DEVICE -y
if [ $? -eq 0 ]; then
display_alert "Writing succeeded" "${version}.img" "info"
if [[ $(lsblk "$CARD_DEVICE" 2>/dev/null) && -f $DEST/images/${version}.img ]]; then
# make sha256sum if it does not exists. we need it for comparisson
if [[ -f "$DEST/images/${version}".img.sha ]]; then
local ifsha=$(cat $DEST/images/${version}.img.sha | awk '{print $1}')
else
local ifsha=$(sha256sum -b "$DEST/images/${version}".img | awk '{print $1}')
fi
display_alert "Writing image" "$CARD_DEVICE ${readsha}" "info"
# write to SD card
pv -p -b -r -c -N "[ .... ] dd" $DEST/images/${version}.img | dd of=$CARD_DEVICE bs=1M iflag=fullblock oflag=direct status=none
# read and compare
display_alert "Verifying. Please wait!"
local ofsha=$(dd if=$CARD_DEVICE count=$(du -b $DEST/images/${version}.img | cut -f1) status=none iflag=count_bytes oflag=direct | sha256sum | awk '{print $1}')
if [[ $ifsha == $ofsha ]]; then
display_alert "Writing verified" "${version}.img" "info"
else
display_alert "Writing failed" "${version}.img" "err"
fi
elif [[ `systemd-detect-virt` == 'docker' && -n $CARD_DEVICE ]]; then
# display warning when we want to write sd card under Docker
display_alert "Can't write to $CARD_DEVICE" "Enable docker privileged mode in config-docker.conf" "wrn"
fi
} #############################################################################

View File

@ -19,7 +19,6 @@
# prepare_host
# webseed
# download_and_verify
# download_etcher_cli
# cleaning <target>
#
@ -735,9 +734,6 @@ prepare_host()
fi
done
# download etcher CLI utility
download_etcher_cli
[[ ! -f $USERPATCHES_PATH/customize-image.sh ]] && cp $SRC/config/templates/customize-image.sh.template $USERPATCHES_PATH/customize-image.sh
if [[ ! -f $USERPATCHES_PATH/README ]]; then
@ -913,41 +909,6 @@ download_and_verify()
}
download_etcher_cli()
{
local url="https://github.com/balena-io/etcher/releases/download/v1.4.8/balena-etcher-cli-1.4.8-linux-x64.tar.gz"
local hash="9befa06b68bb5846bcf5a9516785d48d6aaa9364d80a5802deb5b6a968bf5404"
local filename=${url##*/}
local dirname=${filename/.tar.gz/-dist}
export PATH="$PATH:$SRC/cache/utility/$dirname"
if [[ -f $SRC/cache/utility/$dirname/.download-complete ]]; then
return
fi
cd $SRC/cache/utility/
display_alert "Downloading" "$dirname"
curl -Lf --progress-bar $url -o $filename
local verified=false
local b=$(sha256sum $filename)
display_alert "Verifying"
[[ "$hash" == "$(sha256sum $filename | cut -d ' ' -f 1)" ]] && verified=true
if [[ $verified == true ]]; then
display_alert "Extracting"
tar --no-same-owner --overwrite -xf $filename && touch $SRC/cache/utility/$dirname/.download-complete && rm $filename
display_alert "Download complete" "" "info"
else
display_alert "Verification failed" "" "wrn"
fi
}
show_developer_warning()