由于内部虚拟机采用pv,vg,lv模式,导致经常性的做lv扩容操作。 于是编写以下脚本方便使用,仅供参考
#!/bin/bash
#v1.0
#by-xgmin-20200507
echo "please input your lvname"
read namelv
lv_name=df -Ph|grep "/$namelv"|awk '{print $1}'
lv_type=df -PT|grep "/$namelv"|awk '{print $2}'
echo $lv_name $lv_type
#############
pvlist=(pvs |grep "/dev/"|awk '{print $1}'
)
for pvname in ${pvlist[@]};do
echo $pvname
pvresize $pvname
done
vg=vgs|awk ' NR==2{print $NF}'|sed "s/\..*//g"
echo "VG free is "$vg"G"
lvextend -l +100%FREE $lv_name
if [ $lv_type == "ext4" ];then
resize2fs $lv_name
elif [ $lv_type == "xfs" ];then
xfs_growfs $lv_name
else
echo "Error:wrong storage format..."
exit
fi
S=df -h
echo "fineshd!"
echo "$S"