blob: 32e50911824e47fc1a1bc7708db283555c8e558a [file] [log] [blame]
#!/bin/bash
set -o errexit
set -o pipefail
# This plugin checks if the resize2f partition failed during the boot process.
readonly OK=0
readonly NONOK=1
readonly UNKNOWN=2
readonly DISKFRACTIONMINIMUM=90
readonly ROOTDEVICE="sda1"
if ! grep $ROOTDEVICE /proc/partitions > /dev/null; then
echo "Error retrieving requested disk size"
exit $UNKNOWN
fi
requestedDiskSize="$(grep $ROOTDEVICE /proc/partitions | awk 'NR == 1 {printf $3}')"
if ! df -P "/dev/$ROOTDEVICE" > /dev/null; then
echo "Error retrieving actual disk size"
exit $UNKNOWN
fi
actualDiskSize="$(df -P "/dev/$ROOTDEVICE" | awk 'NR == 2 {printf $2}')"
actualDiskSize=$((actualDiskSize*100))
ratio=$(($actualDiskSize/$requestedDiskSize))
# if the ratio of actualdiskSize to requestedDiskSize is less than 0.9, then it
# implies there is a problem occuring during the resize2f partition.
if [[ $ratio -lt $DISKFRACTIONMINIMUM ]]; then
echo "DiskSizeCheck failure occured"
exit $NONOK
else
echo "DiskSizeCheck is successful"
exit $OK
fi