Skip to content

Commit 5ea0fe9

Browse files
nazariigraphaelt-nvidia
authored andcommitted
[installer]: Prevent filesystem corruption (sonic-net#7264)
This improvement reads current SONiC version directly from `/proc/cmdline`. it supports `grub/aboot/uboot` bootloaders. **Code snippet**: ```bash cat /proc/cmdline | sed -n 's/^.*loop=\/*image-\(\S\+\)\/.*$/\1/p' ``` **Description**: ``` -n don't print lines s substitute ^.* matches anything before the <image_version> loop= matches <loop> kernel parameter \/*image- matches <image_version> prefix \(\S\+\) matches <image_version> group and assigns it to \1 \/.*$ matches anything after the <image_version> \1 replace everything with <image_version> p print it ``` closes sonic-net#6267 #### Why I did it * To fix sonic-net#6267 #### How I did it * Fixed installer scripts #### How to verify it 1. Write invalid SONiC version to sonic_version.yml 2. Run SONiC-To-SONiC update
1 parent 7c7c015 commit 5ea0fe9

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

installer/arm64/install.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,13 @@ if [ "$install_env" = "onie" ]; then
9898
mount_partition
9999
elif [ "$install_env" = "sonic" ]; then
100100
demo_mnt="/host"
101-
eval running_sonic_revision=$(cat /etc/sonic/sonic_version.yml | grep build_version | cut -f2 -d" ")
101+
# Get current SONiC image (grub/aboot/uboot)
102+
eval running_sonic_revision="$(cat /proc/cmdline | sed -n 's/^.*loop=\/*image-\(\S\+\)\/.*$/\1/p')"
103+
# Verify SONiC image exists
104+
if [ ! -d "$demo_mnt/image-$running_sonic_revision" ]; then
105+
echo "ERROR: SONiC installation is corrupted: path $demo_mnt/image-$running_sonic_revision doesn't exist"
106+
exit 1
107+
fi
102108
# Prevent installing existing SONiC if it is running
103109
if [ "$image_dir" = "image-$running_sonic_revision" ]; then
104110
echo "Not installing SONiC version $running_sonic_revision, as current running SONiC has the same version"

installer/armhf/install.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,13 @@ if [ "$install_env" = "onie" ]; then
9898
mount_partition
9999
elif [ "$install_env" = "sonic" ]; then
100100
demo_mnt="/host"
101-
eval running_sonic_revision=$(cat /etc/sonic/sonic_version.yml | grep build_version | cut -f2 -d" ")
101+
# Get current SONiC image (grub/aboot/uboot)
102+
eval running_sonic_revision="$(cat /proc/cmdline | sed -n 's/^.*loop=\/*image-\(\S\+\)\/.*$/\1/p')"
103+
# Verify SONiC image exists
104+
if [ ! -d "$demo_mnt/image-$running_sonic_revision" ]; then
105+
echo "ERROR: SONiC installation is corrupted: path $demo_mnt/image-$running_sonic_revision doesn't exist"
106+
exit 1
107+
fi
102108
# Prevent installing existing SONiC if it is running
103109
if [ "$image_dir" = "image-$running_sonic_revision" ]; then
104110
echo "Not installing SONiC version $running_sonic_revision, as current running SONiC has the same version"

installer/x86_64/install.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,13 @@ if [ "$install_env" = "onie" ]; then
467467
468468
elif [ "$install_env" = "sonic" ]; then
469469
demo_mnt="/host"
470-
eval running_sonic_revision=$(cat /etc/sonic/sonic_version.yml | grep build_version | cut -f2 -d" ")
470+
# Get current SONiC image (grub/aboot/uboot)
471+
eval running_sonic_revision="$(cat /proc/cmdline | sed -n 's/^.*loop=\/*image-\(\S\+\)\/.*$/\1/p')"
472+
# Verify SONiC image exists
473+
if [ ! -d "$demo_mnt/image-$running_sonic_revision" ]; then
474+
echo "ERROR: SONiC installation is corrupted: path $demo_mnt/image-$running_sonic_revision doesn't exist"
475+
exit 1
476+
fi
471477
# Prevent installing existing SONiC if it is running
472478
if [ "$image_dir" = "image-$running_sonic_revision" ]; then
473479
echo "Not installing SONiC version $running_sonic_revision, as current running SONiC has the same version"

0 commit comments

Comments
 (0)