sonic-buildimage/installer/sharch_body.sh
Lijitha ck 75cc701e5d Support for updating tmpfs size according to Image size (#7484)
#### Why I did it
while sonic upgrade, Image will be extracted to tmpfs for installation so tmpfs size should be larger than image size. Image installation will fail if image size is larger than tmpfs size.

we are facing below error while installing debug image with size greater than tmpfs which is 1.5g in marvell armhf platform.

sonic-installer install <url>
New image will be installed, continue? [y/N]: y
Downloading image...
...99%, 1744 MB, 708 KB/s, 0 seconds left...
Installing image SONiC-OS-202012.0-dirty-20210311.224845 and setting it as default...
Command: bash /tmp/sonic_image
tar: installer/fs.zip: Wrote only 7680 of 10240 bytes
tar: installer/onie-image-arm64.conf: Cannot write: No space left on device
tar: Exiting with failure status due to previous errors
Verifying image checksum ... OK.
Preparing image archive ...

#### How I did it
compare downloaded image size with tmpfs size, if size less than image size update the tmpfs size according to image size.

#### How to verify it
Install an Image with size larger than tmpfs. we verified by installing debug image with size 1.9gb which is larger than tmpfs size 1.5gb.
2021-09-13 03:25:32 +00:00

71 lines
1.9 KiB
Bash

#!/bin/sh
# Copyright (C) 2013 Curt Brune <curt@cumulusnetworks.com>
#
# SPDX-License-Identifier: GPL-2.0
##
## Shell archive template
##
## Strings of the form %%VAR%% are replaced during construction.
##
echo -n "Verifying image checksum ..."
sha1=$(sed -e '1,/^exit_marker$/d' "$0" | sha1sum | awk '{ print $1 }')
payload_sha1=%%IMAGE_SHA1%%
if [ "$sha1" != "$payload_sha1" ] ; then
echo
echo "ERROR: Unable to verify archive checksum"
echo "Expected: $payload_sha1"
echo "Found : $sha1"
exit 1
fi
echo " OK."
image_size_in_kb=$((($(sed -e '1,/^exit_marker$/d' "$0" | tar --to-stdout -xf - | wc -c) + 1023 ) / 1024))
# Untar and launch install script in a tmpfs
cur_wd=$(pwd)
export cur_wd
archive_path=$(realpath "$0")
tmp_dir=$(mktemp -d)
if [ "$(id -u)" = "0" ] ; then
mount -t tmpfs tmpfs-installer $tmp_dir || exit 1
mount_size_in_kb=$(df $tmp_dir | tail -1 | tr -s ' ' | cut -d' ' -f4)
#checking extra 100KB space in tmp_dir, after image extraction
padding=102400
if [ "$mount_size_in_kb" -le "$((image_size_in_kb + padding))" ]; then
image_size_in_mb=$(((image_size_in_kb + 1023) / 1024))
#Adding extra 32MB free space for image extraction.
mount_size_in_mb=$((((image_size_in_mb + 31) / 32) * 32))
mount -o remount,size="${mount_size_in_mb}M" -t tmpfs tmpfs-installer $tmp_dir || exit 1
fi
fi
cd $tmp_dir
echo -n "Preparing image archive ..."
sed -e '1,/^exit_marker$/d' $archive_path | tar xf - || exit 1
echo " OK."
cd $cur_wd
if [ -n "$extract" ] ; then
# stop here
echo "Image extracted to: $tmp_dir"
if [ "$(id -u)" = "0" ] && [ ! -d "$extract" ] ; then
echo "To un-mount the tmpfs when finished type: umount $tmp_dir"
fi
exit 0
fi
$tmp_dir/installer/install.sh
rc="$?"
# clean up
if [ "$(id -u)" = "0" ] ; then
umount $tmp_dir
fi
rm -rf $tmp_dir
exit $rc
exit_marker