#!/bin/bash
function
check_execution_result(){
if
[[ ! -z $RETVAL ]];
then
unset
RETVAL
fi
RETVAL=$?
if
[[ $RETVAL -
ne
0 ]];
then
echo
execution failed!
exit
$RETVAL
else
echo
execution successfully!
fi
unset
RETVAL
}
ONLINE_SCSI_DISK_PRESENT=$(lsblk --all |
grep
disk |
grep
-
v
fd |
awk
'{print $1}'
|
xargs
)
ONLINE_SCSI_DISK_PRESENT=sda
echo
"- - -"
>
/sys/class/scsi_host/host0/scan
echo
"- - -"
>
/sys/class/scsi_host/host1/scan
echo
"- - -"
>
/sys/class/scsi_host/host2/scan
ONLINE_SCSI_DISK_NEWADD=$(lsblk --all |
grep
disk |
grep
-
v
fd |
awk
'{print $1}'
|
xargs
echo
|
sed
"s/$ONLINE_SCSI_DISK_PRESENT//g"
)
echo
New Added SCSI Disk: $ONLINE_SCSI_DISK_NEWADD
VG_Name=$(vgdisplay |
grep
'VG Name'
|
awk
'{print $NF}'
)
VG_PATH_TO_EXTEND=$(lvdisplay |
grep
'LV Path'
|
awk
'{print $NF}'
|
grep
root)
for
BLOCK
in
$ONLINE_SCSI_DISK_NEWADD;
do
ONLINE_SCSI_DISK_NEWADD_FILENAME=
"/dev/"
$BLOCK
fdisk
$ONLINE_SCSI_DISK_NEWADD_FILENAME >
/dev/null
2>&1<<eof
n
p
1
t
8e
w
eof
check_execution_result
LVM_OPERATION_DISK_FILENAME=$ONLINE_SCSI_DISK_NEWADD_FILENAME
"1"
pvcreate $LVM_OPERATION_DISK_FILENAME >
/dev/null
2>&1
check_execution_result
vgextend $VG_Name $LVM_OPERATION_DISK_FILENAME >
/dev/null
2>&1
check_execution_result
lvresize -l +100%FREE $VG_PATH_TO_EXTEND >
/dev/null
2>&1
check_execution_result
which
xfs_info >
/dev/null
2>&1
if
[[ $? -
ne
0 ]];
then
yum
install
xfsprogs -y >
/dev/null
2>&1
fi
xfs_info $VG_PATH_TO_EXTEND >
/dev/null
2>&1
if
[[ $? -
ne
0 ]];
then
VG_PATH_TO_EXTEND_IS_NOT_XFS=0
else
VG_PATH_TO_EXTEND_IS_NOT_XFS=1
fi
if
[[ $VG_PATH_TO_EXTEND_IS_NOT_XFS ]];
then
xfs_growfs $VG_PATH_TO_EXTEND >
/dev/null
2>&1
else
resize2fs $VG_PATH_TO_EXTEND >
/dev/null
2>&1
fi
check_execution_result
df
-h
lsblk --all
done