Handle persistent_size variations for subcloud install

The persistent_size variable is passed in via the dcmanager
install-values file, allowing the customer to specify
a non-default size for the platform-backup partition.
Default size is 30000 MiB.

When deviating from the default size we must handle the
following installation cases:

1. New Partition
- persistent_size must be >= default (30000 MiB)

2. Existing Partition
- persistent_size must be >= default (30000 MiB)
- persistent_size must be >= existing partition size
- if persistent_size > existing, then we must also
  extend the filesystem to match the new persistent_size

Story: 2010118
Task: 46698

Test Plan:

PASS:
- Fail installation if persistent_size is < default
- New Partition:
    - Installation with unspecified persistent_size
    - Installation with specified persistent_size == default value
    - Installation with specified persistent_size > default
- Existing Partition:
    - Installation with unspecified persistent_size
    - Installation with specified persistent_size == default value
    - Fail installation if persistent_size is < existing partition size
    - Installation with specified persistent_size > default
        - Verify that existing filesystem is extended to match
          new partition size

Signed-off-by: Kyle MacLeod <kyle.macleod@windriver.com>
Change-Id: I8d06ee585ad96acf1076d4b140d7c516a17f15ea
This commit is contained in:
Kyle MacLeod 2022-11-01 09:06:22 -04:00
parent 81142e5b00
commit c9fbb076db
1 changed files with 45 additions and 5 deletions

View File

