#! /bin/bash

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


yum install lvm2 -y
echo ""
echo ""
echo ""
echo "-----------------------------------------------------------------------"

export VG_NAME=datavg

echo "n
p



t

8e
w
" | fdisk /dev/vdb
partprobe
# 如果已经存在卷组，直接进行添加
# vgextend rootvg /dev/bdb1
vgcreate ${VG_NAME} /dev/vdb1
export selfpesize=$(vgdisplay ${VG_NAME} | grep 'Total PE' | awk '{print $3}')
# 大小根据实际情况调整
lvcreate -l ${selfpesize} -n lvdata ${VG_NAME}
mkfs.xfs /dev/mapper/${VG_NAME}-lvdata
# mkfs.ext4  /dev/mapper/${VG_NAME}-lvdata
mkdir -p /data
mkdir -p /var/lib/docker  
#selffstab="/dev/mapper/${VG_NAME}-lvdata       /var/lib/docker          xfs    defaults        0 0"
export selffstab="/dev/mapper/${VG_NAME}-lvdata       /var/lib/docker         xfs    defaults        0 0"
echo "${selffstab}" >> /etc/fstab
mount -a

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

lsblk