From 0e89acc83c616741952a068a3ff07ba91440eff8 Mon Sep 17 00:00:00 2001 From: Daniel Safta Date: Thu, 27 Aug 2020 11:15:17 +0000 Subject: [PATCH] Align partitions created by kickstarters Partitions on some disks may be created unaligned. The cause is that the creation of partitions is done between specific intervals expressed in MBs. The kernel exposed a specific variable for each disk for providing an offset to align each partitions (/sys/block//alignment_offset). For better granular control, we transform MB units into logical sector units and use the alignment_offset variable to properly align the partitions. Change-Id: I971c232fe0969eac14b85c5796908f0c85e23dbf Closes-bug: 1883975 Signed-off-by: Daniel Safta --- bsp-files/kickstarts/pre_disk_aio.cfg | 99 +++++++++++++++----- bsp-files/kickstarts/pre_disk_controller.cfg | 99 ++++++++++++++------ 2 files changed, 144 insertions(+), 54 deletions(-) diff --git a/bsp-files/kickstarts/pre_disk_aio.cfg b/bsp-files/kickstarts/pre_disk_aio.cfg index ded2b735..df8f4552 100755 --- a/bsp-files/kickstarts/pre_disk_aio.cfg +++ b/bsp-files/kickstarts/pre_disk_aio.cfg @@ -104,6 +104,8 @@ SCRATCH_VOL_SIZE=16000 PLATFORM_BACKUP_SIZE=10000 BOOT_SIZE=500 EFI_SIZE=300 +ONE_MiB=$(( 1024 * 1024 )) +ONE_TENTH_MiB_IN_SECTORS=200 ROOTFS_OPTIONS="defaults" profile_mode=`cat /proc/cmdline |xargs -n1 echo |grep security_profile= | grep extended` @@ -112,22 +114,50 @@ if [ -n "$profile_mode" ]; then ROOTFS_OPTIONS="${ROOTFS_OPTIONS},iversion" fi +BLOCK_DEVICE=$(echo $rootfs_device |awk -F/ '{ print $3 }') + +optimal_io_size=$(cat /sys/block/$BLOCK_DEVICE/queue/optimal_io_size) +logical_block_size=$(cat /sys/block/$BLOCK_DEVICE/queue/logical_block_size) +alignment_offset=$(cat /sys/block/$BLOCK_DEVICE/alignment_offset) + +if [ -z ${optimal_io_size} ] || [ $optimal_io_size -le 0 ]; then + optimal_io_size=$ONE_MiB + wlog "Error finding optimal_io_size. Using the default ${ONE_MiB} value" +fi + +if [ -z ${logical_block_size} ] || [ $logical_block_size -le 0 ]; then + logical_block_size=512 + wlog "Error finding logical_block_size. Using the default 512 value" +fi + +if [ -z ${alignment_offset} ]; then + alignment_offset=0 + wlog "Error finding alignment_offset. Using the default 0 value" +fi + +wlog "Optimal IO size: ${optimal_io_size}, logical block size: ${logical_block_size}, alignment offset: ${alignment_offset}." + +START_POINT=$(( ($optimal_io_size + $alignment_offset)/$logical_block_size )) + if [ -d /sys/firmware/efi ] ; then BACKUP_PART=${ROOTFS_PART_PREFIX}1 BACKUP_PART_NO=1 START_POINT=1 - END_POINT=$(($START_POINT + $PLATFORM_BACKUP_SIZE)) + SIZE_SEC=$(( ($PLATFORM_BACKUP_SIZE * $ONE_MiB )/$logical_block_size )) + END_POINT=$(( $START_POINT + $SIZE_SEC - 1 )) BACKUP_END_POINT=$END_POINT if [ $BACKUP_CREATED -eq 0 ] ; then - wlog "Creating platform backup partition of ${PLATFORM_BACKUP_SIZE}MiB from ${START_POINT}MiB to ${END_POINT}MiB." - exec_retry 5 0.5 "parted -s $rootfs_device mkpart primary ext4 ${START_POINT}MiB ${END_POINT}MiB" + wlog "Creating platform backup partition of ${PLATFORM_BACKUP_SIZE}MiB from ${START_POINT}s to ${END_POINT}s." + exec_retry 5 0.5 "parted $rootfs_device mkpart primary ext4 ${START_POINT}s ${END_POINT}s" [ $? -ne 0 ] && report_pre_failure_with_msg "ERROR: Partition creation failed!" fi - START_POINT=$END_POINT - END_POINT=$(($START_POINT + $EFI_SIZE)) - wlog "Creating EFI partition of ${EFI_SIZE}MiB from ${START_POINT}MiB to ${END_POINT}MiB." - exec_retry 5 0.5 "parted -s $rootfs_device mkpart primary fat32 ${START_POINT}MiB ${END_POINT}MiB" + START_POINT=$(( $END_POINT + 1 )) + SIZE_SEC=$(( ($EFI_SIZE * $ONE_MiB )/$logical_block_size )) + END_POINT=$(( $START_POINT + $SIZE_SEC - 1)) + + wlog "Creating EFI partition of ${EFI_SIZE}MiB from ${START_POINT}s to ${END_POINT}s." + exec_retry 5 0.5 "parted $rootfs_device mkpart primary fat32 ${START_POINT}s ${END_POINT}s" [ $? -ne 0 ] && report_pre_failure_with_msg "ERROR: Partition creation failed!" cat<>/tmp/part-include @@ -137,15 +167,29 @@ else BACKUP_PART=${ROOTFS_PART_PREFIX}2 BACKUP_PART_NO=2 wlog "Creating 1MB BIOS GRUB partition from 1MiB to 2MiB." - exec_retry 5 0.5 "parted -s $rootfs_device mkpart primary 1MiB 2MiB" + # Although we calculate proper sector between which to create the bios + # partition, we still create it between 1MiB and 2MiB to take into account + # upgrade scenarios. + # If upgrading from version N to N+1, version N might have non-aligned bios + # partition, but right after it will be the platform backup partition. If + # the alignment is bad, then if we try to align the bios partition by + # shifting it right, we may come over the backup partition, that is not + # deleted by kickstarters. + # Since the bios partition is only used for booting, it not being aligned + # shouldn't cause any issues. + exec_retry 5 0.5 "parted $rootfs_device mkpart primary 1MiB 2MiB" [ $? -ne 0 ] && report_pre_failure_with_msg "ERROR: Partition creation failed!" - START_POINT=2 - END_POINT=$(($START_POINT + $PLATFORM_BACKUP_SIZE)) + SIZE_SEC=$(( ( $ONE_MiB )/$logical_block_size )) + END_POINT=$(( $START_POINT + $SIZE_SEC - 1 )) + + START_POINT=$(( $END_POINT + 1 )) + SIZE_SEC=$(( ($PLATFORM_BACKUP_SIZE * $ONE_MiB )/$logical_block_size )) + END_POINT=$(( $START_POINT + $SIZE_SEC - 1 )) BACKUP_END_POINT=$END_POINT if [ $BACKUP_CREATED -eq 0 ] ; then - wlog "Creating platform backup partition of ${PLATFORM_BACKUP_SIZE}MiB from ${START_POINT}MiB to ${END_POINT}MiB." - exec_retry 5 0.5 "parted -s $rootfs_device mkpart primary ext4 ${START_POINT}MiB ${END_POINT}MiB" + wlog "Creating platform backup partition of ${PLATFORM_BACKUP_SIZE}MiB from ${START_POINT}s to ${END_POINT}s." + exec_retry 5 0.5 "parted $rootfs_device mkpart primary ext4 ${START_POINT}s ${END_POINT}s" [ $? -ne 0 ] && report_pre_failure_with_msg "ERROR: Partition creation failed!" fi cat<>/tmp/part-include @@ -153,22 +197,25 @@ part biosboot --asprimary --fstype=biosboot --onpart=${ROOTFS_PART_PREFIX}1 EOF fi -START_POINT=$END_POINT -END_POINT=$(($START_POINT + $BOOT_SIZE)) -wlog "Creating boot partition of ${BOOT_SIZE}MiB from ${START_POINT}MiB to ${END_POINT}MiB." -exec_retry 5 0.5 "parted -s $rootfs_device mkpart primary ext4 ${START_POINT}MiB ${END_POINT}MiB" +START_POINT=$(( $END_POINT + 1 )) +SIZE_SEC=$(( ($BOOT_SIZE * $ONE_MiB )/$logical_block_size )) +END_POINT=$(( $START_POINT + $SIZE_SEC - 1 )) +wlog "Creating boot partition of ${BOOT_SIZE}MiB from ${START_POINT}s to ${END_POINT}s." +exec_retry 5 0.5 "parted $rootfs_device mkpart primary ext4 ${START_POINT}s ${END_POINT}s" [ $? -ne 0 ] && report_pre_failure_with_msg "ERROR: Partition creation failed!" -START_POINT=$END_POINT -END_POINT=$(($START_POINT + $ROOTFS_SIZE)) -wlog "Creating rootfs partition of ${ROOTFS_SIZE}MiB from ${START_POINT}MiB to ${END_POINT}MiB." -exec_retry 5 0.5 "parted -s $rootfs_device mkpart primary ext4 ${START_POINT}MiB ${END_POINT}MiB" +START_POINT=$(( $END_POINT + 1 )) +SIZE_SEC=$(( ($ROOTFS_SIZE * $ONE_MiB )/$logical_block_size )) +END_POINT=$(( $START_POINT + $SIZE_SEC - 1 )) +wlog "Creating rootfs partition of ${ROOTFS_SIZE}MiB from ${START_POINT}s to ${END_POINT}s." +exec_retry 5 0.5 "parted $rootfs_device mkpart primary ext4 ${START_POINT}s ${END_POINT}s" [ $? -ne 0 ] && report_pre_failure_with_msg "ERROR: Partition creation failed!" -START_POINT=$END_POINT -END_POINT=$(($START_POINT + $CGCS_PV_SIZE)) -wlog "Creating cgcs-vg partition of ${CGCS_PV_SIZE}MiB from ${START_POINT}MiB to ${END_POINT}MiB." -exec_retry 5 0.5 "parted -s $rootfs_device mkpart extended ${START_POINT}MiB ${END_POINT}MiB" +START_POINT=$(( $END_POINT + 1 )) +SIZE_SEC=$(( ($CGCS_PV_SIZE * $ONE_MiB )/$logical_block_size )) +END_POINT=$(( $START_POINT + $SIZE_SEC - 1 )) +wlog "Creating cgcs-vg partition of ${CGCS_PV_SIZE}MiB from ${START_POINT}s to ${END_POINT}s." +exec_retry 5 0.5 "parted $rootfs_device mkpart extended ${START_POINT}s ${END_POINT}s" [ $? -ne 0 ] && report_pre_failure_with_msg "ERROR: Partition creation failed!" if [ $BACKUP_CREATED -ne 0 ] ; then @@ -176,8 +223,8 @@ if [ $BACKUP_CREATED -ne 0 ] ; then if [ $BACKUP_CURRENT_SIZE -lt $PLATFORM_BACKUP_SIZE ] ; then wlog "Backup partition size is ${BACKUP_CURRENT_SIZE}MiB, resizing to ${PLATFORM_BACKUP_SIZE}MiB." # 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 - exec_retry 5 0.5 "parted -s $rootfs_device resizepart $BACKUP_PART_NO ${BACKUP_END_POINT}MiB" + BACKUP_END_POINT=$(( $BACKUP_END_POINT - $ONE_TENTH_MiB_IN_SECTORS )) + exec_retry 5 0.5 "parted $rootfs_device resizepart $BACKUP_PART_NO ${BACKUP_END_POINT}s" [ $? -ne 0 ] && report_pre_failure_with_msg "ERROR: resize of platform backup partition failed!" exec_retry 2 0.1 "e2fsck -p -f $BACKUP_PART" [ $? -ne 0 ] && report_pre_failure_with_msg "ERROR: e2fsck failed on platform backup partition!" diff --git a/bsp-files/kickstarts/pre_disk_controller.cfg b/bsp-files/kickstarts/pre_disk_controller.cfg index 1d246027..a76136c3 100755 --- a/bsp-files/kickstarts/pre_disk_controller.cfg +++ b/bsp-files/kickstarts/pre_disk_controller.cfg @@ -1,37 +1,62 @@ ## NOTE: updates to partition sizes need to be also reflected in ## _controller_filesystem_limits() in sysinv/api/controllers/v1/istorconfig.py - ROOTFS_SIZE=20000 LOG_VOL_SIZE=8000 SCRATCH_VOL_SIZE=16000 PLATFORM_BACKUP_SIZE=10000 BOOT_SIZE=500 EFI_SIZE=300 - +ONE_MiB=$((1024 * 1024)) +ONE_TENTH_MiB_IN_SECTORS=200 ROOTFS_OPTIONS="defaults" profile_mode=`cat /proc/cmdline |xargs -n1 echo |grep security_profile= | grep extended` if [ -n "$profile_mode" ]; then # Enable iversion labelling for rootfs when IMA is enabled ROOTFS_OPTIONS="${ROOTFS_OPTIONS},iversion" fi +BLOCK_DEVICE=$(echo $rootfs_device |awk -F/ '{ print $3 }') + +optimal_io_size=$(cat /sys/block/$BLOCK_DEVICE/queue/optimal_io_size) +logical_block_size=$(cat /sys/block/$BLOCK_DEVICE/queue/logical_block_size) +alignment_offset=$(cat /sys/block/$BLOCK_DEVICE/alignment_offset) + +if [ -z ${optimal_io_size} ] || [ $optimal_io_size -le 0 ]; then + optimal_io_size=$ONE_MiB + wlog "Error finding optimal_io_size. Using the default ${ONE_MiB} value" +fi + +if [ -z ${logical_block_size} ] || [ $logical_block_size -le 0 ]; then + logical_block_size=512 + wlog "Error finding logical_block_size. Using the default 512 value" +fi + +if [ -z ${alignment_offset} ]; then + alignment_offset=0 + wlog "Error finding alignment_offset. Using the default 0 value" +fi + +wlog "Optimal IO size: ${optimal_io_size}, logical block size: ${logical_block_size}, alignment offset: ${alignment_offset}." + +START_POINT=$(( ($optimal_io_size + $alignment_offset)/$logical_block_size )) if [ -d /sys/firmware/efi ] ; then BACKUP_PART=${ROOTFS_PART_PREFIX}1 BACKUP_PART_NO=1 - START_POINT=1 - END_POINT=$(($START_POINT + $PLATFORM_BACKUP_SIZE)) + SIZE_SEC=$(( ($PLATFORM_BACKUP_SIZE * $ONE_MiB )/$logical_block_size )) + END_POINT=$(( $START_POINT + $SIZE_SEC - 1 )) BACKUP_END_POINT=$END_POINT if [ $BACKUP_CREATED -eq 0 ] ; then - wlog "Creating platform backup partition of ${PLATFORM_BACKUP_SIZE}MiB from ${START_POINT}MiB to ${END_POINT}MiB." - exec_retry 5 0.5 "parted -s $rootfs_device mkpart primary ext4 ${START_POINT}MiB ${END_POINT}MiB" + wlog "Creating platform backup partition of ${PLATFORM_BACKUP_SIZE}MiB from ${START_POINT}s to ${END_POINT}s." + exec_retry 5 0.5 "parted $rootfs_device mkpart primary ext4 ${START_POINT}s ${END_POINT}s" [ $? -ne 0 ] && report_pre_failure_with_msg "ERROR: Partition creation failed!" fi - START_POINT=$END_POINT - END_POINT=$(($START_POINT + $EFI_SIZE)) - wlog "Creating EFI partition of ${EFI_SIZE}MiB from ${START_POINT}MiB to ${END_POINT}MiB." - exec_retry 5 0.5 "parted -s $rootfs_device mkpart primary fat32 ${START_POINT}MiB ${END_POINT}MiB" + START_POINT=$(( $END_POINT + 1 )) + SIZE_SEC=$(( ($EFI_SIZE * $ONE_MiB )/$logical_block_size )) + END_POINT=$(( $START_POINT + $SIZE_SEC - 1)) + wlog "Creating EFI partition of ${EFI_SIZE}MiB from ${START_POINT}s to ${END_POINT}s." + exec_retry 5 0.5 "parted $rootfs_device mkpart primary fat32 ${START_POINT}s ${END_POINT}s" [ $? -ne 0 ] && report_pre_failure_with_msg "ERROR: Partition creation failed!" cat<>/tmp/part-include @@ -40,16 +65,32 @@ EOF else BACKUP_PART=${ROOTFS_PART_PREFIX}2 BACKUP_PART_NO=2 + + # Although we calculate proper sector between which to create the bios + # partition, we still create it between 1MiB and 2MiB to take into account + # upgrade scenarios. + # If upgrading from version N to N+1, version N might have non-aligned bios + # partition, but right after it will be the platform backup partition. If + # the alignment is bad, then if we try to align the bios partition by + # shifting it right, we may come over the backup partition, that is not + # deleted by kickstarters. + # Since the bios partition is only used for booting, it not being aligned + # shouldn't cause any issues. + SIZE_SEC=$(( ( $ONE_MiB )/$logical_block_size )) + END_POINT=$(( $START_POINT + $SIZE_SEC - 1 )) + wlog "Creating 1MB BIOS GRUB partition from 1MiB to 2MiB." - exec_retry 5 0.5 "parted -s $rootfs_device mkpart primary 1MiB 2MiB" + exec_retry 5 0.5 "parted $rootfs_device mkpart primary 1MiB 2MiB" [ $? -ne 0 ] && report_pre_failure_with_msg "ERROR: Partition creation failed!" - START_POINT=2 - END_POINT=$(($START_POINT + $PLATFORM_BACKUP_SIZE)) + START_POINT=$(( $END_POINT + 1 )) + SIZE_SEC=$(( ($PLATFORM_BACKUP_SIZE * $ONE_MiB )/$logical_block_size )) + END_POINT=$(( $START_POINT + $SIZE_SEC - 1 )) + BACKUP_END_POINT=$END_POINT if [ $BACKUP_CREATED -eq 0 ] ; then - wlog "Creating platform backup partition of ${PLATFORM_BACKUP_SIZE}MiB from ${START_POINT}MiB to ${END_POINT}MiB." - exec_retry 5 0.5 "parted -s $rootfs_device mkpart primary ext4 ${START_POINT}MiB ${END_POINT}MiB" + wlog "Creating platform backup partition of ${PLATFORM_BACKUP_SIZE}MiB from ${START_POINT}s to ${END_POINT}s." + exec_retry 5 0.5 "parted $rootfs_device mkpart primary ext4 ${START_POINT}s ${END_POINT}s" [ $? -ne 0 ] && report_pre_failure_with_msg "ERROR: Partition creation failed!" fi cat<>/tmp/part-include @@ -57,21 +98,23 @@ part biosboot --asprimary --fstype=biosboot --onpart=${ROOTFS_PART_PREFIX}1 EOF fi -START_POINT=$END_POINT -END_POINT=$(($START_POINT + $BOOT_SIZE)) -wlog "Creating boot partition of ${BOOT_SIZE}MiB from ${START_POINT}MiB to ${END_POINT}MiB." -exec_retry 5 0.5 "parted -s $rootfs_device mkpart primary ext4 ${START_POINT}MiB ${END_POINT}MiB" +START_POINT=$(( $END_POINT + 1 )) +SIZE_SEC=$(( ($BOOT_SIZE * $ONE_MiB )/$logical_block_size )) +END_POINT=$(( $START_POINT + $SIZE_SEC - 1 )) +wlog "Creating boot partition of ${BOOT_SIZE}MiB from ${START_POINT}s to ${END_POINT}s." +exec_retry 5 0.5 "parted $rootfs_device mkpart primary ext4 ${START_POINT}s ${END_POINT}s" [ $? -ne 0 ] && report_pre_failure_with_msg "ERROR: Partition creation failed!" -START_POINT=$END_POINT -END_POINT=$(($START_POINT + $ROOTFS_SIZE)) -wlog "Creating rootfs partition of ${ROOTFS_SIZE}MiB from ${START_POINT}MiB to ${END_POINT}MiB." -exec_retry 5 0.5 "parted -s $rootfs_device mkpart primary ext4 ${START_POINT}MiB ${END_POINT}MiB" +START_POINT=$(( $END_POINT + 1 )) +SIZE_SEC=$(( ($ROOTFS_SIZE * $ONE_MiB )/$logical_block_size )) +END_POINT=$(( $START_POINT + $SIZE_SEC - 1 )) +wlog "Creating rootfs partition of ${ROOTFS_SIZE}MiB from ${START_POINT}s to ${END_POINT}s." +exec_retry 5 0.5 "parted $rootfs_device mkpart primary ext4 ${START_POINT}s ${END_POINT}s" [ $? -ne 0 ] && report_pre_failure_with_msg "ERROR: Partition creation failed!" -START_POINT=$END_POINT -wlog "Creating cgcs-vg partition of ${CGCS_PV_SIZE}MiB from ${START_POINT}MiB to 100%." -exec_retry 5 0.5 "parted -s $rootfs_device mkpart extended ${START_POINT}MiB 100%" +START_POINT=$(( $END_POINT + 1 )) +wlog "Creating cgcs-vg partition of ${CGCS_PV_SIZE}MiB from ${START_POINT}s to 100%." +exec_retry 5 0.5 "parted $rootfs_device mkpart extended ${START_POINT}s 100%" [ $? -ne 0 ] && report_pre_failure_with_msg "ERROR: Partition creation failed!" if [ $BACKUP_CREATED -ne 0 ] ; then @@ -79,8 +122,8 @@ if [ $BACKUP_CREATED -ne 0 ] ; then if [ $BACKUP_CURRENT_SIZE -lt $PLATFORM_BACKUP_SIZE ] ; then wlog "Backup partition size is ${BACKUP_CURRENT_SIZE}MiB, resizing to ${PLATFORM_BACKUP_SIZE}MiB." # 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 - exec_retry 5 0.5 "parted -s $rootfs_device resizepart $BACKUP_PART_NO ${BACKUP_END_POINT}MiB" + BACKUP_END_POINT=$(( $BACKUP_END_POINT - $ONE_TENTH_MiB_IN_SECTORS )) + exec_retry 5 0.5 "parted $rootfs_device resizepart $BACKUP_PART_NO ${BACKUP_END_POINT}s" [ $? -ne 0 ] && report_pre_failure_with_msg "ERROR: resize of platform backup partition failed!" exec_retry 2 0.1 "e2fsck -p -f $BACKUP_PART" [ $? -ne 0 ] && report_pre_failure_with_msg "ERROR: e2fsck failed on platform backup partition!"