From c6624fc632d07ea78c6c8a7c3e2282bd65ab49ec Mon Sep 17 00:00:00 2001 From: Luke Yang Date: Wed, 1 Nov 2023 11:33:47 -0400 Subject: [PATCH] tests: create partition scheme test Create a test to verify partition numbers and sizes. This is to ensure that the partition scheme is valid during the transition to using OSBuild in the FCOS pipeline. --- tests/kola/disks/partition-scheme | 80 +++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100755 tests/kola/disks/partition-scheme diff --git a/tests/kola/disks/partition-scheme b/tests/kola/disks/partition-scheme new file mode 100755 index 0000000000..e8447a2df8 --- /dev/null +++ b/tests/kola/disks/partition-scheme @@ -0,0 +1,80 @@ +#!/bin/bash +## kola: +## exclusive: false +## description: Verify the partition scheme is what we expect. +## + +set -xeuo pipefail + +# shellcheck disable=SC1091 +. "$KOLA_EXT_DATA/commonlib.sh" + +# check for 4 partitions +root_part=$(findmnt -n -o SOURCE /sysroot) +disk_name=$(lsblk --json -o PKNAME --path "$root_part" | jq --raw-output '.blockdevices[].pkname') +totalPartitions=$(sudo lsblk --json --bytes -o NAME,FSTYPE,START,SIZE,MOUNTPOINT,PARTLABEL,PARTTYPENAME "$disk_name" | jq '.blockdevices[].children | length') +if [[ $totalPartitions -ne 4 ]]; then + fatal "Expected 4 partitions, got $totalPartitions" +fi + +# get partition data and then verify the starting sector and size of all we can +partitionData=$(sudo lsblk --json -ba -o NAME,FSTYPE,START,SIZE,MOUNTPOINT,PARTLABEL,PARTTYPENAME | jq .blockdevices[].children[] ) + +# bios boot +biosBootSize=$( echo "$partitionData" | jq 'select ( .partlabel == "BIOS-BOOT" or .parttypename == "BIOS boot") | .size ' ) +biosBootStart=$( echo "$partitionData" | jq 'select ( .partlabel == "BIOS-BOOT" or .parttypename == "BIOS boot") | .start ' ) + +# efi system +efiSystemSize=$( echo "$partitionData" | jq 'select ( .partlabel == "EFI-SYSTEM" or .parttypename == "EFI System") | .size ' ) +efiSystemStart=$( echo "$partitionData" | jq 'select ( .partlabel == "EFI-SYSTEM" or .parttypename == "EFI System") | .start ' ) + +# boot +bootSize=$( echo "$partitionData" | jq 'select ( .partlabel == "boot" or .mountpoint == "/boot") | .size ' ) +bootStart=$( echo "$partitionData" | jq 'select ( .partlabel == "boot" or .mountpoint == "/boot") | .start ' ) + +# root (only get start size of root partition since the growfs service runs on first boot) +rootStart=$( echo "$partitionData" | jq 'select ( .partlabel == "root" or .mountpoint == "/sysroot") | .start ' ) + +# check sizes of each parition +ONE_MiB=$(( 1024 * 1024 )) + +expectedBIOSBootStart=$((2048)) +expectedBIOSBootSize=$((1 * $ONE_MiB)) + +expectedEFISystemStart=$((4096)) +expectedEFISystemSize=$((127 * $ONE_MiB)) + +expectedBootStart=$((258 * 1024)) +expectedBootSize=$((384 * $ONE_MiB)) + +expectedRootStart=$(($ONE_MiB + 2048)) + +if [[ $biosBootStart -ne $expectedBIOSBootStart ]]; then + fatal "Expected BIOS-BOOT partition start size of $expectedBIOSBootStart, got $biosBootStart" +fi + +if [[ $biosBootSize -ne $expectedBIOSBootSize ]]; then + fatal "Expected BIOS-BOOT partition of size $expectedBIOSBootSize, got $biosBootSize" +fi + +if [[ $efiSystemStart -ne $expectedEFISystemStart ]]; then + fatal "Expected EFI-SYSTEM partition start size of $expectedEFISystemStart, got $efiSystemStart" +fi + +if [[ $efiSystemSize -ne $expectedEFISystemSize ]]; then + fatal "Expected EFI-SYSTEM partition of size $expectedEFISystemSize, got $efiSystemSize" +fi + +if [[ $bootStart -ne $expectedBootStart ]]; then + fatal "Expected boot partition start size of $expectedBootStart, got $bootStart" +fi + +if [[ $bootSize -ne $expectedBootSize ]]; then + fatal "Expected boot partition of size $expectedBootSize, got $bootSize" +fi + +if [[ $rootStart -ne $expectedRootStart ]]; then + fatal "Expected root partition start size of $expectedRootStart, got $rootStart" +fi + +ok partition scheme \ No newline at end of file