disk_lvm.sh

【disk_lvm.sh】怀抱观古今,寝食展戏谑。这篇文章主要讲述disk_lvm.sh相关的知识,希望能为你提供帮助。

#!/bin/bash
diskName=/dev/$(lsblk -f |awk {print NF, $1}|awk $1~/1/ & & $2!~/a|0/{print $2}|sed -n 1p)
vgName=bszh
lvName=data

lvm_partition(){
pvcreate $diskName
vgcreate $vgName $diskName
startNR=$(vgdisplay |awk "/VG Name.*$vgName/ {print NR}")
FreePESize=$(vgdisplay |sed -n "/$vgName$/,+18p"|awk $1~/Free/{print $5})
lvcreate -l $FreePESize -n $lvName $vgName
mkfs.ext4 /dev/$vgName/$lvName
tune2fs -c 0 -i 0 /dev/$vgName/$lvName
mkdir -p /data
echo "/dev/$vgName/$lvName/dataext4defaults0 0" > > /etc/fstab
mount -a
}

main(){
if [ $diskName == "/dev/sdb" ]; then
echo 非云主机
echo $diskName
lvm_partition
elif [ $diskName == "/dev/vdb" ]; then
echo 云主机
echo $diskName
lvm_partition
else
echo 请手动检查磁盘数量及状态
fi
}

main

hostnamectl set-hostname $(hostname -I |awk {print $1}|awkBEGIN{FS="."; OFS="-"}{$1=$1}1)


    推荐阅读