Fix growpart error when missing.

If the virtual machine don't have cloud-utils intalled this script print errors.
I test if growpart command is available before running the action
pull/15/head
Philippe Caseiro 10 years ago
parent 8669f28e45
commit 6e6e70e29f

@ -1,29 +1,34 @@
#!/bin/bash #!/bin/bash
MOUNT_LINE=$(cat /etc/mtab | grep ' / ' | grep -v '^rootfs') GROWPART=$(which growpart)
if [[ ${?} -ne 0 ]]
then
echo "Skipping growfs, growpart command is missing"
else
MOUNT_LINE=$(cat /etc/mtab | grep ' / ' | grep -v '^rootfs')
DEVICE=$(echo "$MOUNT_LINE" | cut -d' ' -f1) DEVICE=$(echo "$MOUNT_LINE" | cut -d' ' -f1)
DEVICE=$(readlink -f "$DEVICE") DEVICE=$(readlink -f "$DEVICE")
FSTYPE=$(echo "$MOUNT_LINE" | cut -d' ' -f3) FSTYPE=$(echo "$MOUNT_LINE" | cut -d' ' -f3)
DISK=$(echo "$DEVICE" | sed 's/.$//') DISK=$(echo "$DEVICE" | sed 's/.$//')
PARTITION=$(echo "$DEVICE" | sed "s|^$DISK||") PARTITION=$(echo "$DEVICE" | sed "s|^$DISK||")
if [ -n $DEBUG ]; then if [ -n $DEBUG ]; then
echo DEVICE: $DEVICE echo DEVICE: $DEVICE
echo FSTYPE: $FSTYPE echo FSTYPE: $FSTYPE
echo DISK: $DISK echo DISK: $DISK
echo PARTITION: $PARTITION echo PARTITION: $PARTITION
fi fi
growpart "$DISK" "$PARTITION" growpart "$DISK" "$PARTITION"
case "$FSTYPE" in case "$FSTYPE" in
ext2|ext3|ext4) ext2|ext3|ext4)
resize2fs "$DEVICE" resize2fs "$DEVICE"
;; ;;
xfs) xfs)
xfs_growfs / xfs_growfs /
;; ;;
esac esac
fi

Loading…
Cancel
Save