From 7d4d3c78beace5539b9f033ae1b23ef72fef2e50 Mon Sep 17 00:00:00 2001 From: Mihnea Saracin Date: Tue, 12 May 2020 18:33:15 +0300 Subject: [PATCH] Persistent backup partition resizing The persistent backup partition will be resized if it's detected to be smaller than it should be. Story: 2007403 Task: 39548 Change-Id: I6809a7c3a8363c8ee7f26bc9c8d61ed97451d29d Signed-off-by: Mihnea Saracin --- bsp-files/kickstarts/pre_disk_aio.cfg | 19 ++++++++++++++++--- bsp-files/kickstarts/pre_disk_controller.cfg | 19 ++++++++++++++++--- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/bsp-files/kickstarts/pre_disk_aio.cfg b/bsp-files/kickstarts/pre_disk_aio.cfg index 56819432..ef304eb1 100755 --- a/bsp-files/kickstarts/pre_disk_aio.cfg +++ b/bsp-files/kickstarts/pre_disk_aio.cfg @@ -117,7 +117,10 @@ if [ -d /sys/firmware/efi ] ; then BACKUP_PART_NO=1 START_POINT=1 END_POINT=$(($START_POINT + $PLATFORM_BACKUP_SIZE)) - parted -s $ROOTFS_DISK mkpart primary ext4 ${START_POINT}MiB ${END_POINT}MiB + BACKUP_END_POINT=$END_POINT + if [ $BACKUP_CREATED -eq 0 ] ; then + parted -s $ROOTFS_DISK mkpart primary ext4 ${START_POINT}MiB ${END_POINT}MiB + fi START_POINT=$END_POINT END_POINT=$(($START_POINT + $EFI_SIZE)) @@ -133,8 +136,10 @@ else START_POINT=2 END_POINT=$(($START_POINT + $PLATFORM_BACKUP_SIZE)) - parted -s $ROOTFS_DISK mkpart primary ext4 ${START_POINT}MiB ${END_POINT}MiB - + BACKUP_END_POINT=$END_POINT + if [ $BACKUP_CREATED -eq 0 ] ; then + parted -s $ROOTFS_DISK mkpart primary ext4 ${START_POINT}MiB ${END_POINT}MiB + fi cat<>/tmp/part-include part biosboot --asprimary --fstype=biosboot --onpart=${ROOTFS_PART_PREFIX}1 EOF @@ -153,6 +158,14 @@ END_POINT=$(($START_POINT + $CGCS_PV_SIZE)) parted -s $ROOTFS_DISK mkpart extended ${START_POINT}MiB ${END_POINT}MiB if [ $BACKUP_CREATED -ne 0 ] ; then + BACKUP_CURRENT_SIZE=$(parted -s $BACKUP_PART unit MiB print | grep $BACKUP_PART | awk '{print $3}' | sed 's/[^C0-9]*//g') + if [ $BACKUP_CURRENT_SIZE -lt $PLATFORM_BACKUP_SIZE ] ; then + # parted will throw an error about overlapping with the next partition if we don't do this + BACKUP_END_POINT=$(($BACKUP_END_POINT - 1)).9 + parted -s $ROOTFS_DISK resizepart $BACKUP_PART_NO ${BACKUP_END_POINT}MiB + e2fsck -p -f $BACKUP_PART + resize2fs $BACKUP_PART + fi cat<>/tmp/part-include part /opt/platform-backup --fstype=ext4 --asprimary --noformat --onpart=$BACKUP_PART --fsoptions="$ROOTFS_OPTIONS" EOF diff --git a/bsp-files/kickstarts/pre_disk_controller.cfg b/bsp-files/kickstarts/pre_disk_controller.cfg index deb87e80..6399b782 100755 --- a/bsp-files/kickstarts/pre_disk_controller.cfg +++ b/bsp-files/kickstarts/pre_disk_controller.cfg @@ -21,7 +21,10 @@ if [ -d /sys/firmware/efi ] ; then BACKUP_PART_NO=1 START_POINT=1 END_POINT=$(($START_POINT + $PLATFORM_BACKUP_SIZE)) - parted -s $ROOTFS_DISK mkpart primary ext4 ${START_POINT}MiB ${END_POINT}MiB + BACKUP_END_POINT=$END_POINT + if [ $BACKUP_CREATED -eq 0 ] ; then + parted -s $ROOTFS_DISK mkpart primary ext4 ${START_POINT}MiB ${END_POINT}MiB + fi START_POINT=$END_POINT END_POINT=$(($START_POINT + $EFI_SIZE)) @@ -37,8 +40,10 @@ else START_POINT=2 END_POINT=$(($START_POINT + $PLATFORM_BACKUP_SIZE)) - parted -s $ROOTFS_DISK mkpart primary ext4 ${START_POINT}MiB ${END_POINT}MiB - + BACKUP_END_POINT=$END_POINT + if [ $BACKUP_CREATED -eq 0 ] ; then + parted -s $ROOTFS_DISK mkpart primary ext4 ${START_POINT}MiB ${END_POINT}MiB + fi cat<>/tmp/part-include part biosboot --asprimary --fstype=biosboot --onpart=${ROOTFS_PART_PREFIX}1 EOF @@ -56,6 +61,14 @@ START_POINT=$END_POINT parted -s $ROOTFS_DISK mkpart extended ${START_POINT}MiB 100% if [ $BACKUP_CREATED -ne 0 ] ; then + BACKUP_CURRENT_SIZE=$(parted -s $BACKUP_PART unit MiB print | grep $BACKUP_PART | awk '{print $3}' | sed 's/[^C0-9]*//g') + if [ $BACKUP_CURRENT_SIZE -lt $PLATFORM_BACKUP_SIZE ] ; then + # parted will throw an error about overlapping with the next partition if we don't do this + BACKUP_END_POINT=$(($BACKUP_END_POINT - 1)).9 + parted -s $ROOTFS_DISK resizepart $BACKUP_PART_NO ${BACKUP_END_POINT}MiB + e2fsck -p -f $BACKUP_PART + resize2fs $BACKUP_PART + fi cat<>/tmp/part-include part /opt/platform-backup --fstype=ext4 --asprimary --noformat --onpart=$BACKUP_PART --fsoptions="$ROOTFS_OPTIONS" EOF