carlwgeorge / rpms / centos-repos

Forked from rpms/centos-repos 4 years ago
Clone

Blame SOURCES/rootfs-expand

161103
#!/bin/bash
161103
clear
161103
part=$(mount |grep '^/dev.* / ' |awk '{print $1}')
161103
if [ -z "$part" ];then
161103
    echo "Error detecting rootfs"
161103
    exit -1
161103
fi
161103
dev=$(echo $part|sed 's/[0-9]*$//g')
161103
devlen=${#dev}
161103
num=${part:$devlen}
161103
if [[ "$dev" =~ ^/dev/mmcblk[0-9]*p$ ]];then
161103
    dev=${dev:0:-1}
161103
fi
161103
if [ ! -x /usr/bin/growpart ];then
161103
    echo "Please install cloud-utils-growpart (sudo yum install cloud-utils-growpart)"
161103
    exit -2
161103
fi
161103
if [ ! -x /usr/sbin/resize2fs ];then
161103
    echo "Please install e2fsprogs (sudo yum install e2fsprogs)"
161103
    exit -3
161103
fi
161103
echo $part $dev $num
161103
161103
echo "Extending partition $num to max size ...."
161103
growpart $dev $num
161103
echo "Resizing ext4 filesystem ..."
161103
resize2fs $part
161103
echo "Done."
161103
df -h |grep $part
161103