blob: 1f3ab03e9c94751a6e1457786d2ed0d3ad5e3adf [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=0.9
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}')"
ratio=$(echo "$actualDiskSize/$requestedDiskSize" | bc -l)
# 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 (( $(echo "$ratio < $DISKFRACTIONMINIMUM" | bc -l) )); then
echo "DiskSizeCheck failure occured"
exit $NONOK
else
echo "DiskSizeCheck is successful"
exit $OK
fi