#!/bin/sh set -e MOUNT_LINE=$(cat /etc/mtab | grep ' / ' | grep -v '^rootfs') DEVICE=$(echo "$MOUNT_LINE" | cut -d' ' -f1) FSTYPE=$(echo "$MOUNT_LINE" | cut -d' ' -f3) GROWPART=$(which growpart) if [ $? -ne 0 ]; then echo "growpart command is missing" exit 1 fi if [ $(grep mapper /etc/fstab |grep ' / ' |wc -l) -eq 0 ]; then DEVICE=$(readlink -f "$DEVICE") DISK=$(echo "$DEVICE" | sed 's/.$//') PARTITION=$(echo "$DEVICE" | sed "s|^$DISK||") LVM="no" fi if [ "${LVM}" != "no" ]; then PVRESIZE=$(which pvresize) LVEXTEND=$(which lvextend) DISK=$(pvdisplay |grep "PV Name"|awk '{print $3}'|sed 's/.$//') PARTITION=$(pvdisplay |grep "PV Name"|awk '{print $3}'| sed "s|^${DISK}||") PV=$(pvdisplay |grep "PV Name"|awk '{print $3}') LV=$(lvdisplay ${DEVICE} |grep "LV Path"|awk '{print $3}') fi if [ -n "$DEBUG" ]; then echo DEVICE: ${DEVICE} echo FSTYPE: ${FSTYPE} echo DISK: ${DISK} echo PARTITION: ${PARTITION} fi ${GROWPART} ${DISK} ${PARTITION} if [ "${LVM}" != "no" ]; then ${PVRESIZE} ${PV} ${LVEXTEND} -l +100%FREE ${LV} fi case "${FSTYPE}" in ext2|ext3|ext4) resize2fs ${DEVICE} ;; xfs) xfs_growfs / ;; esac