#!/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/rootvg-lvroot" | awk '{print $3}')
# echo "扩容之前的root目录的容量为：${RootVolumeSizeBefore}"

# echo "y


# " | lvremove /dev/mapper/rootvg-lvopt

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

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


# ## #自动扩展XFS文件系统到最大的可用大小
# xfs_growfs /dev/mapper/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+++++"

# echo ""
# echo ""
# echo ""
# echo "-----------------------------------------------------------------------"


## vloume group的名字
VG_NAME=datavg
## logic volume 的名字
LV_NAME=lvdocker
## 实际物理磁盘的名称
PV_DISK=vdb
## 需要将物理磁盘挂载的目录
BIND_PATH=/var/lib/docker

echo "n
p



t

8e
w
" | fdisk /dev/${PV_DISK}
partprobe
vgcreate ${VG_NAME} /dev/${PV_DISK}1
selfpesize=$(vgdisplay ${VG_NAME} | grep 'Total PE' | awk '{print $3}')
lvcreate -l ${selfpesize} -n ${LV_NAME} ${VG_NAME}
mkfs.xfs /dev/mapper/${VG_NAME}-${LV_NAME}
mkdir -p ${BIND_PATH}
selffstab="/dev/mapper/${VG_NAME}-${LV_NAME}      ${BIND_PATH}          xfs    defaults        0 0"
echo "${selffstab}" >> /etc/fstab
mount -a

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