diff --git a/tests/kola/disks/partition-scheme b/tests/kola/disks/partition-scheme new file mode 100755 index 0000000000..cbcf35bdb0 --- /dev/null +++ b/tests/kola/disks/partition-scheme @@ -0,0 +1,61 @@ +#!/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" + +root_part=$(findmnt -n -o SOURCE /sysroot) +disk_name=$(lsblk --json -o PKNAME --path "$root_part" | jq --raw-output '.blockdevices[].pkname') +diskData=$(lsblk --json --bytes -o NAME,FSTYPE,START,SIZE,MOUNTPOINT,PARTLABEL,PARTTYPENAME,LOG-SEC "$disk_name" | jq '.blockdevices[]' ) +partitionData=$(echo $diskData | jq '.children[]') +totalPartitions=$(echo $diskData | jq '.children | length') +sector_size=$(echo $diskData | jq '.["log-sec"]') + +if [[ $totalPartitions -ne 4 ]]; then + fatal "Expected 4 partitions, got $totalPartitions" +fi + +# check sizes of each parition +ONE_MiB=$(( 1024 * 1024 )) + +# An associative array that maps the partition label to the size (in MiB) +# of the partition. For the root partition we set it to "" to skip the check +# there because the growfs service runs on first boot. Checking start +# should be enough there. +declare -A expected=( + ["BIOS-BOOT"]="1" + ["EFI-SYSTEM"]="127" + ["boot"]="384" + ["root"]="" +) + +# There is a 1MiB gap at the beginning of the disks +expected_start=$(( 1 * $ONE_MiB / $sector_size )) + +# Iterate over the partitions and check their +for key in ${!expected[@]}; do + echo "${key}, ${expected[${key}]}" + size_MiB="${expected[${key}]}" + start=$(echo "$partitionData" | jq "select ( .partlabel == \"$key\") | .start") + size=$(echo "$partitionData" | jq "select ( .partlabel == \"$key\") | .size") + if [[ "$start" -ne "$expected_start" ]]; then + fatal "Expected $key partition start sector of $expected_start, got $start" + fi + if [ ! -z "$size_MiB" ]; then + expected_size=$(($size_MiB * $ONE_MiB)) + if [[ "$expected_size" -ne "$size" ]]; then + fatal "Expected $key partition of size $expected_size, got $size" + fi + fi + # The expected start of the next partition will be the start of this partition + # plus the size of this partition. + expected_start=$(($expected_start + $size / $sector_size)) +done + +ok partition scheme +exit 0 \ No newline at end of file