#!/bin/bash

echo "-----------------------------------------------------------------------"
RootVolumeSizeBefore=$(df -TH | grep -w "/dev/mapper/rootvg-lvroot" | awk '{print $3}')
echo "扩容之前的root目录的容量为：${RootVolumeSizeBefore}"

echo "y


" | lvremove /dev/rootvg/lvswap

freepesize=$(vgdisplay rootvg | grep 'Free  PE' | awk '{print $5}')

lvextend  -l+${freepesize} /dev/rootvg/lvroot


## #自动扩展XFS文件系统到最大的可用大小
xfs_growfs /dev/rootvg/lvroot

df -TH | grep -w "/dev/mapper/rootvg-lvroot" | awk '{print $3}'

echo "-----------------------------------------------------------------------"
RootVolumeSizeAfter=$(df -TH | grep -w "/dev/mapper/rootvg-lvroot" | awk '{print $3}')
echo "扩容之后的root目录的容量为：${RootVolumeSizeAfter}"
RootVolumeSizeBeforeNum=$(echo $RootVolumeSizeBefore | cut -d "G" -f1)
RootVolumeSizeAfterNum=$(echo $RootVolumeSizeAfter | cut -d "G" -f1)

echo "恭喜，您的root目录容量增加了+++++++$(( ${RootVolumeSizeAfterNum}-${RootVolumeSizeBeforeNum} ))GB+++++"

