# 腳本僅供交流學習使用!
# 腳本當前版本為1.0.實現了物理卷的創建,移除,更改(啟用/禁用分配),掃描,查看功能.
# 後續會補齊卷組和邏輯卷的管理,整合成一個Linux LVM TOOL.類似於AIX的SMIT.雖然,它只能管理LVM.
# 腳本已在Red Hat Enterprise Linux 5.4 64bit上測試通過.原則上適用於RHEL 5和RHEL 6.
# 歡迎提出改進意見.
# 直接復制請注意標點符號.也可通過微盤下載文件,避免復制引起的問題:http://vdisk.weibo.com/s/zKW6M
#!/bin/bash
# Version 1.0
# AUTHOR:Xin23 http://weibo.com/231988
PV()
{
NextLine()
{
echo ' '
}
Split()
{
echo '-----------------------------------------------------------------------'
}
EchoTitle()
{
echo "--------$Title-----------------------------------------"
}
ShowPVFirstMenu()
{
echo '
Physical Volumn Main Menu
Input Number To Choose!
Create Physical Volumn ...... 1
Remove Physical Volumn ...... 2
Change Physical Volumn ...... 3
Show Physical Volumn ...... 4
Scan Physical Volumn ...... 5
Exit ...... 6'
NextLine
}
GetChoice()
{
read -p ' Input Your Choice: ' Var
NextLine
}
ConfirmOperate()
{
NextLine
echo " Continue ...... y
Return ...... n"
NextLine
GetChoice
NextLine
Run
}
Run()
{
if [ $Var == y ]
then $Parameter $Disk
elif [ $Var == n ]
then Split
PV
else ConfirmOperate
fi
}
ChooseDisk()
{
read -p " Please Choose Disk: (Example: /dev/sdc) " Disk
NextLine
}
PVChange()
{
echo ' Which Operate You Want To do ? '
NextLine
echo ' ENABLE Allocatable ...... y
DISABLE Allocatable ...... n'
NextLine
GetChoice
}
CheckPVChange()
{
if [ $Var == y ]
then Parameter='pvchange -x y'
elif [ $Var == n ]
then Parameter='pvchange -x n'
else
PVChange
fi
}
PVShow()
{
echo ' Which Physical Volumn You Want To Show ? '
NextLine
echo ' All Physical Volumn ...... 1
Single Physical Volumn ...... 2'
NextLine
GetChoice
}
CheckPVShow()
{
if [ $Var -eq 1 ]
then pvdisplay
elif [ $Var -eq 2 ]
then pvdisplay $Disk
fi
}
TestPVShow()
{
if [ $Var -eq 1 ]
then Disk=All
elif [ $Var -eq 2 ]
then EchoTitle
NextLine
ChooseDisk
fi
}
ShowPVFirstMenu
GetChoice
case $Var in
"1")
Title='Create Physical Volumn'
Parameter=pvcreate
EchoTitle
NextLine
ChooseDisk
echo " Disk $Disk Will Be Convert To Physical Volumn"
ConfirmOperate
Status=0
;;
"2")
Title='Remove Physical Volumn'
EchoTitle
Parameter=pvremove
NextLine
ChooseDisk
echo " Disk $Disk Will Be Remove From Physical Volumn"
ConfirmOperate
Status=0
;;
"3")
Title='Change Physical Volumn'
EchoTitle
NextLine
PVChange
CheckPVChange
NextLine
ChooseDisk
echo " Physical Volumn $Disk Will Be Change"
ConfirmOperate
Status=0
;;
"4")
Title='Show Physical Volumn'
EchoTitle
NextLine
PVShow
NextLine
TestPVShow
echo " Physical Volumn $Disk Will Be Show"
NextLine
CheckPVShow
Status=0
;;
"5")
Title='Scan Physical Volumn'
EchoTitle
NextLine
pvscan
Status=0
;;
"6")
exit 0
;;
* )
echo ' Input Error,Retype!'
PV
;;
esac
NeedContinue()
{
if [ $Status -eq 0 ]
then NextLine
Split
PV
fi
}
NeedContinue
}
PV
本文出自 “Xin23的流水賬” 博客,請務必保留此出處http://xin23.blog.51cto.com/1827266/1192046