expansion of linux root partition script, suitable for centos 6, centos 7 version

! # / bin / bash
#auther chentongsan, Time 2019-05-30
#description: suitable for expansion of the system root partition, the first, second, third ...... .. suitable for centos 6, centos 7 version
# scan bus to identify the new added disks.
echo "- - -"> / SYS / class / scsi_host / host0 / Scan
echo "- - -"> / SYS / class / scsi_host / host1 / Scan
echo "- - -"> / SYS / class / scsi_host / host2 / Scan
# detection newly added disk drive letter, and extended VG disk size
divisible by DIVISOR = 1073741824
DISK_NAME = fdisk -l | grep "Disk /dev/sd" | awk -F '[ :]+' '{print $2}'
for disk DISK_NAME in $ {[*]}; do
df_disk = df -h | grep $disk | wc -l
IF [[$ df_disk -eq 0]]; the then
pvs_disk = pvs | grep $disk | wc -l
IF [ [$ pvs_disk -eq 0]]; the then
new_disk_size = fdisk -l | grep "$disk" | awk -F '[ ,:]+' '{print $5}'
new_disk_size_G = $ (($ new_disk_size / $ divisible by DIVISOR))
echo "detects the new disk: $ disk capacity: new_disk_size_G} {$ G"
echo "start creating PV, extended VG "


lvdisplay | grep "VG Name" | awk '{print $3}'
= Lv_path lvdisplay | grep "LV Path" | awk '{print $3}'
the vgextend $ $ vg_name Disk
lvresize -l + 100% $ lv_path the FREE
resize2fs $ lv_path
echo "$ lv_path / ext4 Defaults 0 0" >> / etc / fstab
Fi
Fi
DONE
echo "root partition expansion is completed, check that!"

Guess you like

Origin blog.51cto.com/chentongsan/2402725