diff --git a/installer/arm64/install.sh b/installer/arm64/install.sh index 280d9f200af9..c1e20b62bf42 100755 --- a/installer/arm64/install.sh +++ b/installer/arm64/install.sh @@ -98,7 +98,13 @@ if [ "$install_env" = "onie" ]; then mount_partition elif [ "$install_env" = "sonic" ]; then demo_mnt="/host" - eval running_sonic_revision=$(cat /etc/sonic/sonic_version.yml | grep build_version | cut -f2 -d" ") + # Get current SONiC image (grub/aboot/uboot) + eval running_sonic_revision="$(cat /proc/cmdline | sed -n 's/^.*loop=\/*image-\(\S\+\)\/.*$/\1/p')" + # Verify SONiC image exists + if [ ! -d "$demo_mnt/image-$running_sonic_revision" ]; then + echo "ERROR: SONiC installation is corrupted: path $demo_mnt/image-$running_sonic_revision doesn't exist" + exit 1 + fi # Prevent installing existing SONiC if it is running if [ "$image_dir" = "image-$running_sonic_revision" ]; then echo "Not installing SONiC version $running_sonic_revision, as current running SONiC has the same version" diff --git a/installer/armhf/install.sh b/installer/armhf/install.sh index 53f2fdf99661..c85170ff256e 100755 --- a/installer/armhf/install.sh +++ b/installer/armhf/install.sh @@ -98,7 +98,13 @@ if [ "$install_env" = "onie" ]; then mount_partition elif [ "$install_env" = "sonic" ]; then demo_mnt="/host" - eval running_sonic_revision=$(cat /etc/sonic/sonic_version.yml | grep build_version | cut -f2 -d" ") + # Get current SONiC image (grub/aboot/uboot) + eval running_sonic_revision="$(cat /proc/cmdline | sed -n 's/^.*loop=\/*image-\(\S\+\)\/.*$/\1/p')" + # Verify SONiC image exists + if [ ! -d "$demo_mnt/image-$running_sonic_revision" ]; then + echo "ERROR: SONiC installation is corrupted: path $demo_mnt/image-$running_sonic_revision doesn't exist" + exit 1 + fi # Prevent installing existing SONiC if it is running if [ "$image_dir" = "image-$running_sonic_revision" ]; then echo "Not installing SONiC version $running_sonic_revision, as current running SONiC has the same version" diff --git a/installer/x86_64/install.sh b/installer/x86_64/install.sh index 7c0d311b1a8a..d40dedc9a160 100755 --- a/installer/x86_64/install.sh +++ b/installer/x86_64/install.sh @@ -467,7 +467,13 @@ if [ "$install_env" = "onie" ]; then elif [ "$install_env" = "sonic" ]; then demo_mnt="/host" - eval running_sonic_revision=$(cat /etc/sonic/sonic_version.yml | grep build_version | cut -f2 -d" ") + # Get current SONiC image (grub/aboot/uboot) + eval running_sonic_revision="$(cat /proc/cmdline | sed -n 's/^.*loop=\/*image-\(\S\+\)\/.*$/\1/p')" + # Verify SONiC image exists + if [ ! -d "$demo_mnt/image-$running_sonic_revision" ]; then + echo "ERROR: SONiC installation is corrupted: path $demo_mnt/image-$running_sonic_revision doesn't exist" + exit 1 + fi # Prevent installing existing SONiC if it is running if [ "$image_dir" = "image-$running_sonic_revision" ]; then echo "Not installing SONiC version $running_sonic_revision, as current running SONiC has the same version"