磁盘扩容
扩容
#!/bin/bash #下述下个变量需要根据实际情况进行修改 disk="/dev/sdb" partition="$disk"1 num=90 echo "n p 1 t 8e w " | fdisk $disk &>/dev/null #判断分区是否成功 a="`fdisk -l | grep /dev/sdb1 | grep 8e | wc -l`" if [ $a -ge 1 ]; then echo "分区成功,即将扩容;" sleep 3 else echo "分区失败,即将退出;" sleep 3 exit fi #创建物理PV,并进行扩容 #确定VG Name vgname="`vgdisplay | grep "VG Name" | awk '{print $3}'`" #定义需要扩容的目录 contents="`df -h | grep /dev/mapper/centos-root | awk '{print $1}'`" b="`cat /etc/fstab | grep $contents | grep "xfs" | wc -l`" if [ $b -ge 1 ]; then echo "系统格式是xfs,可扩展;" sleep 3 else echo "系统格式不对,即将退出;" sleep 3 exit fi echo "pvcreate $partition vgextend $vgname $partition lvextend -L +"$num"G $contents pvdisplay quit " | lvm &>/dev/null xfs_growfs /dev/mapper/centos-root echo " " echo " " vgdisplay | grep "VG Size" echo " " echo " " df -h