标签:
[root@localhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb vg0 lvm2 a-- 10.00g 0
/dev/sdc vg0 lvm2 a-- 10.00g 0
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg0 2 1 0 wz--n- 19.98g 0
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
data vg0 -wi-ao---- 19.98g
[root@localhost ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg0-data ext3 19G 52M 18G 1% /data
[root@localhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb vg0 lvm2 a-- 10.00g 0
/dev/sdc vg0 lvm2 a-- 10.00g 0
/dev/sdd vg0 lvm2 a-- 15.00g 0
/dev/sde vg0 lvm2 a-- 15.00g 0
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg0 4 1 0 wz--n- 49.98g 0
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
data vg0 -wi-ao---- 49.98g
[root@localhost ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg0-data ext3 50G 52M 47G 1% /data
#!/bin/bash
#################################################
# Create by ssslinppp
# 201699 15:16:58
##################################################
log_file_extendLvm="/data/logs/log_file_extendLvm.log"
echo "====================================================" > $log_file_extendLvm
echo "Begin to extendLVM at `date "+%Y-%m-%d %H:%M:%S"`" >> $log_file_extendLvm
vg_name="vg0"
lv_name="/dev/vg0/data"
fdisk_info="/data/fdisk_info"
pvs_info="/data/pvs_info"
diffSet="/data/diffSet"
displayInfo()
{
echo "---cmd: df -Th--------------------- " >> $log_file_extendLvm
df -Th /data >> $log_file_extendLvm 2>&1
echo "---cmd: pvs------------------------ " >> $log_file_extendLvm
pvs >> $log_file_extendLvm 2>&1
echo "---------------------------- " >> $log_file_extendLvm
}
getUnLvmDisk()
{
fdisk -l | grep /dev/[sh]d.: | awk -F ‘ ‘ ‘{print $2}‘ | awk -F ‘:‘ ‘{print $1}‘ > $fdisk_info
pvs | grep /dev/[sh]d. | awk -F ‘ ‘ ‘{print $1}‘ > $pvs_info
#get Difference set
sort $fdisk_info $pvs_info $pvs_info | uniq -u > $diffSet
echo "-----------------------------" >> $log_file_extendLvm
echo "fdisk_info is :" >> $log_file_extendLvm
cat $fdisk_info >> $log_file_extendLvm
echo "pvs_info is :" >> $log_file_extendLvm
cat $pvs_info >> $log_file_extendLvm
echo "diffSet is:" >> $log_file_extendLvm
cat $diffSet >> $log_file_extendLvm
echo "----------------------------" >> $log_file_extendLvm
rm -rf $fdisk_info
rm -rf $pvs_info
}
extendLV()
{
# example: change "sdb" to "/dev/sdb"
dev_disk=`echo $dev_disk|sed ‘/dev/!s/^/\/dev\//‘`
if [ ! -e $dev_disk ];then
echo "[ERROR] $dev_disk do not exists" >> $log_file_extendLvm
echo "error"
exit -1
fi
if [ `pvs | grep $dev_disk | wc -l` = "1" ];then
echo "[ERROR] $dev_disk(as PE) has already extend to $vg_name" >> $log_file_extendLvm
echo "error"
exit -2
fi
# step 1 :extend vg
echo "step 1- exec cmd: vgextend vg0 $dev_disk" >> $log_file_extendLvm
vgextend -f vg0 $dev_disk >> $log_file_extendLvm 2>&1
# step 2 :extend lv
echo "step 2- exec cmd: lvextend -l 100%VG $lv_name" >> $log_file_extendLvm
lvextend -l 100%VG $lv_name >> $log_file_extendLvm 2>&1
# step 3: resize2fs /dev/vg0/data
echo "step 3- exec cmd: resize2fs $lv_name" >> $log_file_extendLvm
resize2fs $lv_name >> $log_file_extendLvm 2>&1
}
# display info
echo "Before extendLVM..." >> $log_file_extendLvm
displayInfo
getUnLvmDisk
cat $diffSet | while read dev_disk
do
if [ $dev_disk != "/dev/sda" ] && [ `echo $dev_disk | wc -L` == 8 ];then
# exec extendLVM
extendLV
fi
done
# display info
echo "After extendLVM... " >> $log_file_extendLvm
displayInfo
echo "extendLVM finish success" >> $log_file_extendLvm
echo "success"
标签:
原文地址:http://www.cnblogs.com/ssslinppp/p/5857983.html