Skip to content

Commit

Permalink
Change to use sfdisk
Browse files Browse the repository at this point in the history
Use sfdisk instead of lsblk to get the partition table. This requires
some changes in how the size of partitions are checked since sfdisk
records disk size in sectors, not MiB.
  • Loading branch information
lukewarmtemp committed Nov 28, 2023
1 parent 13a364c commit 4fea8d1
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions tests/kola/disks/partition-scheme
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ 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')
sector_size=$(echo $diskData | jq .sectorsize)

if [[ $totalPartitions -ne 4 ]]; then
fatal "Expected 4 partitions, got $totalPartitions"
Expand All @@ -37,12 +37,12 @@ declare -A expected=(
# 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
# Iterate over the partitions and check their start and size
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")
start=$(echo "$partitionData" | jq "select ( .name == \"$key\") | .start")
sectors=$(echo "$partitionData" | jq "select ( .name == \"$key\") | .size")
size=$(( $sectors * $sector_size ))
if [[ "$start" -ne "$expected_start" ]]; then
fatal "Expected $key partition start sector of $expected_start, got $start"
fi
Expand Down

0 comments on commit 4fea8d1

Please sign in to comment.