diff --git a/tests/kola/disks/partition-scheme b/tests/kola/disks/partition-scheme index cbcf35bdb0..6381c01299 100755 --- a/tests/kola/disks/partition-scheme +++ b/tests/kola/disks/partition-scheme @@ -11,10 +11,15 @@ set -xeuo pipefail 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"]') +diskData=$(sfdisk --json "$disk_name" | jq '.partitiontable' ) +partitionData=$(echo $diskData | jq '.partitions[]') +totalPartitions=$(echo $diskData | jq '.partitions | length') + +# lsblk always reports `START` in sectors that are 512 bytes even if +# the disk is a 4k native disk with 4096 byte sectors. Let's hard code +# the value here and do our math based on that. See +# https://github.com/karelzak/util-linux/commit/61c40f484563881420e1606a27663aee930cbe53 +sector_size=512 if [[ $totalPartitions -ne 4 ]]; then fatal "Expected 4 partitions, got $totalPartitions" @@ -22,8 +27,9 @@ fi # check sizes of each parition ONE_MiB=$(( 1024 * 1024 )) +SECTOR_UNIT=$(( $ONE_MiB / $sector_size )) -# An associative array that maps the partition label to the size (in MiB) +# An associative array that maps the partition label to the size (in Sector Units) # 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. @@ -39,23 +45,22 @@ 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") + size_in_sectors="${expected[${key}]}" + start=$(echo "$partitionData" | jq "select ( .name == \"$key\") | .start") + size=$(echo "$partitionData" | jq "select ( .name == \"$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 [ ! -z "$size_in_sectors" ]; then + expected_size=$(($size_in_sectors * $SECTOR_UNIT)) 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)) + expected_start=$(($expected_start + $size)) done ok partition scheme -exit 0 \ No newline at end of file +exit 0