@ -908,6 +908,7 @@ export insturl_orig=""
# Assume there is no Platform Backup (persistent) Partition
export BACKUP_PART_FOUND=0
export BACKUP_PART_CURRENT_SIZE=0
export STOR_DEV_FDS=""
@ -1462,6 +1463,9 @@ do
ilog "Looking for platform-backup partition on $part from ... instdev=${INSTDEV} device=${by_dev}"
sgdisk_part_info=$(sgdisk -i $part_number $dev)
part_type_guid=$(echo "$sgdisk_part_info" | grep "$part_type_guid_str" | awk '{print $4;}')
dlog "Examining part_number=${part_number}, by_dev=${by_dev}, dev=${dev}, part_type_guid: ${part_type_guid}"
dlog "sgdisk_part_info: ${sgdisk_part_info}"
dlog "BACKUP_PART_GUID: ${BACKUP_PART_GUID}"
if [ "$dev" == "${by_dev}" -a "$part_type_guid" == $BACKUP_PART_GUID ] ; then
part_type_name=$(echo "$sgdisk_part_info" | grep "$part_type_name_str" | awk '{print $3,$4;}')
BACKUP_PART_NAME=${part_type_name:1:-1}
@ -1485,8 +1489,9 @@ do
if [ "${part_number}" == "${BACKUP_PART_NO}" ] ; then
part_fstype=$(exec_retry 5 0.5 "blkid -s TYPE -o value $part")
if [ "${part_fstype}" == "ext4" ]; then
ilog "Discovered persistent backup partition, ${part}, is in the expected location and is formatted correctly. Maintaining..."
BACKUP_PART_CURRENT_SIZE=$(parted -s ${part} unit MiB print | grep ${part} | awk '{print $3}' | sed 's/[^C0-9]*//g')
BACKUP_PART_FOUND=1
ilog "Discovered persistent backup partition, ${part} [${BACKUP_PART_CURRENT_SIZE} MiB], is in the expected location and is formatted correctly. Maintaining..."
continue
else
ilog "Discovered persistent backup partition, ${part}, has a missing 'ext4' filesystem . Recreating..."
@ -1713,7 +1718,13 @@ if [ "${controller}" = true ] ; then
fi
# Only controllers have a persistent backup partition
export BACKUP_SIZE=${BACKUP_DEFAULT_PERSISTENT_SIZE}
# Use current partition size if it has been detected
if [ ${BACKUP_PART_CURRENT_SIZE} -gt 0 ]; then
BACKUP_SIZE=${BACKUP_PART_CURRENT_SIZE}
else
BACKUP_SIZE=${BACKUP_DEFAULT_PERSISTENT_SIZE}
fi
export BACKUP_SIZE
# Check for a bootline override and allocate platform backup partition
if [ -z "$persistent_size" ]; then
@ -1721,9 +1732,23 @@ if [ "${controller}" = true ] ; then
ilog "Platform Backup persistent size not on command line ; defaulting to ${BACKUP_SIZE}"
else
if [ ${persistent_size} -lt ${BACKUP_SIZE} ] ; then
wlog "Cannot set persistent_size smaller than default size of ${BACKUP_SIZE} KB"
report_failure_with_msg "Cannot set persistent_size smaller than ${BACKUP_SIZE} MiB"
else
export BACKUP_SIZE=${persistent_size}
ilog "Using Platform Backup persistent size from boot command: ${persistent_size}"
BACKUP_SIZE=${persistent_size}
fi
fi
backup_part_extension_required=0
if [ ${BACKUP_PART_CURRENT_SIZE} -gt 0 ]; then
# Reconcile current backup partition size against BACKUP_SIZE
if [ ${BACKUP_SIZE} -eq ${BACKUP_PART_CURRENT_SIZE} ] ; then
ilog "Platform Backup partition size is unchanged: ${BACKUP_SIZE} MiB."
elif [ ${BACKUP_SIZE} -gt ${BACKUP_PART_CURRENT_SIZE} ] ; then
# We need to extend the existing partition - this is done after the partitions are recreated
backup_part_extension_required=1
else
# Do not allow shrinking of backup partition
report_failure_with_msg "Cannot shrink platform backup smaller than existing ${BACKUP_PART_CURRENT_SIZE} MiB"
fi
fi
ilog "Platform Backup partition size: ${BACKUP_SIZE}"
@ -1733,6 +1758,7 @@ if [ "${controller}" = true ] ; then
else
ilog "Platform Backup Partition was detected: PERSISTING"
fi
dlog "BACKUP_SIZE=${BACKUP_SIZE} after persistent_size=${persistent_size}, backup_part_extension_required=${backup_part_extension_required}"
end_sec=$(($start_sec+(${BACKUP_SIZE}*${MIB_BYTES}/${LOGICAL_SECTOR_SZ})-1))
sgdisk_parts="$sgdisk_parts -n $part_no:$start_sec:$end_sec -c $part_no:${BACKUP_PART_LABEL} -t $part_no:${BACKUP_PART_GUID}"
@ -1796,10 +1822,24 @@ STOR_DEVS=$(echo "$STOR_DEVS" | xargs -n 1 | sort -u | xargs)
[ -z "$STOR_DEVS" ] && report_failure_with_msg "No storage devices available."
ilog "STOR_DEV_FDS Updated ; $STOR_DEV_FDS"
# CREATE PARTITIONS
dlog "Requesting ${dev} Partition Table: ${a}"
dlog "Executing: sgdisk ${sgdisk_parts} -p ${dev}"
sgdisk $sgdisk_parts -p ${dev}
[ $? -ne 0 ] && report_failure_with_msg "sgdisk failed to create partitions: ${a}"
rc=$?
[ ${rc} -ne 0 ] && report_failure_with_msg "sgdisk failed to create partitions: ${a} [rc=${rc}]"
if [ "${backup_part_extension_required}" -ne 0 ]; then
# The backup partition has been increased via persistent_size.
# Extend the partition and resize the FS
wlog "Platform Backup partition: resizing ${BACKUP_PART} from ${BACKUP_PART_CURRENT_SIZE}MiB to ${BACKUP_SIZE}MiB"
e2fsck -p -f ${BACKUP_PART}
rc=$?
[ ${rc} -ne 0 ] && report_failure_with_msg "e2fsck failed on platform backup partition [rc=${rc}]"
resize2fs -f ${BACKUP_PART}
rc=$?
[ ${rc} -ne 0 ] && report_failure_with_msg "Failed to resize ext4 fs of platform backup partition [rc=${rc}]"
fi
true
%end