#! /bin/bash

## 关闭虚拟缓存
#swapoff -a
#cp -f /etc/fstab /etc/fstab_bak
#cat /etc/fstab_bak | grep -v swap >/etc/fstab

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

# echo "y


# " | lvremove /dev/mapper/centos-swap

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

# lvextend  -l+${freepesize} /dev/mapper/centos-root


# ## #自动扩展XFS文件系统到最大的可用大小
# xfs_growfs /dev/mapper/centos-root

# df -TH | grep -w "/dev/mapper/centos-root" | awk '{print $3}'

# echo "-----------------------------------------------------------------------"
# RootVolumeSizeAfter=$(df -TH | grep -w "/dev/mapper/centos-root" | 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+++++"

echo ""
echo ""
echo ""
echo "-----------------------------------------------------------------------"

export VG_NAME=minio-vg
export LV_NAME=4
echo "n
p



t

8e
w
" | fdisk /dev/vdf
partprobe

#vgcreate ${VG_NAME} /dev/vdd1
vgextend ${VG_NAME} /dev/vdf1
export selfpesize=319999
selfpesize=$(vgdisplay | grep -A 20 ${VG_NAME} | grep "Free  PE" | awk '{print$5}')
lvcreate -l ${selfpesize} -n ${LV_NAME} ${VG_NAME}
mkfs.xfs /dev/${VG_NAME}/${LV_NAME}

export selffstab="/dev/${VG_NAME}/${LV_NAME}       /data/minio-pv/pv4         xfs    defaults        0 0"
echo "${selffstab}" >> /etc/fstab
mount -a

echo ""
echo ""
echo ""
df -TH
echo "-----------------------------------------------------------------------"

# 扩容根目录，${VG_NAME}-root 通过df -Th获取需要扩容的文件系统
# lvextend -l +100%FREE /dev/mapper/${VG_NAME}-root
# xfs_growfs /dev/mapper/${VG_NAME}-root


