-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a test to verify partition numbers and sizes. This is to ensure that the partition scheme is what we expect during the transition to using OSBuild in the FCOS pipeline.
- Loading branch information
1 parent
f4f8dc7
commit 45c2a27
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |