#!/usr/bin/env bash

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

umount /dev/mapper/openeuler-swap
lvremove /dev/openeuler/swap

freepesize=$(vgdisplay openeuler | grep 'Free  PE' | awk '{print $5}')
lvextend  -l+${freepesize} /dev/openeuler/root
resize2fs /dev/openeuler/root

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

# 自定义 安装lvm2'
echo "n
p



t

8e
w
" | fdisk /dev/sda
partprobe

# 如果已经存在卷组，直接进行添加
export VG_NAME=datavg
vgcreate ${VG_NAME} /dev/sda1
export selfpesize=$(vgdisplay ${VG_NAME} | grep 'Total PE' | awk '{print $3}')
# 大小根据实际情况调整
lvcreate -l ${selfpesize} -n lvdata ${VG_NAME}
partprobe

mkfs.xfs /dev/mapper/${VG_NAME}-lvdata
mkdir -p /var/lib/docker
export selffstab="/dev/mapper/${VG_NAME}-lvdata       /var/lib/docker         xfs    defaults        0 0"
echo "${selffstab}" >> /etc/fstab
mount -a
echo ""
sleep 3

df -Th

echo ""
lsblk