Preserve persistent backup when invalid persistent_size provided

Miniboot wipes the backup-partition when the persistent size
is set to a value less than the existing size. The expectation is
that the install should fail and the contents of platform-backup
should be preserved.

This fix solves the issue by failing the installation during the
ks-early phase, where the provided persistent size value in the
kernel commandline can be read, and no disk operations have been
performed.

Test Plan:
PASS: Verify that installation with valid parameters passes.

PASS: Verify that reinstall fails if persistent_size less
      than the current persistent_size is provided.

PASS: Verify that contents of /opt/platform-backup are preserved
      when persistent_size less than the current size is
      provided.

PASS: Verify that reinstall fails if persistent_size greater
      than the size of the rootfs device is provided.

PASS: Verify that the contents of /opt/platform-backup are
      preserved when persistent-size greater than size of rootfs
      device is provided.

Closes-Bug: 1998932

Signed-off-by: Shrikumar Sharma <shrikumar.sharma@windriver.com>
Change-Id: I51351cb14cdcfa63b4b5839d935589d997b5403a
This commit is contained in:
Shrikumar Sharma 2022-12-06 13:44:11 +00:00
parent 07640af5df
commit b29e8c7345

View File

@ -980,6 +980,32 @@ for arg in $*; do
esac
done
# Handle persistent_size setting.
# If the persistent_size is less than the size of the existing persistent backup,
# then the installation process must terminate and exit.
if [ -n "${persistent_size}" ]; then
part=$(readlink -f "/dev/disk/by-partlabel/platform_backup")
device=$(readlink -f "${rootfs_device}")
ilog "Persistent backup is in ${part}"
MAX_SIZE=$(parted -s ${device} unit MiB print | grep "Disk ${device}:" | awk '{print $3}' | sed 's/[^C0-9]*//g')
CURRENT_PERSISTENT_SIZE=$(parted -s ${part} unit MiB print | grep ${part} | awk '{print $3}' | sed 's/[^C0-9]*//g')
ilog "Current size of persistent backup is ${CURRENT_PERSISTENT_SIZE}"
ilog "Max size of ${device} is ${MAX_SIZE}"
if [ ${persistent_size} -lt ${CURRENT_PERSISTENT_SIZE} ]; then
ilog "Provided persistent_size (${persistent_size}) is less than ${CURRENT_PERSISTENT_SIZE}"
report_failure_with_msg "Persistent size setting is less than current backup size (${CURRENT_PERSISTENT_SIZE})"
fi
if [ ${persistent_size} -gt ${MAX_SIZE} ]; then
ilog "Provided persistent_size (${persistent_size}) is greater than ${MAX_SIZE}"
report_failure_with_msg "Persistent size setting is greater than maximum allowable size (${MAX_SIZE})"
fi
fi
# Note: This is equivalent to pre_disk_setup_common.cfg
# Name : check_execs
@ -1669,12 +1695,8 @@ if [ "${controller}" = true ] ; then
# Default backup partition size in MiB
ilog "Platform Backup persistent size not on command line ; defaulting to ${BACKUP_SIZE}"
else
if [ ${persistent_size} -lt ${BACKUP_SIZE} ] ; then
report_failure_with_msg "Cannot set persistent_size smaller than ${BACKUP_SIZE} MiB"
else
ilog "Using Platform Backup persistent size from boot command: ${persistent_size}"
BACKUP_SIZE=${persistent_size}
fi
ilog "Using Platform Backup persistent size from boot command: ${persistent_size}"
BACKUP_SIZE=${persistent_size}
fi
backup_part_extension_required=0
if [ ${BACKUP_PART_CURRENT_SIZE} -gt 0 ]; then